svchelper/app/bin/stop

54 lines
11 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
"$APP" onearg "$@"
"$APP" exist "$1"
echo "[$APP_NAME] Stopping '$1' ..."
source "$APP" service_env "$1"
if [ "$SERVICE_STOP" = "0" ]; then
exit 0
fi
if ! "$APP" service_running "$1"; then
echo "Service already stopped."
exit 0
fi
if [ -e "$APP_SERVICES/$1/stop" ]; then
source "$APP_SERVICES/$1/stop"
fi
if [ "$SERVICE_SCREEN" = "1" ] && ! [ "$SERVICE_SCREEN_EXIT_COMMAND" = "" ]; then
echo "[$APP_NAME] * Sending backspaces to screen ..."
if [ "$SERVICE_SCREEN_EXIT_BACKSPACE" = "1" ]; then
screen -S "$SERVICE_SCREEN_NAME" -X stuff ""
screen -S "$SERVICE_SCREEN_NAME" -X stuff ""
screen -S "$SERVICE_SCREEN_NAME" -X stuff ""
screen -S "$SERVICE_SCREEN_NAME" -X stuff ""
screen -S "$SERVICE_SCREEN_NAME" -X stuff ""
screen -S "$SERVICE_SCREEN_NAME" -X stuff ""
screen -S "$SERVICE_SCREEN_NAME" -X stuff ""
screen -S "$SERVICE_SCREEN_NAME" -X stuff ""
screen -S "$SERVICE_SCREEN_NAME" -X stuff ""
screen -S "$SERVICE_SCREEN_NAME" -X stuff ""
fi
echo "[$APP_NAME] * Sending exit command to screen ..."
screen -S "$SERVICE_SCREEN_NAME" -X stuff "$SERVICE_SCREEN_EXIT_COMMAND^M"
echo "[$APP_NAME] * Waiting for service to end ..."
"$APP" user_wait "$SERVICE_USER" "$SERVICE_TIMEOUT_SCREEN_EXIT"
if [ "$?" = "0" ]; then
exit 0
fi
fi
echo "[$APP_NAME] * Terminating service ..."
killall -15 -u "$SERVICE_USER"
echo "[$APP_NAME] * Waiting for service to end ..."
"$APP" user_wait "$SERVICE_USER" "$SERVICE_TIMEOUT_TERMINATE"
if [ "$?" = "0" ]; then
exit 0
fi
echo "[$APP_NAME] * Killing service."
killall -9 -u "$SERVICE_USER"
exit 0