systemd-custom-unit

:: system, systemd, tutorial

By: Maciej Barć

Template

File: /etc/systemd/system/APP.service

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[Unit]
Description=Run APP application

[Service]
Type=simple
ExecStart=/usr/bin/LANG APP_DIR/APP APP_ARGS
Restart=on-failure
User=root
WorkingDirectory=APP_DIR

[Install]
WantedBy=multi-user.target

Also, the application might need to reference a PID file, let systemD know abut it via PIDFile.

1
PIDFile=/tmp/APP.pid

Example

File: /etc/systemd/system/julia_dash_app.service

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[Unit]
Description=Run Julia Dash application

[Service]
Type=simple
ExecStart=/usr/bin/julia /root/julia_dash_app/main.jl
Restart=on-failure
User=root
WorkingDirectory=/root/julia_dash_app

[Install]
WantedBy=multi-user.target