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:
sudo nano /etc/systemd/system/example.service
Common commands:
sudo systemctl start example
sudo systemctl status example
sudo systemctl stop example
sudo systemctl restart example
### ENABLE SERVICE ### !!!IMPORTANT!!! This enables it to run on boot
sudo systemctl enable example
Template:
[Unit] Description= [Service] ExecStart=/usr/bin/node /home/kiza/AppName/server/server.js User=kiza Group=kiza Restart=always RestartSec=10 Environment=NODE_ENV=production WorkingDirectory=/home/kiza/AppName/ [Install] WantedBy=multi-user.target
See logs with:
sudo journalctl -u example
Last 100 lines:
sudo journalctl -u example -n 100 --no-pager
Sources: