Managing Services with systemd and journalctl
On most modern Linux distributions, systemd starts the system and supervises long-running services. A service is described by a unit file, and systemctl is the command you use to control it.
Check and control a service:
bash systemctl status nginx sudo systemctl enable --now nginx sudo systemctl restart nginx systemctl list-units --type=service --state=failed
enable makes a service start at boot and --now also starts it immediately. status shows the recent log lines and whether the process is running.
For your own application, create a unit file in /etc/systemd/system/myapp.service:
bash sudo nano /etc/systemd/system/myapp.service sudo systemctl daemon-reload sudo systemctl enable --now myapp
A minimal unit has a [Unit] section for dependencies, a [Service] section with ExecStart= and Restart=on-failure, and an [Install] section with WantedBy=multi-user.target. Run daemon-reload after every edit.
To read logs, use journalctl:
bash journalctl -u myapp -n 100 --no-pager journalctl -u myapp -f journalctl -u myapp --since "1 hour ago"
The journal keeps logs in binary form, so journalctl is the right tool rather than grepping files. Use systemd-analyze blame to see which units slow down boot.