Skip to content

Instantly share code, notes, and snippets.

@alanshaw
Created November 24, 2016 13:08
Show Gist options
  • Save alanshaw/75880e3178addf8dd4811d94c3400905 to your computer and use it in GitHub Desktop.
Save alanshaw/75880e3178addf8dd4811d94c3400905 to your computer and use it in GitHub Desktop.
upstart -> systemd

upstart -> systemd

I can recommend having a quick read through this: https://wiki.ubuntu.com/SystemdForUpstartUsers

Instead of putting your upstart config in /etc/init you put it in /etc/systemd/system and it has a different format. Systemd configs are called "units" and (for us) look like:

[Unit]
Description=Job that runs the {{service}} service

[Service]
Type=simple
WorkingDirectory=/home/{{service}}/current/src
ExecStart=/usr/bin/npm start
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier={{service}}
User={{service}}
Group={{service}}
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

Most of these are self explanatory.

Note: You HAVE to use full paths to binaries.

Type=simple - it is ready when the process is started. You can set this to "fork" and it will be ready when it has spawned another process and the original has exited

WantedBy=multi-user.target - adds this unit as a dependency of the "multi-user.target" unit, which is a built in unit of systemd. Essentially it allows you to specify when your unit is started/stopped

No more logrotate or tail /var/log/upstart/{{service}}.log:

journalctl -u node-sample

Where "node-sample" is SyslogIdentifier.

This article was also helpful: https://blog.codeship.com/running-node-js-linux-systemd/

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