Run programs as managed background services — check, start, stop, and restart services with systemctl, make them launch at boot, read their logs with journalctl, and write your own unit file.
Long-running background programs — web servers, databases, SSH — are managed by systemd as "services" (also called "units"). systemctl is how you control them. status is your go-to: it shows whether a service is running ("active"), whether it starts at boot ("enabled"), and the last few log lines, all at once.
Full status: running? enabled at boot? plus recent log lines
systemctl status sshJust a yes/no: is it running right now?
systemctl is-active sshWill it start automatically at boot?
systemctl is-enabled sshThese verbs do exactly what they say. restart stops and starts in one step. reload is gentler when a service supports it — it re-reads the config without dropping connections, ideal for applying a config change with no downtime. All of these change system state, so they need sudo.
Stop a running one
sudo systemctl stop nginxStart a stopped service
sudo systemctl start nginxStop then start (apply changes the blunt way)
sudo systemctl restart nginxRe-read config without dropping connections (if supported)
sudo systemctl reload nginxStarting a service is temporary — it will not come back after a reboot unless you "enable" it. enable registers it to launch at boot; disable undoes that. The handy enable --now does both: enable for the future and start it right now. This is the step people forget, then wonder why their service vanished after a restart.
Stop it from starting at boot (leaves it running for now)
sudo systemctl disable nginxStart now AND start automatically on every boot
sudo systemctl enable --now nginxsystemd captures everything a service prints into a central log you query with journalctl. -u picks one service, -e jumps to the newest entries, and -f follows live like tail -f — the fastest way to watch why a service is failing. --since filters by time in plain English.
Logs for one service, jumping to the most recent (-e)
journalctl -u nginx -eFollow a service's logs live (Ctrl+C to stop)
journalctl -u nginx -fOnly today's entries for a service
journalctl -u nginx --since todayTo run your own program as a managed service, drop a unit file in /etc/systemd/system/. [Unit] describes it and its ordering, [Service] says what to run (ExecStart) and that systemd should Restart it if it crashes, and [Install] sets when it starts at boot. Save this as /etc/systemd/system/myapp.service.
# /etc/systemd/system/myapp.service
[Unit]
Description=My Node App
After=network.target
[Service]
ExecStart=/usr/bin/node /var/www/app/server.js
WorkingDirectory=/var/www/app
User=deploy
Restart=on-failure
[Install]
WantedBy=multi-user.targetAfter creating or editing any unit file, run daemon-reload so systemd notices the change. Then enable --now to start it and set it to launch at boot — and check status to confirm it came up cleanly. From here your app is a first-class service: it restarts on crash, starts on boot, and logs to journalctl like any other.
Tell systemd to re-read unit files after you add or edit one
sudo systemctl daemon-reloadStart it now and enable it at boot
sudo systemctl enable --now myappConfirm it's running
systemctl status myapp