nem.ec

Programming Information Security Recipes Personal Code Snippets

Creating a Systemd startup for a service

Some description

Source: https://www.howtogeek.com/687970/how-to-run-a-linux-program-at-startup-with-systemd/

Create unit file:

sudo nano /etc/systemd/system/myapp.service

Paste the following into the unit file:

[Unit]
Description=My App

Wants=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/myapp.sh
#ExecStart=node src/www
Restart=on-failure
RestartSec=10
KillMode=process

[Install]
WantedBy=multi-user.target
sudo chmod 640 /etc/systemd/system/myapp.service

Test the unit file:

systemctl status myapp.service

Enable unit file and service:

sudo systemctl daemon-reload
sudo systemctl enable myapp
sudo systemctl start myapp

Verify service status:

sudo systemctl status myapp.service