Skip to content

Instantly share code, notes, and snippets.

@GopherJ
Forked from zsiegel/systemd-example.md
Created August 2, 2018 13:28
Show Gist options
  • Save GopherJ/4cadcacf4e97e415ec2bf214c8b39790 to your computer and use it in GitHub Desktop.
Save GopherJ/4cadcacf4e97e415ec2bf214c8b39790 to your computer and use it in GitHub Desktop.
systemd example - works on Ubuntu 16.04

Ubuntu 16.04 systemd service setup

Enable persistent user systemd services

loginctl enable-linger $user

Create a user systemd directory

mkdir ~/.config/systemd/user

Create a systemd configuration

touch my-service.service

Example service

[Unit]
Description=myservice
After=network.target

[Service]
EnvironmentFile=/home/user/.myservice_env
Restart=always
RestartSec=5
ExecStart=/usr/bin/java -jar /home/user/my-service.jar

[Install]
WantedBy=multi-user.target
# WantedBy=default.target *use this if you want to start on boot*

For more info and details of options checkout this

Reload the user daemon (this must be done on every change to your service file)

systemctl --user daemon-reload

Starting and or stop your service as needed

systemctl --user [start|stop|restart] my-service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment