TOOL » LINUX » SYSTEMCTL

Service

Usage

Root privileges are often needed when running systemctl commands.

shell
systemctl OPTION ACTION my.service
OptionDescription
--userUse the user service manager.
ActionDescription
startStart the service.
stopStop the service.
restartRestart the service.
enableEnable automatic service startup on boot.
disableDisable automatic service startup on boot.

Creation

ScopePath
System/etc/systemd/system
User~/.config/systemd/user

System service

ini
# something.service
[Unit]
Description=some service
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
User=mateus
Environment=DISPLAY=:0
EnvironmentFile=/etc/someservice/someservice.conf
ExecStart=/path/to/script.py

[Install]
WantedBy=multi-user.target

User service

Replace {HOME} with your home directory.

ini
# caddy.service
[Unit]
Description=Caddy web server
Documentation=https://caddyserver.com/docs/
After=network.target

[Service]
Type=notify
ExecStartPre=/usr/bin/caddy validate --config {HOME}/.local/server/Caddyfile
ExecStart=/usr/bin/caddy run --config {HOME}/.local/server/Caddyfile
ExecReload=/usr/bin/caddy reload --config {HOME}/.local/server/Caddyfile --force
Restart=on-abnormal
TimeoutStopSec=5s

[Install]
WantedBy=default.target