#!/bin/bash # # initd a node app # Based on a script posted by https://gist.github.com/jinze at https://gist.github.com/3748766 # # Source function library. . /lib/lsb/init-functions pidFile=/var/run/plunker-www.pid logFile=/var/run/plunker-www.log nodePath=/path/to/plunker/plunker_www nodeApp=$nodePath/server.js start() { echo "Starting $nodeApp" cd $nodePath # This is found in the library referenced at the top of the script start_daemon # Notice that we change the PATH because on reboot # the PATH does not include the path to node. # Launching forever with a full path # does not work unless we set the PATH. PATH=/usr/local/bin:$PATH export NODE_ENV=development #PORT=80 /usr/bin/forever start --pidFile $pidFile -l $logFile -a -d $nodeApp RETVAL=$? } restart() { echo -n "Restarting $nodeApp" /usr/bin/forever restart $nodeApp RETVAL=$? } stop() { echo -n "Shutting down $nodeApp" /usr/bin/forever stop $nodeApp RETVAL=$? } status() { echo -n "Status $nodeApp" /usr/bin/forever list RETVAL=$? } case "$1" in start) start ;; stop) stop ;; status) status ;; restart) restart ;; *) echo "Usage: {start|stop|status|restart}" exit 1 ;; esac exit $RETVAL