Upstart to systemd

Now that all the mainstream Linux distros (Debian, Ubuntu, RHEL/Fedora) use systemd, a lot of people are moving from init and Upstart scripts to systemd "Unit files" (I thought they were just called service files).

Here's an upstart configuration for a Go service we use:

# /etc/init/chimney-upstart.conf
description "chimney service"

start on filesystem or runlevel [2345]
stop on runlevel [!2345]

respawn

setuid pusher
setgid pusher

env CHIMNEY_LOG_LEVEL=INFO

exec /usr/local/bin/chimney -config=/etc/chimney/config.json

And, translated to a systemd unit file:

# /etc/systemd/system/chimney.service
[Unit]
Description=chimney service

[Service]
Environment=CHIMNEY_LOG_LEVEL=INFO
WorkingDirectory=/home/pusher
User=pusher
ExecStart=/usr/local/bin/chimney -config=/etc/chimney/config.json
Restart=always

[Install]
WantedBy=multi-user.target

And then, we have Salt configured to push out the systemd file if the salt minion is using a new enough version of Ubuntu (16.04 and newer):

{% if grains.oscodename == 'trusty' %}
/etc/init/chimney.conf:
  file.managed:
    - source: salt://chimney/upstart.conf
    - user: root
    - group: root
    - makedirs: True
    - template: jinja
{% else %}
/etc/systemd/system/chimney.service:
  file.managed:
    - source: salt://chimney/chimney.service
    - user: root
    - group: root
    - makedirs: True
    - template: jinja
{% endif %}