Systemd & Services

Systemd unit management, quadlet files, socket activation, and RHEL 10 systemd changes.

Overview

Systemd is the init system and service manager for RHEL 10. It manages services, sockets, timers, mounts, and more through unit files.

# Check service status
systemctl status httpd

# Enable and start a service
sudo systemctl enable --now httpd

# Stop and disable
sudo systemctl disable --now httpd

# List failed units
systemctl --failed

# List all loaded units
systemctl list-units --type=service --state=running

# View unit file
systemctl cat httpd

Custom Unit Files

# Create a custom service
sudo tee /etc/systemd/system/myapp.service <<'EOF'
[Unit]
Description=My Application
After=network.target
Wants=network.target

[Service]
Type=simple
ExecStart=/opt/myapp/bin/myapp
Restart=on-failure
RestartSec=5
User=myapp
Group=myapp

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now myapp.service

Socket Activation

Socket activation starts services on-demand when a connection arrives, reducing boot time and resource usage.

# Example socket unit
sudo tee /etc/systemd/system/myapp.socket <<'EOF'
[Unit]
Description=My App Socket

[Socket]
ListenStream=8080
Accept=no

[Install]
WantedBy=sockets.target
EOF

# Matching service (Type=simple, no ExecStart needed for socket activation)
sudo systemctl enable --now myapp.socket

Quadlet Files (RHEL 10)

Quadlet files let you manage Podman containers through systemd using .container and .volume unit files, similar to Docker Compose.

# Create a Quadlet container file
sudo tee /etc/systemd/system/myapp.container <<'EOF'
[Unit]
Description=My App Container

[Container]
Image=registry.access.redhat.com/ubi10/ubi-minimal
Exec=echo hello
Port=8080:80
Volume=data:/app/data:Z

[Install]
WantedBy=multi-user.target
EOF

# Optional volume file
sudo tee /etc/systemd/system/myapp.volume <<'EOF'
[Volume]
Driver=local
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now myapp.container

Timers (cron replacement)

# Create a timer unit
sudo tee /etc/systemd/system/backup.timer <<'EOF'
[Unit]
Description=Daily Backup Timer

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target
EOF

# Matching service
sudo tee /etc/systemd/system/backup.service <<'EOF'
[Unit]
Description=Run Backup

[Service]
Type=oneshot
ExecStart=/usr/local/bin/backup.sh
EOF

sudo systemctl enable --now backup.timer
systemctl list-timers --all

Journal & Logs

# View logs for a service
sudo journalctl -u httpd

# Follow logs in real time
sudo journalctl -u httpd -f

# Logs since last boot
sudo journalctl -b

# Logs from a specific time range
sudo journalctl --since '2026-05-01' --until '2026-05-02'

# Persistent logging (survives reboot)
sudo mkdir -p /var/log/journal
sudo systemd-tmpfiles --create --prefix /var/log/journal
sudo systemctl restart systemd-journald

Targets (Runlevels)

# Current default target
systemctl get-default

# Change to multi-user (no GUI)
sudo systemctl set-default multi-user.target

# Change to graphical (with GUI)
sudo systemctl set-default graphical.target

# List available targets
systemctl list-unit-files --type=target