npm install forever -g
forever --help
forever start app.js
forever stop app.js
previous command check forever help, start app.js then stop app.js We need forever run automatically
creat file node
in /etc/init.d/forever
with the following content
#!/bin/bash
#
# node Start up node server daemon
#
# chkconfig: 345 85 15
# description: Forever for Node.js
#
PATH=/path/to/node/in/your/server
DEAMON=/path/to/your/app.js
LOG=/path/to/your/app/log/
PID=/root/.forever/pids/forever.pid
case "$1" in
start)
forever start -l $LOG/forever.log -o $LOG/forever_out.log -e $LOG/forever_err.log --pidFile $PID -a $DEAMON
;;
stop)
forever stop --pidFile $PID $DEAMON
;;
stopall)
forever stopall --pidFile $PID
;;
restartall)
forever restartall --pidFile $PID
;;
reload|restart)
forever restart -l $LOG/forever.log -o $LOG/forever_out.log -e $LOG/forever_err.log --pidFile $PID -a $DEAMON
;;
list)
forever list
;;
*)
echo "Usage: /etc/init.d/forever {start|stop|restart|reload|stopall|restartall|list}"
exit 1
;;
esac
exit 0
#!/bin/bash
# chkconfig: 345 88 08
# description: Forever for Node.js
DEAMON=/path/to/your/app.js
LOG=/path/to/your/app/logs/forever.log
PID=/root/.forever/pids/forever.pid
export PATH=$PATH:/usr/bin/node/bin
export NODE_PATH=$NODE_PATH:/usr/bin/node/lib/node_modules
node=node
forever=forever
case "$1" in
start)
$forever start -l $LOG --pidFile $PID -a $DEAMON
;;
stop)
$forever stop --pidFile $PID $DEAMON
;;
stopall)
$forever stopall --pidFile $PID
;;
restartall)
$forever restartall --pidFile $PID
;;
reload|restart)
$forever restart -l $LOG --pidFile $PID -a $DEAMON
;;
list)
$forever list
;;
*)
echo "Usage: /etc/init.d/forever {start|stop|restart|reload|stopall|restartall|list}"
exit 1
;;
esac
make file /etc/init.d/forever
executable with following command
chmod 755 /etc/init.d/forever
chkconfig --add forever
chkconfig forever on
chkconfig /etc/init.d/forever on
reboot your server