debian-services-and-systemd
Debian services and systemd
Table of Contents
Debian services and systemd
systemd is the service manager. It starts, stops, and manages daemons (background processes). Services are defined as unit files.
Basic commands
Start a service:
sudo systemctl start ssh
Stop:
sudo systemctl stop ssh
Restart:
sudo systemctl restart ssh
Check status:
sudo systemctl status ssh
Enable on boot:
sudo systemctl enable ssh
Disable from boot:
sudo systemctl disable ssh
Listing services
List all loaded services:
systemctl list-units --type=service systemctl list-units --type=service --state=running systemctl list-units --type=service --state=failed
Unit files
Located in:
/etc/systemd/system/: local customizations/usr/lib/systemd/system/: package-provided units
Example unit file:
[Unit] Description=My Service After=network.target [Service] Type=simple User=www-data ExecStart=/usr/bin/myapp Restart=on-failure [Install] WantedBy=multi-user.target
After editing:
sudo systemctl daemon-reload sudo systemctl start myservice
Common services
ssh: remote accessapache2/nginx: web serversmysql/postgresql: databasesdocker: container runtimecron: scheduled taskssyslog: system logging
Troubleshooting
Check logs:
journalctl -u ssh journalctl -u ssh -n 50 # last 50 lines journalctl -u ssh -f # follow in real-time
Reload config after editing service files:
sudo systemctl daemon-reload
Services set to start on boot if [Install] section has WantedBy=multi-user.target.
debian-services-and-systemd.md ยท Last modified:
