Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 17th, 2012  |  syntax: None  |  size: 0.82 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2.  
  3. set -e
  4. DESC="node.js test"
  5. NAME="test.js"
  6. DAEMON=/home/zz/test.js
  7. SCRIPTNAME=/home/zz/test.init
  8.  
  9. # Gracefully exit if the package has been removed.
  10. test -x $DAEMON || exit 0
  11.  
  12. #. /etc/default/$NAME
  13. WDIR=/home/zz
  14. RUNAS=zz
  15.  
  16. # Function that starts the daemon/service.
  17. d_start() {
  18.         cd $WDIR &&
  19.         su $RUNAS node test.js > /dev/null 2>&1 &
  20. }
  21.  
  22. # Function that stops the daemon/service.
  23. d_stop() {
  24.         killall "node test.js" > /dev/null 2>&1 || true
  25. }
  26.  
  27. case "$1" in
  28.   start)
  29.         echo -n "Starting $DESC: $NAME"
  30.         d_start
  31.         echo "."
  32.         ;;
  33.   stop)
  34.         echo -n "Stopping $DESC: $NAME"
  35.         d_stop
  36.         echo "."
  37.         ;;
  38.   restart|force-reload)
  39.         echo -n "Restarting $DESC: $NAME"
  40.         d_stop
  41.         sleep 1
  42.         d_start
  43.         echo "."
  44.         ;;
  45.   *)
  46.         echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  47.         exit 1
  48.         ;;
  49. esac
  50.  
  51. exit 0