add startup service on 16.04
38,886
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
asmyforever.service
( or with whatever name you like ).-
Start the service and enable at start up.
sudo systemctl start myforever.service sudo systemctl enable myforever.service
-
Check if it's running:
sudo systemctl status myforever.service
-
To stop and disable it any time:
sudo systemctl stop myforever.service sudo systemctl disable myforever.service
NOTE:
- This is a simplified version of a
systemd service
many options are available - The service can also be called
myforever
without the.service
extension,systemd
will pick the right file - This
/home/george/.npm-global/bin/forever
is where mynode
modules are kept, yours will be different. Find it withwhich forever
Additional Information:
https://www.axllent.org/docs/view/nodejs-service-with-systemd/
Related videos on Youtube
Author by
Hesam Pourghazian
Updated on September 18, 2022Comments
-
Hesam Pourghazian over 1 year
i need to run "node js" project on 16.4 Permanently
and use forever package for run in background in ubuntu
now I want add a startup service to ubuntu but i searched there is no result.
I've created a file called
test.conf
to/etc/init.d
test.conf :
start on startup exec forever start /root/node/node_modules/.bin/www
-
George Udosen about 7 yearsYou will need to use a
systemd service
for this. -
George Udosen about 7 yearsWill you be using
mysql
-
Hesam Pourghazian about 7 years@George There are training in this topic?
-
George Udosen about 7 yearsWhat topic are you referring to, have you set up
forever
and just need a way to run it in Ubuntu service? -
Hesam Pourghazian about 7 years@George yes ...
-
-
Hesam Pourghazian about 7 yearsfinally i use package "service-systemd"