#! /bin/sh

# Description: Startup script for node.js webapp on Debian. 
# Place in /etc/init.d/ and chmod 744 nodejs
# run 'update-rc.d nodejs defaults' 
# or use the appropriate command on your distro.
#
# Author:    Vincent RABAH

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=test.js
DESC="nodejs daemon $NAME" 
DAEMON=/var/www/node.js/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

case "$1" in
  start)
  echo -n "Starting $DESC: $NAME"
  start-stop-daemon -S -q --oknodo -g www-data -u www-data -b -x $DAEMON 
  echo "."
  ;;
  stop)
  echo -n "Stopping $DESC: $NAME"
  start-stop-daemon --oknodo -K -q -R 30 -n $NAME
  echo "."
  ;;
  restart|force-reload)
  echo "Restarting $DESC: $NAME"
  start-stop-daemon --oknodo -K -q -R 30 -n $NAME
  start-stop-daemon -S -q --oknodo -g www-data -u www-data -b -x $DAEMON 
  echo "."
  ;;
  *)
  echo "Usage: $0 {start|stop|restart}" >&2
  exit 1
  ;;
esac