In the simplest for using systemd service
:
-
Install
forever
:[sudo] npm install forever -g
-
Write and store the script to run in preferred location.
-
Write the
Systemd service
:[Unit] Description=forever service After=network.target [Service] ExecStart=/home/george/.npm-global/bin/forever start /root/node/node_modules/.bin/www ExecStop=/home/george/.npm-global/bin/forever stop /root/node/node_modules/.bin/www Restart=always RestartSec=10 # Restart service after 10 seconds if node service crashes StandardOutput=syslog # Output to syslog StandardError=syslog # Output to syslog SyslogIdentifier=nodejs-example [Install] WantedBy=multi-user.target
-
Save the
systemd service
file in/etc/systemd/system</