Node and systemd, BFF!

Since Centos7 was released in July, a “nondesktop” distro(other than rhel7 ofc) is using systemd.
Like it, hate it or discuss it, systemd is here to stay.
As we have been discussing internally how to manage startup of nodejs apps, using monit/pm2/others has been alternatives, and now, imho, systemd is sailing up as the better option. And the main reason is KISS. systemd will already handle the rest of your stack, so why add more.

So how to use it? This is the simplest way.

Create a configfile for the service in
/etc/systemd/system/node-hello.service

So “ExecStart” is obviously first the node binary, then your app.
“Restart” makes sure it starts again if it dies.

Then systemctl is your friend for controlling it:

And for the logs, we use journalctl:

Now ofcourse there is a billion things you can make systemd do, like cute things like have it listen on a port and stop and start your nodeapp as it is being used, but thats another story(post)

More to read about Software engineering
SUBSCRIBE TO OUR UPDATES
Menu