Challenges...
- run Node.js services in background
- automatically restart them if they are crashing
- collect output/error logs for analyzing them later or watching them in real time.
Handles and processes long running background tasks/services.
SystemD is an init system.
Make server.js
an executable and create a symlink.
Note: symlink path must be absolute.
chmod +x server.js
ln /home/yoda/Github/node-systemd/app/services/hello_moto/server.js /app/services/hello_moto/server.js
ln /home/yoda/Github/node-systemd/etc/systemd/system/hello_moto.service /etc/systemd/system/hello_moto.service
systemctl enable hello_moto.service
systemctl start hello_moto.service
If troublshooting make sure to reload the daemon.
systemctl daemon-reload
To view all output logs use the following command.
sudo journalctl -u hello_moto.service
# For real time logs just add -f argument
sudo journalctl -fu hello_moto.service