Skip to content

Instantly share code, notes, and snippets.

@kardeiz
Created January 9, 2018 18:35
Show Gist options
  • Save kardeiz/1dcbba70370d93a7fc72cf01de92631a to your computer and use it in GitHub Desktop.
Save kardeiz/1dcbba70370d93a7fc72cf01de92631a to your computer and use it in GitHub Desktop.
#!/bin/sh
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
cd $SCRIPTPATH
source /etc/init.d/functions
source ./.env
APP_CMD="target/release/$APP_NAME web > $APP_LOG 2>&1 &
echo \$! > '$APP_PID'"
do_start() {
touch $APP_PID
[ $? -eq 0 ] && chown "${APP_USER}:" $APP_PID
daemon \
--user "${APP_USER}" \
--pidfile "${APP_PID}" \
"${APP_CMD}"
return $?
}
do_stop() {
killproc -p "${APP_PID}"
return $?
}
do_restart() {
local result
do_stop
result=$?
if [ $result -eq 0 ]; then
do_start
result=$?
fi
return $result
}
do_status() {
status -p "${APP_PID}" "$APP_NAME"
return $?
}
do_usage() {
echo $"Usage: $0 {start | stop | restart | status}"
exit 1
}
case "$1" in
start) do_start; exit $? ;;
stop) do_stop; exit $? ;;
restart) do_restart; exit $? ;;
status) do_status; exit $? ;;
*) do_usage; exit 1 ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment