Skip to content

Instantly share code, notes, and snippets.

@lokesh-webonise
Created October 28, 2015 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lokesh-webonise/914e9725cea3406f5165 to your computer and use it in GitHub Desktop.
Save lokesh-webonise/914e9725cea3406f5165 to your computer and use it in GitHub Desktop.
#!/bin/bash
###################
#Set Env variables#
###################
USER=deploy
PIDFILE=/tmp/demo.pid
APPDIR=/var/www/demo-warehouse.weboapps.com/server/
NODEENV=staging
DEAMON=/usr/bin/node
DEAMON_OPT=/var/www/demo-warehouse.weboapps.com/server/server.js
function start {
start-stop-daemon --start --oknodo --background --user $USER --chuid $USER -m -p $PIDFILE --chdir $APPDIR --exec /usr/bin/env NODE_ENV="`echo $NODEENV`" $DEAMON -- $DEAMON_OPT
}
function stop {
start-stop-daemon --stop --oknodo --user $USER --chuid $USER -p $PIDFILE --chdir $APPDIR --exec $DEAMON -- $DEAMON_OPT
}
case $1 in
start)
if [ -f $DEAMON_OPT ]; then
echo "starting Node service"
start
echo -e "Started [OK] \nNode service started with pid : `cat $PIDFILE`"
else
echo "Node service start failed"
echo "status returned $?"
fi
;;
stop)
if [ -f $PIDFILE ]; then
echo "shutting down Node service"
stop
echo "Node service stopped [OK]"
else
echo "Node service shutdown failed"
echo "status returned $?"
fi
;;
restart)
stop
start
;;
*)
echo "Use (start|stop|restart)";
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment