Skip to content

Instantly share code, notes, and snippets.

@ykrkn
Created March 1, 2013 17:21
Show Gist options
  • Save ykrkn/5066224 to your computer and use it in GitHub Desktop.
Save ykrkn/5066224 to your computer and use it in GitHub Desktop.
#! /bin/sh
### BEGIN INIT INFO
# Provides: alena-sio-client-handler
### END INIT INFO
set -e
NAME=alena-sio-client-handler
RUN_AS=alena:alena
PATH=$PATH:/usr/local/bin
NODE_PATH=/usr/local/lib/node_modules
WORK_PATH=/opt/alena/client-handler
DAEMON=/usr/local/bin/node
DAEMON_ARGS=/opt/alena/client-handler/client-handler.js
DAEMON_NAME=$NAME
DAEMON_DESC=$NAME
DAEMON_PIDFILE=/var/run/$DAEMON_NAME
case "$1" in
start)
echo -n "Starting $DAEMON_DESC: "
touch $DAEMON_PIDFILE
chown $RUN_AS $DAEMON_PIDFILE
if start-stop-daemon --background --make-pidfile --start --pidfile $DAEMON_PIDFILE --chuid $RUN_AS --exec $DAEMON -- $DAEMON_ARGS
then
echo "$DAEMON_NAME started."
else
echo "failed"
fi
;;
stop)
echo -n "Stopping $DAEMON_DESC: "
if start-stop-daemon --stop --retry forever/QUIT/1 --quiet --oknodo --pidfile $DAEMON_PIDFILE --exec $DAEMON
then
echo "$DAEMON_NAME stopped."
else
echo "failed"
fi
rm -f $DAEMON_PIDFILE
;;
restart)
${0} stop
${0} start
;;
status)
echo -n "$DAEMON_DESC is "
if start-stop-daemon --stop --quiet --signal 0 --pidfile $DAEMON_PIDFILE
then
echo "running"
else
echo "not running"
#exit 1
fi
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment