How do you check and troubleshoot a systemd service on Linux?
Answer
Start with `systemctl status <unit>` to inspect the unit state and recent messages. Use `systemctl start`, `stop` or `restart` only when appropriate, and use `journalctl -u <unit>` for service logs. Also distinguish `enable`, which affects start-at-boot configuration, from `start`, which changes the current runtime state.
Strong answer includes
- systemctl status before blindly restarting
- journalctl -u for unit logs
- distinguishes start from enable
Practical example
If `api.service` is down after deployment, `systemctl status api.service` may reveal an exit code, and `journalctl -u api.service -n 100 --no-pager` provides the startup error without restarting away useful evidence.