Skip to content

Arch Linux Systemd Advanced

Mattscreative edited this page Dec 5, 2025 · 2 revisions

Arch Linux systemd Advanced Guide

Complete beginner-friendly guide to advanced systemd usage on Arch Linux, 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 service
sudo systemctl enable myservice

# Start service
sudo systemctl start myservice

⏰ 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: GUI mode
  • rescue.target: Rescue mode
  • emergency.target: Emergency mode

Change Target

Switch target:

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

# Or
sudo systemctl isolate multi-user.target

Troubleshooting

Service Not Starting

Check logs:

# Service logs
journalctl -u service-name

# Recent logs
journalctl -u service-name -n 50

# Follow logs
journalctl -u service-name -f

Unit Errors

Check unit:

# Check unit
systemctl status service-name

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

Summary

This guide covered unit files, creating services, timers, targets, and troubleshooting.


Next Steps


This guide is based on the ArchWiki. For the most up-to-date information, always refer to the official ArchWiki.

Clone this wiki locally