Systemd cheat sheet

How to create a systemd service:

View existing systemd services:

ls /etc/systemd/system/

Make a serviceName.service file with the template below in the folder:

nano /etc/systemd/system/{{name}}.service

Common commands:

systemctl start {{name}}
systemctl status {{name}}
systemctl stop {{name}}

### ENABLE SERVICE ### !!!IMPORTANT!!! This enables it to run on boot

systemctl enable {{name}}

Template:
[Unit]
Description=Absentia web app

[Service]
ExecStart=/usr/bin/node /home/kiza/LT/server/server.js
Restart=always
RestartSec=10
Environment=NODE_ENV=production
WorkingDirectory=/home/kiza/LT/

[Install]
WantedBy=multi-user.target

Other useful commands:

systemctl restart {{name}}

See logs with:

journalctl -u {{name}}

Sources:

https://stackoverflow.com/questions/4018154/how-do-i-run-a-node-js-app-as-a-background-service/29042953#29042953
https://www.axllent.org/docs/view/nodejs-service-with-systemd/