Click any command to expand the explanation and examples.
🔧 Service Management
start / stop / restart / status basics
sudo systemctl start nginx sudo systemctl stop nginx sudo systemctl restart nginx sudo systemctl reload nginx # Reload config without restartsystemctl status nginx # Check status (no sudo needed)
Is it running?
systemctl is-active nginx # “active” or “inactive” systemctl is-failed nginx # “failed” or “active”
enable / disable — start on boot basics
# Start on boot sudo systemctl enable nginxStart on boot AND start now
sudo systemctl enable —now nginx
Don’t start on boot
sudo systemctl disable nginx
Check if enabled
systemctl is-enabled nginx # “enabled” or “disabled”
List services basics
# All running services systemctl list-units --type=service --state=runningAll services (including stopped)
systemctl list-units —type=service —all
Failed services
systemctl —failed
All enabled services
systemctl list-unit-files —type=service —state=enabled
📋 Logs (journalctl)
View service logs logs
# Logs for a service journalctl -u nginxFollow (stream) logs
journalctl -u nginx -f
Last 50 lines
journalctl -u nginx -n 50
Since a time
journalctl -u nginx —since “1 hour ago” journalctl -u nginx —since “2026-03-14 10:00”
Only errors
journalctl -u nginx -p err
Boot logs
journalctl -b # Current boot journalctl -b -1 # Previous boot
Disk usage
journalctl —disk-usage
Clean old logs
sudo journalctl —vacuum-time=7d # Keep last 7 days sudo journalctl —vacuum-size=500M # Keep max 500MB
📝 Create a Custom Service
Service unit file custom
# /etc/systemd/system/myapp.service [Unit] Description=My Node.js App After=network.target[Service] Type=simple User=deploy WorkingDirectory=/home/deploy/myapp ExecStart=/usr/bin/node dist/index.js Restart=on-failure RestartSec=5 Environment=NODE_ENV=production Environment=PORT=3000
[Install] WantedBy=multi-user.target
# After creating/editing the file: sudo systemctl daemon-reload # Reload unit files sudo systemctl enable --now myapp systemctl status myapp