# 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: ```bash sudo systemctl start ssh ``` Stop: ```bash sudo systemctl stop ssh ``` Restart: ```bash sudo systemctl restart ssh ``` Check status: ```bash sudo systemctl status ssh ``` Enable on boot: ```bash sudo systemctl enable ssh ``` Disable from boot: ```bash sudo systemctl disable ssh ``` ## Listing Services List all loaded services: ```bash 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: ```ini [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: ```bash sudo systemctl daemon-reload sudo systemctl start myservice ``` ## Common Services - `ssh` — remote access - `apache2`/`nginx` — web servers - `mysql`/`postgresql` — databases - `docker` — container runtime - `cron` — scheduled tasks - `syslog` — system logging ## Troubleshooting Check logs: ```bash 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: ```bash sudo systemctl daemon-reload ``` Services set to start on boot if `[Install]` section has `WantedBy=multi-user.target`.