Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hazulifidastian/2a0c8cd95f59a8b2dd45ccfbdc7f68b9 to your computer and use it in GitHub Desktop.
Save hazulifidastian/2a0c8cd95f59a8b2dd45ccfbdc7f68b9 to your computer and use it in GitHub Desktop.
Create systemd user service for elixir release.

Create service file

$ touch ~/.config/systemd/user/your-service.service

your-service.service file

[Unit]
Description=Your App - descripction
After=network.target

[Service]
ExecStart=/path/to/your/app/bin/your_app start
ExecStop=/path/to/your/app/bin/your_app start stop
SyslogIdentifier=simple
Restart=always

# 'StartLimitInterval' must be greater than 'RestartSec * StartLimitBurst' otherwise the service will be restarted indefinitely.
# https://serverfault.com/a/800631
RestartSec=5
StartLimitBurst=3
StartLimitInterval=10

[Install]
WantedBy=default.target

Service commands

# reload user daemon
$ systemctl --user daemon-reload

# confirm service is available
$ systemctl --user list-unit-files your-service.service

# enable service
$ systemctl --user enable --now your-service.service

# check status
$ systemctl --user status your-service.service

# stop service
$ systemctl --user stop --now your-service.service

# enable load user service on boot
$ loginctl enable-linger username
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment