systemd Unit Types Overview
Why systemd Matters in Production
On modern Linux systems, systemd is PID 1. It is responsible for starting, stopping, supervising, and restarting services. If you do not understand systemd, you are not managing production Linux — you are just running processes.
What Is a Unit?
systemd manages resources using unit files called units. Each unit represents something systemd can manage: a service, a socket, a timer, a mount, a device, or a grouping target. In production, thinking in units (instead of raw processes) makes operations predictable.
Most Common Unit Types (Production View)
.service — Background Services
The unit type you will use most. It defines how to start/stop a long-running process and how to supervise it. Examples: nginx, php-fpm, your API, a worker, a queue consumer.
systemctl status nginx systemctl status myapp
.socket — Socket Activation
A socket unit can listen on a port or UNIX socket and start the related service only when traffic arrives. Benefits: faster boot, on-demand start, and better resource usage for rarely-used services.
Production use case: internal admin tools, low-traffic daemons, or services you want to auto-start on connection.
.timer — Scheduled Tasks (Cron Alternative)
Timers replace cron with better reliability:
- Can run missed jobs after reboot (Persistent=true)
- Integrates with journald logging
- Supports jitter/random delays to avoid thundering herds
systemctl list-timers
.target — Grouping and Boot Stages
Targets are not “processes”. They group units and represent system states. Example: multi-user.target is a common “server is up” target.
Production use case: bring up a whole stack by binding units to a target.
.mount / .automount — Mount Management
systemd can manage mounts and even mount on-demand with automount. This is safer than random startup scripts, especially for network filesystems.
.path — Trigger on Filesystem Changes
A path unit can watch a directory/file and trigger a service when something changes. Production use case: drop a file into a directory → a service consumes it.
.slice / .scope — Resource Isolation and One-Off Jobs
systemd uses cgroups under the hood:
- slice: group of services with shared resource policy
- scope: externally started processes that systemd starts tracking
Production use case: enforce CPU/memory limits per service, isolate noisy neighbors on the same host.
Where Unit Files Live
- /usr/lib/systemd/system/ (package-provided; do not edit)
- /etc/systemd/system/ (your overrides and custom units)
How to Inspect Units Fast
systemctl list-units --type=service --state=running systemctl list-unit-files | head systemctl status myapp --no-pager systemctl cat myapp
Common Production Mistakes
- Managing processes with kill/nohup instead of systemd units
- Editing vendor unit files under /usr/lib instead of overriding in /etc
- Using cron for everything and losing logs/observability
- Not understanding that After= is ordering, not readiness
Mental Model
systemd is the supervisor and policy engine of the host. If you want reliability, you define behavior as units: startup, restart, dependencies, limits, logging.
Production Checklist
- Know the key unit types: service, timer, socket, target
- Use /etc/systemd/system for overrides/custom units
- Prefer timers over cron for reliability + journald logs
- Inspect units with systemctl status/cat/show