Name origin: systemd = "system daemon." Created by Lennart Poettering and Kay Sievers (Red Hat) in 2010 to replace SysVinit. The controversial "d" follows Unix naming convention (httpd, sshd, crond). systemd is not just an init system — it manages services, logging (journald), networking (networkd), DNS (resolved), time sync (timesyncd), and login sessions (logind). It boots faster than SysVinit by starting services in parallel based on dependency graphs.
# Start / stop / restartsystemctlstartnginx
systemctlstopnginx
systemctlrestartnginx
systemctlreloadnginx# Reload config without restart# Enable / disable (auto-start on boot)systemctlenablenginx
systemctldisablenginx
systemctlenable--nownginx# Enable AND start immediately# Status and inspectionsystemctlstatusnginx# Status + recent logssystemctlis-activenginx# Just "active" or "inactive"systemctlis-enablednginx# "enabled" or "disabled"systemctlis-failednginx# "failed" or "active"systemctlshownginx# All propertiessystemctlshownginx-pMainPID# Specific propertysystemctlcatnginx# Show unit file contents# List servicessystemctllist-units--type=service# Running servicessystemctllist-units--type=service--state=failed# Failed servicessystemctllist-unit-files--type=service# All installed services
# View logs for a servicejournalctl-unginx# All logs for unitjournalctl-unginx-e# Jump to end (most recent)journalctl-unginx-f# Follow (like tail -f)journalctl-unginx--since"1 hour ago"journalctl-unginx--since"2024-01-15 09:00"--until"2024-01-15 10:00"# Filter by priorityjournalctl-perr# Errors and abovejournalctl-pwarning-unginx# Warnings and above for nginx# Priority levels: emerg, alert, crit, err, warning, notice, info, debug# Kernel messagesjournalctl-k# Kernel messages (like dmesg)journalctl-k-b-1# Kernel messages from previous boot# Boot logsjournalctl-b# Current bootjournalctl-b-1# Previous bootjournalctl--list-boots# List all recorded boots# Output formatsjournalctl-unginx-ojson-pretty# JSON formatjournalctl-unginx-oshort-precise# Precise timestampsjournalctl-unginx--no-pager# Disable paging (for scripts)journalctl-unginx-n50# Last 50 lines# Disk usagejournalctl--disk-usage# How much space logs consumejournalctl--vacuum-size=500M# Shrink to 500MBjournalctl--vacuum-time=7d# Keep only last 7 days
Gotcha:journalctl -u <service> -f follows logs but only shows the journal — if the service writes to a file (e.g., /var/log/myapp.log), journalctl will not show it. Check the service's StandardOutput= and StandardError= settings with systemctl cat <service>. For container-style services, stdout/stderr logging via journald is preferred.
Soft dependency — if it fails, this unit still starts
BindsTo=
Like Requires, but also stops when dependency stops
Conflicts=
Cannot run at the same time as listed unit
Remember: After editing a unit file, you MUST run systemctl daemon-reload before the changes take effect. Without it, systemd uses the cached (old) version. This is the #1 "why isn't my change working?" mistake. Mnemonic: "Edit, reload, restart" — three steps, always in that order.
Default trap:Restart=on-failure does NOT restart on clean exit (exit code 0). If your app exits cleanly but should always be running, use Restart=always. The difference matters: a graceful shutdown (SIGTERM handled, exit 0) will not trigger on-failure restart.
# /etc/systemd/system/backup.timer[Unit]Description=Daily backup timer[Timer]OnCalendar=*-*-* 02:00:00# Daily at 2 AM# OnCalendar=hourly # Every hour# OnCalendar=Mon *-*-* 09:00:00 # Every Monday at 9 AM# OnBootSec=5min # 5 minutes after boot# OnUnitActiveSec=1h # 1 hour after last activationPersistent=true# Run missed events after downtimeRandomizedDelaySec=300# Jitter up to 5 minutes[Install]WantedBy=timers.target
# Timer managementsystemctlenable--nowbackup.timer# Enable and start timersystemctllist-timers--all# List all timerssystemctlstatusbackup.timer# Timer statusjournalctl-ubackup.service# Logs from timer-triggered runs
# Reload after editing unit filessystemctldaemon-reload
# Mask a service (prevent start, even by dependencies)systemctlmasknginx
systemctlunmasknginx
# Check boot timesystemd-analyze# Total boot timesystemd-analyzeblame# Time per unitsystemd-analyzecritical-chain# Critical path# View dependenciessystemctllist-dependenciesnginx
systemctllist-dependencies--reversenginx# What depends on nginx# Kill a service's processessystemctlkillnginx
systemctlkill-sSIGKILLnginx# Force kill# Reset failed statesystemctlreset-failednginx
# Edit a unit (creates override)systemctleditnginx# Creates drop-in overridesystemctledit--fullnginx# Edit the full unit file# Overrides go to /etc/systemd/system/nginx.service.d/override.conf
# Find why a service failedsystemctlstatusmyapp&&journalctl-umyapp-e--no-pager-n50# Watch service restarts in real timejournalctl-umyapp-f-oshort-precise
# Create a simple oneshot servicecat>/etc/systemd/system/cleanup.service<< 'EOF'[Unit]Description=Cleanup temp files[Service]Type=oneshotExecStart=/usr/bin/find /tmp -mtime +7 -deleteEOFsystemctldaemon-reload&&systemctlstartcleanup
# Check resource usage of a servicesystemctlshowmyapp-pMemoryCurrent,CPUUsageNSec,TasksCurrent