Skip to content

Commit

Permalink
update start/run function
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonEverling committed Feb 17, 2024
1 parent 703928b commit 0285fd7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/usr/lib/ocie/types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function app_reload()
/path/to/your/app --reload
}
# This must return, e.g echo the process id (PID)
function app_start()
{
/path/to/your/app --start
Expand Down
4 changes: 3 additions & 1 deletion src/usr/lib/ocie/types/apache.ocie
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function app_reload()

function app_start()
{
/usr/sbin/apachectl -k start -D FOREGROUND;
/usr/sbin/apachectl -k start;
sleep 5;
echo $(cat ${APACHE_PID});
}

function app_test()
Expand Down
8 changes: 5 additions & 3 deletions src/usr/lib/ocie/types/itsm.ocie
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

function app_shutdown()
{
su jetbrains -c "${YOUTRACK_HOME}/bin/youtrack.sh stop";
${YOUTRACK_HOME}/bin/youtrack.sh stop;
}

function app_reload()
{
su jetbrains -c "${YOUTRACK_HOME}/bin/youtrack.sh restart";
${YOUTRACK_HOME}/bin/youtrack.sh restart;
}

function app_start()
{
su jetbrains -c "${YOUTRACK_HOME}/bin/youtrack.sh run $@";
su jetbrains -c "${YOUTRACK_HOME}/bin/youtrack.sh start $@";
sleep 5;
echo "$(cat ${YOUTRACK_PID} | sed 's/ //'))";
}

function app_certs()
Expand Down
5 changes: 3 additions & 2 deletions src/usr/lib/ocie/types/postfix.ocie
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ function app_reload()

function app_start()
{
#Start Foreground
/usr/sbin/postfix -c /etc/postfix start-fg;
/usr/sbin/postfix -c /etc/postfix;
sleep 5;
echo "$(cat ${POSTFIX_PID} | sed 's/ //'))";
}

function app_test()
Expand Down
8 changes: 6 additions & 2 deletions src/usr/lib/ocie/types/tomcat.ocie
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
function app_shutdown()
{
/usr/sbin/apachectl -k stop;
"${CATALINA_HOME}/bin/catalina.sh" stop;
${CATALINA_HOME}/bin/catalina.sh stop 15 >/dev/null 2>&1;
}

function app_reload()
{

app_shutdown;
app_start;
}

function app_start()
{
/usr/sbin/apachectl -k start;
su ${APP_OWNER} -c "${CATALINA_HOME}/bin/catalina.sh run";
su ${RUNAS} -c "${CATALINA_HOME}/bin/catalina.sh start >/dev/null";
#Give tomcat a few seconds to create java PID
sleep 5;
echo "$(cat ${CATALINA_PID})";
}

function app_test()
Expand Down
24 changes: 19 additions & 5 deletions src/usr/sbin/ociectl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# Custom config
RUNAS="${APP_OWNER}";
if [[ ! -z "${OCIE_CONFIG}" ]];then
if [[ -d "${OCIE_CONFIG}" ]];then
if [[ -f "${OCIE_CONFIG}/config.ocie" ]];then
Expand Down Expand Up @@ -66,7 +67,7 @@ function ocie_shutdown()
{
echo "Ocie: Recieved stop signal, attemtping to terminate application gracefully";
app_shutdown;
echo "Ocie: Application stopped with exit code [ $? ], shutting down..";
echo "Ocie: Application stopped with exit code [ $? ], shutting down container..";
exit 0;
}

Expand Down Expand Up @@ -130,7 +131,6 @@ function ocie_start()
ocie_keys;
ocie_config;
ocie_deploy;
RUNAS="${APP_OWNER}";
if [[ "${APP_ENV}" == "prod" ]];then
check_volumes;
fi;
Expand All @@ -143,9 +143,23 @@ function ocie_start()
else
echo "Ocie: Application will run as [ ${RUNAS} ] OR you can set APP_OWNER to [ root ] and risk it for the biscuit";
fi;
echo "Ocie: Initialization complete, starting container";
app_start &
wait
echo "Ocie: Initialization complete";
echo "Ocie: Application starting, please wait...";
local pid=$(app_start);
if [[ ! -z "$pid" ]];then
echo "Ocie: Application started, watching PID: [ $pid ]";
echo "Ocie: Press CTRL+C to stop";
else
echo "Ocie: Application did not return a PID";
ocie_shutdown;
fi;
while true;do
if [[ -z $(ps --no-headers -p $pid) ]];then
echo "Ocie: Application process has disappeared";
ocie_shutdown;
fi;
sleep 15;
done;
}

# Shutdown - SIGINT, SIGTERM, SIGWINCH
Expand Down

0 comments on commit 0285fd7

Please sign in to comment.