Created
May 24, 2017 17:17
-
-
Save 0xAF/42f6552db3a85aa41e0d2c4c4f50a211 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: mojo_cdn | |
# Required-Start: $remote_fs $local_fs $network $syslog $time | |
# Required-Stop: $remote_fs $local_fs $network $syslog $time | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Description: starts mojo_cdn application | |
### END INIT INFO | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
APP_DIR="/var/www/cdn" | |
APP_SCRIPT="/var/www/cdn/script/tg" | |
PID_FILE="$APP_DIR/script/hypnotoad.pid" | |
USE_CARTON=0 | |
USER="nobody" | |
if [ -f /etc/default/mojo_cdn ] ; then | |
. /etc/default/mojo_cdn | |
fi | |
if [ "$USE_CARTON" -ne "0" ]; then | |
CARTON="$(which carton) exec" | |
fi | |
if [ -f /lib/lsb/init-functions ] ; then | |
. /lib/lsb/init-functions | |
fi | |
cd $APP_DIR || err "Cannot chdir to $APP_DIR" | |
err() { | |
echo $* >&2 | |
return 1 | |
} | |
status() { | |
if [ -f "$PID_FILE" ] && kill -0 $(cat "$PID_FILE"); then | |
return 0 # true | |
fi | |
return 1 # false | |
} | |
start() { | |
if [ ! status ]; then | |
err 'Service already running' | |
return 1 | |
fi | |
echo 'Starting service...' >&2 | |
su -c "cd \"$APP_DIR\";$CARTON hypnotoad $APP_SCRIPT" $USER | |
} | |
stop() { | |
status || err 'Service is not running' || return 1 | |
echo 'Stopping service...' >&2 | |
su -c "cd \"$APP_DIR\";$CARTON hypnotoad $APP_SCRIPT --stop" $USER | |
} | |
reload() { | |
status || start | |
echo "Reloading hypnotoad..." >&2 | |
su -c "cd \"$APP_DIR\";$CARTON hypnotoad $APP_SCRIPT" $USER | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
reload) | |
reload | |
;; | |
restart) | |
stop | |
start | |
;; | |
status) | |
status && echo "Running at pid $(cat $PID_FILE)" && return 0 | |
err "Not running" || return 1 | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart|reload|status}" | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment