systemd is the service manager. It starts, stops, and manages daemons (background processes). Services are defined as unit files.
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
List all loaded services:
systemctl list-units --type=service systemctl list-units --type=service --state=running systemctl list-units --type=service --state=failed
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
ssh — remote accessapache2/nginx — web serversmysql/postgresql — databasesdocker — container runtimecron — scheduled taskssyslog — system loggingCheck 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.