A simple Unix shell script example to start, stop, restart, and check status of NodeJS forever tool that ensures that a given script runs continuously.
You would need to install forever tool globally:
$ [sudo] npm install forever -g
Place the script into init.d directory.
Update reference according to your system and project setup:
NAME="myapp" Application name
APP_DIRECTORY=/var/www/html/myapp.com Application directory path to start file
APP_START=server.js Application start file name
Setup executable permissions:
chmod +x /etc/init.d/foreverdaemon
Add script to boot on Debian:
update-rc.d foreverdaemon defaults 100
Remove script from boot on Debian:
update-rc.d foreverdaemon stop levels .
To start the service:
$ [sudo] /etc/init.d/foreverdaemon start
To stop the service:
$ [sudo] /etc/init.d/foreverdaemon stop
To restart the service:
$ [sudo] /etc/init.d/foreverdaemon restart
To get the status:
$ [sudo] /etc/init.d/foreverdaemon status