wiki: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.
wiki/debian-services-and-systemd.md · Last modified: by 127.0.0.1
