systemd is the init system and service manager for modern Linux distributions. It's the first process that starts after the kernel loads (PID 1) and is responsible for bringing the system to a usable state.
Think of it as: The "startup manager" that orchestrates all system services and processes.
Created by: Lennart Poettering and Kay Sievers (Red Hat) First Release: 2010 Adopted by: Ubuntu (2015), Debian (2015), RHEL 7+, Fedora, CentOS, Arch Linux, and most major distributions
❌ Slow boot - Services started sequentially (one at a time) ❌ Shell scripts - Init scripts were complex bash scripts ❌ No dependency management - Difficult to handle service dependencies ❌ No process tracking - Lost track of daemon processes ❌ Limited logging - Basic logging capabilities ❌ No socket activation - Services couldn't start on demand
✅ Parallel startup - Starts services simultaneously (much faster boot) ✅ On-demand activation - Starts services when needed (socket/path/device activation) ✅ Better dependency management - Explicit service dependencies ✅ Process tracking - Uses cgroups to track all processes ✅ Unified logging - journald provides centralized logging ✅ Modern features - Timers, automount, network management, etc. ✅ Declarative configuration - Simple unit files instead of complex scripts
1. Power On
↓
2. BIOS/UEFI (POST, hardware initialization)
3. Bootloader (GRUB) loads kernel + initramfs
4. Kernel initializes hardware, mounts root filesystem
5. Kernel starts systemd (PID 1)
6. systemd reads configuration
7. systemd activates default.target
8. systemd starts required services in parallel
├─ System services (networking, logging, etc.)
├─ User services
└─ Target-specific services
9. System reaches target state (multi-user or graphical)
10. Login prompt or GUI appears
systemd (PID 1)
default.target (symlink to graphical.target or multi-user.target)
graphical.target
multi-user.target
basic.target
sysinit.target
local-fs.target + swap.target
Component
Purpose
systemd
Main system and service manager (PID 1)
systemctl
Command to control systemd and manage services
journald
Logging service (system journal)
logind
User session management
networkd
Network configuration manager
resolved
DNS resolver
timesyncd
Network time synchronization
udevd
Device manager
tmpfiles.d
Temporary file management
Units are the basic building blocks of systemd. Everything systemd manages is a unit.
Type
Extension
Example
Service
.service
System services/daemons
sshd.service, nginx.service
sshd.service
nginx.service
Target
.target
Group of units (like runlevels)
multi-user.target, graphical.target
Socket
.socket
IPC/network sockets
sshd.socket, docker.socket
sshd.socket
docker.socket
Device
.device
Hardware devices
dev-sda1.device
Mount
.mount
Filesystem mount points
home.mount, boot.mount
home.mount
boot.mount
Automount
.automount
On-demand mounting
home.automount
Timer
.timer
Scheduled tasks (like cron)
backup.timer, apt-daily.timer
backup.timer
apt-daily.timer
Path
.path
Path-based activation
cups.path
Slice
.slice
Resource management (cgroups)
user.slice, system.slice
user.slice
system.slice
Scope
.scope
Externally created processes
session-1.scope
Swap
.swap
Swap space
dev-sda2.swap
Snapshot
.snapshot
Save/restore system state
(deprecated)
Location: /etc/systemd/system/ or /lib/systemd/system/
/etc/systemd/system/
/lib/systemd/system/
Example: /etc/systemd/system/myapp.service
[Unit]
Description=My Application Service
Documentation=https://myapp.example.com/docs
After=network.target
Requires=network.target
Wants=redis.service
[Service]
Type=simple
User=myapp
Group=myapp
WorkingDirectory=/opt/myapp
ExecStart=/opt/myapp/bin/myapp --config /etc/myapp/config.ini
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5s
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
[Unit] Section:
Directive
Description=
Human-readable description
Documentation=
URLs for documentation
After=
Start after these units
Before=
Start before these units
Requires=
Hard dependency (fails if dependency fails)
Wants=
Soft dependency (continues if dependency fails)
Conflicts=
Cannot run with these units
Condition*=
Start only if condition is met
Assert*=
Assert condition or fail
[Service] Section:
Type=
Service type (simple, forking, oneshot, notify, dbus, idle)
ExecStart=
Command to start service
ExecStop=
Command to stop service
ExecReload=
Command to reload service
Restart=
When to restart (no, on-success, on-failure, always)
RestartSec=
Wait time before restart
User=
User to run service as
Group=
Group to run service as
WorkingDirectory=
Working directory
Environment=
Environment variables
EnvironmentFile=
File with environment variables
StandardOutput=
Where to send stdout (journal, file, null)
StandardError=
Where to send stderr
PIDFile=
Path to PID file
TimeoutStartSec=
Timeout for starting
TimeoutStopSec=
Timeout for stopping
[Install] Section:
WantedBy=
Target that wants this service
RequiredBy=
Target that requires this service
Alias=
Alternative names for unit
Also=
Additional units to enable/disable
Description
Use Case
simple
Process doesn't fork (default)
Most services
forking
Process forks and parent exits
Traditional daemons
oneshot
Process exits after completion
Setup scripts
notify
Service sends notification when ready
Advanced services
dbus
Service acquires D-Bus name
D-Bus services
idle
Delays until all jobs are done
Low priority tasks
systemctl is the main command to interact with systemd.
# Start a service
sudo systemctl start service_name.service
sudo systemctl start nginx
# Stop a service
sudo systemctl stop nginx
# Restart a service
sudo systemctl restart nginx
# Reload service configuration (without restart)
sudo systemctl reload nginx
# Reload or restart if reload not available
sudo systemctl reload-or-restart nginx
# Enable service (start at boot)
sudo systemctl enable nginx
# Disable service (don't start at boot)
sudo systemctl disable nginx
# Enable and start service
sudo systemctl enable --now nginx
# Disable and stop service
sudo systemctl disable --now nginx
# Check if service is enabled
systemctl is-enabled nginx
# Check if service is active
systemctl is-active nginx
# Check if service failed
systemctl is-failed nginx
# Show service status
systemctl status nginx
# Show detailed status
systemctl status -l nginx
What is systemd?
The init system and service manager for modern Linux distributions; the first process (PID 1) that starts after kernel initialization
What PID does systemd always have?
PID 1 (Process ID 1)
Who created systemd and when?
Lennart Poettering and Kay Sievers at Red Hat in 2010
What are the main advantages of systemd over SysVinit?
Parallel service startup, better dependency management, socket activation, unified logging (journald), process tracking with cgroups, and faster boot times
What is the main command to interact with systemd?
What command starts a service?
sudo systemctl start service_name
What command stops a service?
sudo systemctl stop service_name
What command restarts a service?
sudo systemctl restart service_name
What command reloads a service configuration without restarting?
sudo systemctl reload service_name
What command enables a service to start at boot?
sudo systemctl enable service_name
What command disables a service from starting at boot?
sudo systemctl disable service_name
What command shows the status of a service?
systemctl status service_name
What command checks if a service is active?
systemctl is-active service_name
What command checks if a service is enabled?
systemctl is-enabled service_name
What command enables and starts a service simultaneously?
sudo systemctl enable --now service_name
What is a systemd unit?
The basic building block of systemd; everything systemd manages (services, sockets, targets, timers, etc.)
What are the main types of systemd units?
Service (.service), Target (.target), Socket (.socket), Timer (.timer), Mount (.mount), Path (.path), Device (.device)
What is a .service unit?
A unit that manages a system service or daemon
What is a .target unit?
A unit that groups other units together; represents system states (similar to runlevels)
What is a .timer unit?
A unit that schedules tasks based on time (alternative to cron)
Where are system unit files stored?
/lib/systemd/system/ or /usr/lib/systemd/system/ (distribution-provided)
/usr/lib/systemd/system/
Where are custom/administrator unit files stored?
/etc/systemd/system/ (takes priority over distribution files)
What command must you run after creating or modifying unit files?
sudo systemctl daemon-reload
What are the three main sections of a service unit file?
[Unit], [Service], [Install]
What does the [Unit] section contain?
General unit information like Description, dependencies (After, Before, Requires, Wants)
What does the [Service] section contain?
Service-specific settings like Type, ExecStart, Restart, User, WorkingDirectory
What does the [Install] section contain?
Installation information like WantedBy, RequiredBy (used by enable/disable commands)
What are common service types in systemd?
simple (default), forking, oneshot, notify, dbus, idle
What is Type=simple in a service unit?
The process specified in ExecStart is the main process and doesn't fork
What is Type=forking in a service unit?
The process forks and the parent process exits (traditional daemon behavior)
What is Type=oneshot in a service unit?
The process runs once and exits; useful for setup scripts
What is a systemd target?
A unit that groups other units to represent system states (replacement for runlevels)
What target represents multi-user mode without GUI?
multi-user.target (similar to runlevel 3)
What target represents graphical mode with GUI?
graphical.target (similar to runlevel 5)
Zuletzt geändertvor einem Monat