diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-10-12 15:28:52 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-10-12 15:28:52 -0700 |
commit | 6a9029b2d9bce2fe44e14d6fbc50b8c42c759103 (patch) | |
tree | 1a53f4a146dc52026cebfbe9f0ca9fd7fa2550d8 | |
parent | 2355abadca642a8d15b2530a5675f3d7820ebe36 (diff) |
adding SysV init.d script for standalone deployments
-rw-r--r-- | deployment/sysv/ponzu-server | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/deployment/sysv/ponzu-server b/deployment/sysv/ponzu-server new file mode 100644 index 0000000..0a0e724 --- /dev/null +++ b/deployment/sysv/ponzu-server @@ -0,0 +1,68 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: ponzu-server +# Required-Start: $local_fs $network $named $time $syslog +# Required-Stop: $local_fs $network $named $time $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: Ponzu API & Admin server +### END INIT INFO + +PROJECT_DIR=<PROJECT DIRECTORY> +SCRIPT='cd $PROJECT_DIR && ponzu --port=80 run' +RUNAS=<USER> + +PIDFILE=/var/run/ponzu-server.pid +LOGFILE=/var/log/ponzu-server.log + +start() { + if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then + echo 'Service already running' >&2 + return 1 + fi + echo 'Starting serviceā¦' >&2 + local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!" + su -c "$CMD" $RUNAS > "$PIDFILE" + echo 'Service started' >&2 +} + +stop() { + if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then + echo 'Service not running' >&2 + return 1 + fi + echo 'Stopping serviceā¦' >&2 + kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" + echo 'Service stopped' >&2 +} + +uninstall() { + echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] " + local SURE + read SURE + if [ "$SURE" = "yes" ]; then + stop + rm -f "$PIDFILE" + echo "Notice: log file is not be removed: '$LOGFILE'" >&2 + update-rc.d -f <NAME> remove + rm -fv "$0" + fi +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + uninstall) + uninstall + ;; + restart) + stop + start + ;; + *) + echo "Usage: $0 {start|stop|restart|uninstall}" +esac |