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

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.