February 17, 2017

Node and systemd

For a while now I’ve had my dashboard combo tv and dashboard combo, which runs on dashing and dashkiosk, running in screen sessions. This , of course, is not very managable. If something breaks, you have to ssh in and then find the screen session, re-run the command. In comes systemd. This makes managing services easy! You are able to make anything a system managed service, being able to manage the service via the systemctl commands

Here are the systemd unit files I use for both dashing and dashkiosk. Just put them in /etc/systemd/system and away you go

Dashkiosk

[Unit]
Description=Dashkiosk dashboard admin

[Service]
ExecStart=/usr/bin/node server.js --environment production
Restart=always
User=root
Group=root
WorkingDirectory=/home/george/dashkiosk-2.6.6/dist/

[Install]
WantedBy=multi-user.target

Dashing

[Unit]
Description=Dashing Dashboard

[Service]
ExecStart=/usr/local/bin/dashing start -e production -p 80
Restart=always
User=root
Group=root
WorkingDirectory=/home/george/work-dashboard/

[Install]
WantedBy=multi-user.target

As you can see here, I am starting my services as root, as I need to use port 80 for the dashboard. But you can probably just run these as a standard user if you do not need privileged ports