Skip to content

Instantly share code, notes, and snippets.

@hugoeanogueira
Last active July 18, 2019 20:52
Show Gist options
  • Save hugoeanogueira/d1462696f6bd38f6193373282e041002 to your computer and use it in GitHub Desktop.
Save hugoeanogueira/d1462696f6bd38f6193373282e041002 to your computer and use it in GitHub Desktop.
Running services on boot using systemd

systemd

Add an entry in systemd for your service, adding the following file to /lib/systemd/system/steinway.service.

[Unit]
Description=Example node JS app
Documentation=https://www.example.com
After=network.target

[Service]
Environment=NODE_PORT=8080
Type=simple
User=node
ExecStart=/usr/bin/npm --prefix /srv/steinway
Restart=on-failure

[Install]
WantedBy=multi-user.target

Systemctl useful commands:

# check if service is already running
$ sudo systemctl status steinway

# control the lifecycle of the service
$ sudo systemctl start steinway
$ sudo systemctl restart steinway
$ sudo systemctl stop steinway

# enable the service to start on boot
$ sudo systemctl enable steinway

# disable the service from starting on boot
$ sudo systemctl disable steinway

More info at:
https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-1/
https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment