Add the ability for services to require others
This commit is contained in:
parent
e5883a31e1
commit
4dbef0734e
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
screen -ls "$1" >/dev/null 2>&1
|
|
||||||
echo $?
|
|
9
app/bin/service_running
Normal file
9
app/bin/service_running
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
"$APP" onearg "$@"
|
||||||
|
"$APP" exist "$1"
|
||||||
|
source "$APP" service_env "$1"
|
||||||
|
ps -u "$SERVICE_USER"
|
||||||
|
if [ "$?" = "0" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
exit 1
|
@ -3,18 +3,24 @@
|
|||||||
"$APP" exist "$1"
|
"$APP" exist "$1"
|
||||||
source "$APP" service_env "$1"
|
source "$APP" service_env "$1"
|
||||||
|
|
||||||
|
for SERVICE in "${SERVICE_REQUIRE:@}"; do
|
||||||
|
"$APP" start "$SERVICE"
|
||||||
|
done
|
||||||
|
|
||||||
echo "[$APP_NAME] Starting '$1' ..."
|
echo "[$APP_NAME] Starting '$1' ..."
|
||||||
if [ "$SERVICE_RUN" = "" ]; then
|
if [ "$SERVICE_RUN" = "" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set +e
|
if "$APP" service_running "$1"; then
|
||||||
ps -u "$SERVICE_USER"
|
|
||||||
if [ "$?" = "0" ]; then
|
|
||||||
echo "Service is already running."
|
echo "Service is already running."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
set -e
|
|
||||||
|
if [ -e "$APP_SERVICES/$1/start" ]; then
|
||||||
|
source "$APP_SERVICES/$1/start"
|
||||||
|
fi
|
||||||
|
|
||||||
SERVICE_RUN_RAW="cd \"$SERVICE_CD\"; exec ${SERVICE_RUN//"/\\"}"
|
SERVICE_RUN_RAW="cd \"$SERVICE_CD\"; exec ${SERVICE_RUN//"/\\"}"
|
||||||
if [ "$SERVICE_SCREEN" = "1" ]; then
|
if [ "$SERVICE_SCREEN" = "1" ]; then
|
||||||
screen -dmS "$SERVICE_SCREEN_NAME" gosu "$SERVICE_USER" bash -c "$SERVICE_RUN_RAW"
|
screen -dmS "$SERVICE_SCREEN_NAME" gosu "$SERVICE_USER" bash -c "$SERVICE_RUN_RAW"
|
||||||
@ -22,3 +28,6 @@ else
|
|||||||
gosu "$SERVICE_USER" nohup bash -c "$SERVICE_RUN_RAW" > /dev/null 2>&1 &
|
gosu "$SERVICE_USER" nohup bash -c "$SERVICE_RUN_RAW" > /dev/null 2>&1 &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -e "$APP_SERVICES/$1/await" ]; then
|
||||||
|
source "$APP_SERVICES/$1/await"
|
||||||
|
fi
|
||||||
|
@ -7,13 +7,16 @@ source "$APP" service_env "$1"
|
|||||||
if [ "$SERVICE_STOP" = "0" ]; then
|
if [ "$SERVICE_STOP" = "0" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
set +e
|
|
||||||
ps -u "$SERVICE_USER"
|
if ! "$APP" service_running "$1"; then
|
||||||
if ! [ "$?" = "0" ]; then
|
|
||||||
echo "Service already stopped."
|
echo "Service already stopped."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -e "$APP_SERVICES/$1/stop" ]; then
|
||||||
|
source "$APP_SERVICES/$1/stop"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$SERVICE_SCREEN" = "1" ] && ! [ "$SERVICE_SCREEN_EXIT_COMMAND" = "" ]; then
|
if [ "$SERVICE_SCREEN" = "1" ] && ! [ "$SERVICE_SCREEN_EXIT_COMMAND" = "" ]; then
|
||||||
echo "[$APP_NAME] * Sending backspaces to screen ..."
|
echo "[$APP_NAME] * Sending backspaces to screen ..."
|
||||||
if [ "$SERVICE_SCREEN_EXIT_BACKSPACE" = "1" ]; then
|
if [ "$SERVICE_SCREEN_EXIT_BACKSPACE" = "1" ]; then
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
# If defined, the service will wait for other services to be started
|
||||||
|
SERVICE_REQUIRE=()
|
||||||
# If command is defined, it will create and run a service unit
|
# If command is defined, it will create and run a service unit
|
||||||
SERVICE_RUN='./hello'
|
SERVICE_RUN='./hello'
|
||||||
# Working directory
|
# Working directory
|
||||||
|
Loading…
Reference in New Issue
Block a user