Skip to content

Instantly share code, notes, and snippets.

@hx
Created July 2, 2022 22:31
Show Gist options
  • Save hx/e49e61d4337eed860313774935c3b68e to your computer and use it in GitHub Desktop.
Save hx/e49e61d4337eed860313774935c3b68e to your computer and use it in GitHub Desktop.
Systemd Cheat Sheet

I'm constantly forgetting how to write and install these. Here's my crib sheet.

Make a new service

$ sudo vim /lib/systemd/system/name_of_service.service
[Unit]
Description=Name of Service
Wants=network-online.target

[Service]
Type=simple
User=someuser
Group=somegroup
Restart=always
RestartSec=3sec
Environment="SOME_VAR=some value"
Environment="SOME_OTHER_VAR=some other value"
ExecStart=/path/to/some/executable arg1 arg[n]

# For `systemd --version` >= 236:
StandardOutput=file:/path/to/activity.log
StandardError=append:/path/to/persisted/error.log

[Install]
WantedBy=multi-user.target

Enable the service at boot

$ sudo systemctl enable name_of_service.service

Start/stop/restart the service

$ sudo service name_of_service [start|stop|restart]

Status

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