What is systemd?
The standard init system on modern Linux distributions (Ubuntu 22.04+, RHEL/Rocky Linux 8+, Debian 11+). It starts services in parallel at boot and manages their dependencies.
Basic Service Operations
Bash
# Check status
systemctl status nginx
# Start / stop / restart
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl reload nginx # Reload configuration only (no downtime)
# Enable/disable start on boot
systemctl enable nginx
systemctl disable nginx
# Enable and start immediately (in one step)
systemctl enable --now nginxViewing All Service Status
Bash
# List running services
systemctl list-units --type=service --state=running
# Check failed services
systemctl --failed
# Analyze boot time
systemd-analyze blame | head -20Writing Your Own Service Unit File
INI
# /etc/systemd/system/myapp.service
[Unit]
Description=My Node.js Application
After=network.target
[Service]
Type=simple
User=deploy
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/node /opt/myapp/server.js
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal
Environment=NODE_ENV=production PORT=3000
[Install]
WantedBy=multi-user.targetAfter writing the file, apply it:
Bash
systemctl daemon-reload # Always run this after changing a unit file
systemctl enable --now myappChecking Logs (journalctl)
Bash
journalctl -u nginx # Full logs for the nginx service
journalctl -u nginx -f # Follow in real time
journalctl -u nginx --since "1 hour ago"
journalctl -u nginx -n 50 # Last 50 lines
journalctl -u nginx -p err # Errors only
journalctl --disk-usage # Log disk usage
journalctl --vacuum-time=7d # Delete logs older than 7 daysTimers (Cron Replacement)
INI
# /etc/systemd/system/backup.timer
[Unit]
Description=Daily Backup Timer
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.targetBash
systemctl enable --now backup.timer
systemctl list-timersEditorial note
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Topic-related official docs (auto-linked · not per-claim sources)Linux man pages ↗
Questions & answers
Ask a question about this guide. We'll review and reply.