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.

Entry image

Create a configfile for the service in

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)

Published 2014-07-08