Skip to content

Linux Systemd Advanced

Mattscreative edited this page Dec 5, 2025 · 3 revisions

Linux systemd Advanced Guide

Complete beginner-friendly guide to advanced systemd usage on Linux, covering Arch Linux, CachyOS, and other distributions including unit files, timers, targets, and systemd customization.


Table of Contents

  1. Unit Files
  2. Creating Services
  3. Timers
  4. Targets
  5. Troubleshooting

Unit Files

Understanding Units

Unit types:

  • service: System services
  • timer: Scheduled tasks
  • target: System states
  • mount: Filesystem mounts
  • socket: Network sockets

Unit Locations

Unit directories:

# System units
/etc/systemd/system/

# User units
~/.config/systemd/user/

# Runtime units
/run/systemd/system/

Creating Services

Create Service

Create service file:

# Create service
sudo vim /etc/systemd/system/myservice.service

Example:

[Unit]
Description=My Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/mycommand
Restart=always

[Install]
WantedBy=multi-user.target

Enable Service

Enable service:

# Reload systemd
sudo systemctl daemon-reload

# Enable and start service (recommended method)
sudo systemctl enable --now myservice.service

# Alternative method (for learning):
# sudo systemctl enable myservice.service
# sudo systemctl start myservice.service

⏰ Timers

Create Timer

Create timer:

# Create timer
sudo vim /etc/systemd/system/mytimer.timer

Example:

[Unit]
Description=My Timer

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Enable Timer

Enable timer:

# Enable timer
sudo systemctl enable mytimer.timer

# Start timer
sudo systemctl start mytimer.timer

# Check status
systemctl status mytimer.timer

Targets

Understanding Targets

Common targets:

  • multi-user.target: Multi-user mode
  • graphical.target: Graphical mode
  • rescue.target: Rescue mode
  • emergency.target: Emergency mode

Switch Target

Change target:

# Change target
sudo systemctl set-default multi-user.target

# Switch to target
sudo systemctl isolate graphical.target

Troubleshooting

Service Not Starting

Check logs:

# Check service logs
journalctl -u myservice.service

# Check status
systemctl status myservice.service

Unit File Errors

Check syntax:

# Check unit file
systemd-analyze verify /etc/systemd/system/myservice.service

# Reload systemd
sudo systemctl daemon-reload

Summary

This guide covered advanced systemd usage for Arch Linux, CachyOS, and other distributions, including unit files, timers, and targets.


Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally