I configured forever to run my node.js server on startup. using this scipt. It works fine. and forever keeps the server running. However, when I run forever list, I don't see my server here! I know it's running but it's never in this list. It looks like that the system is running two instances of forever.
root@ddd [/etc/init.d]# chkconfig --list |grep node1
node1 0:off 1:off 2:on 3:on 4:on 5:on 6:off
This is the script: /etc/init.d/node1
NAME=node1
NODE_BIN_DIR=/usr/local/bin
NODE_PATH=/usr/local/lib/node_modules
APPLICATION_DIRECTORY=/home/user1/www
APPLICATION_START=node1.js
PIDFILE=/var/run/node1.pid
LOGFILE=/var/log/node1.log
PATH=$NODE_BIN_DIR:$PATH
export NODE_PATH=$NODE_PATH
start() {
echo "Starting $NAME"
forever --pidFile $PIDFILE --sourceDir $APPLICATION_DIRECTORY \
-a -l $LOGFILE --minUptime 5000 --spinSleepTime 2000 \
start $APPLICATION_START &
RETVAL=$?
}
stop() {
if [ -f $PIDFILE ]; then
echo "Shutting down $NAME"
forever stop $APPLICATION_START
rm -f $PIDFILE
RETVAL=$?
else
echo "$NAME is not running."
RETVAL=0
fi
}
restart() {
echo "Restarting $NAME"
stop
start
}
status() {
echo "Status for $NAME:"
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
You could also just put forever in a user's crontab, using the @reboot parameter so it'll start when startup occurs.
something like:
@reboot /usr/bin/forever start /path/to/script.js
(This is assuming forever is in /usr/bin/; it may also be somewhere like /usr/local/bin/.)
The problem is that forever keeps all of it's files in ~/.forever. The above script runs as root. Not sure where it stores them then, but for me doing "sudo forever list" does the job.