Skip to content

Instantly share code, notes, and snippets.

@pluma
Created October 15, 2014 15:47
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 pluma/b364c1b34304a9e648c3 to your computer and use it in GitHub Desktop.
Save pluma/b364c1b34304a9e648c3 to your computer and use it in GitHub Desktop.
Node init.d script with naught.
#!/bin/bash
NAME=webapp
IPC=/var/run/naught/$NAME.ipc
DESC="my application server"
WORKERS=2
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
naught start --worker-count $WORKERS --ipc-file $IPC --log /var/log/$NAME/naught.log --stdout /var/log/$NAME/stdout.log --stderr /var/log/$NAME/stderr.log --cwd /srv/$NAME/ /srv/$NAME/index.js
chown root:root $IPC
echo "done."
;;
stop)
echo -n "Stopping $DESC: "
naught stop --timeout 60 $IPC
echo "done."
;;
reload)
echo -n "Reloading $DESC: "
naught deploy --timeout 60 $IPC
echo "done."
;;
status)
naught status $IPC
exit $?
;;
restart|force-reload)
echo -n "Restarting $DESC: "
naught deploy --timeout 60 $IPC
if [ $? -ne "0" ]; then
$0 stop
$0 start
exit $?
fi
echo "done."
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|status}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment