Cheat SheetsLinuxServices

Services — Cheat Sheet

Linux · 1 topics. Download the PDF or the Instagram carousel and share it.

Cheat Sheet · AiCanCode.org
Services
Linux1 topicsQuick revision reference
1

systemd — Service Management

systemd is the init system and service manager on modern Linux distros. systemctl, journalctl, and unit files let you start, stop, enable, and inspect any service on the system.

  • systemctl enable --now is the one command to both enable at boot and start immediately.
  • journalctl -u service -f follows live logs for a specific service — like tail -f but better.
  • After a .service file change, run systemctl daemon-reload before systemctl restart.
  • Restart=on-failure + RestartSec provides automatic recovery for crashed services.
  • EnvironmentFile keeps secrets out of the unit file (which is world-readable).
  • systemd-analyze blame shows which services slow down boot — essential for optimisation.
bash — systemctl service management
# Service lifecycle
systemctl start nginx          # start now
systemctl stop nginx           # stop now
systemctl restart nginx        # stop then start
systemctl reload nginx         # reload config without full restart (if supported)
systemctl enable nginx         # start at boot
systemctl disable nginx        # don't start at boot
systemctl enable --now nginx   # enable + start in one command

# Status and inspection
systemctl status nginx
# ● nginx.service - A high performance web server
#      Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
#      Active: active (running) since Mon 2024-01-15 10:00:00 UTC; 2h 5min ago
#    Main PID: 1234 (nginx)
#     CGroup: /system.slice/nginx.service
#             ├─1234 nginx: master process
#             â””─1235 nginx: worker process

# Is the service active/enabled?
systemctl is-active nginx      # "active" or "inactive"
systemctl is-enabled nginx     # "enabled" or "disabled"

# System-wide
systemctl list-units --type=service          # all loaded services
systemctl list-units --type=service --failed # failed services
systemctl list-unit-files --type=service     # all installed service files

# Boot analysis
systemd-analyze time          # total boot time
systemd-analyze blame         # which services took longest to start
systemd-analyze critical-chain nginx  # dependency chain for nginx
Learn this free with Aria, your AI tutor → AiCanCode.org/learn/linux