Services: running, start, autostart
Check if a service is running, start and stop it, and enable or disable autostart at boot with systemctl.
The idea
systemd starts the system and keeps services (daemons) running. Each service is described by a unit file, e.g. ssh.service. You control them with systemctl. The .service suffix is optional: systemctl status nginx is enough.
A service has two independent states:
| State | Question | Change with |
|---|---|---|
| active / inactive / failed | Is it running now? | start, stop, restart |
| enabled / disabled | Does it start at boot? | enable, disable |
So enable alone does not start a service, and stop does not prevent it from starting at the next boot.
Is it running?
systemctl status nginx
● nginx.service - A high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running) since Tue 2026-10-21 08:02:11 UTC; 2h ago
Main PID: 1234 (nginx)
Loaded: ...; enabled→ starts at bootActive: active (running)→ running now.failed→ crashed, the last log lines are shown below.
Short yes/no answers, handy in scripts:
systemctl is-active nginx # active / inactive / failed
systemctl is-enabled nginx # enabled / disabled / masked
Cheat sheet
| What | Command |
|---|---|
| Start / stop / restart | sudo systemctl start|stop|restart nginx |
| Reload config without dropping connections | sudo systemctl reload nginx |
| Autostart at boot | sudo systemctl enable nginx |
| Autostart and start now | sudo systemctl enable --now nginx |
| No autostart | sudo systemctl disable nginx |
| No autostart and stop now | sudo systemctl disable --now nginx |
| Block completely (can’t be started at all) | sudo systemctl mask nginx (unmask to undo) |
| What failed? | systemctl --failed |
| All running services | systemctl list-units --type=service --state=running |
| All services with autostart | systemctl list-unit-files --type=service --state=enabled |
| Show the unit file | systemctl cat nginx |
| After editing unit files | sudo systemctl daemon-reload |
| Logs of the service | journalctl -u nginx -n 50 (more: Searching logs) |
Change a service without touching the package file
sudo systemctl edit nginx
This creates an override in /etc/systemd/system/nginx.service.d/override.conf that survives package updates. Example: always restart the service if it crashes.
[Service]
Restart=on-failure
RestartSec=5
Your own service
To run your own program or script as a service (with autostart and restart on crash):
[Unit]
Description=My App
After=network-online.target
Wants=network-online.target
[Service]
User=myapp
ExecStart=/opt/myapp/bin/myapp
Restart=on-failure
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now myapp
WantedBy=multi-user.target is what makes enable work: it means “start during normal boot”. For a dedicated myapp user, see Permission best practices.