systemd unit file directives reference
Complete reference for systemd unit file directives across Unit, Service, Timer, and Install sections.
systemd unit file directives reference
Complete reference for systemd unit file directives across Unit, Service, Timer, and Install sections.
systemd [Unit] Section Directives
| Directive | Description | Default | Example |
|---|---|---|---|
Description= | Human-readable description of the unit, shown in
systemctl status output. | none | Description=My Web App |
After= | Ordering directive — start this unit after the listed units. Does not create a dependency. | none | After=network.target postgresql.service |
Before= | Ordering directive — start this unit before the listed units. | none | Before=nginx.service |
Requires= | Hard dependency — if the required unit fails, this unit fails too. | none | Requires=postgresql.service |
Wants= | Soft dependency — systemd tries to start the wanted unit but continues if it fails. | none | Wants=redis.service |
BindsTo= | Like
Requires=, but also stops this unit when the bound unit stops. | none | BindsTo=docker.service |
Conflicts= | This unit cannot run at the same time as the conflicting unit. | none | Conflicts=iptables.service |
systemd [Service] Section Directives
| Directive | Description | Default | Example |
|---|---|---|---|
Type= | How systemd determines the service is "started."
simple (default): the
ExecStart process is the main process.
forking: the process forks and the parent exits.
oneshot: the process runs once and exits.
notify: the process sends a readiness signal. | simple | Type=forking |
ExecStart= | The command to run when starting the service. Must be an absolute path. | none | ExecStart=/usr/sbin/nginx |
ExecStartPre= | Command to run before
ExecStart. Prefix with
- to ignore failures. | none | ExecStartPre=/usr/sbin/nginx -t |
ExecReload= | Command to run when
systemctl reload is called. | none | ExecReload=/bin/kill -HUP $MAINPID |
ExecStop= | Command to run when stopping the service. | SIGTERM | ExecStop=/usr/sbin/nginx -s quit |
Restart= | When to restart the service.
no,
on-success,
on-failure,
on-abnormal,
on-abort,
always. | no | Restart=on-failure |
RestartSec= | Delay in seconds between restart attempts. | 100ms | RestartSec=5 |
User= | Run the service as this user. | root | User=www-data |
Group= | Run the service as this group. | root | Group=www-data |
WorkingDirectory= | Set the working directory before starting the service. | / | WorkingDirectory=/opt/myapp |
Environment= | Set environment variables for the service process. | none | Environment=NODE_ENV=production |
EnvironmentFile= | Read environment variables from a file. | none | EnvironmentFile=/etc/myapp/env |
MemoryMax= | Hard memory limit enforced by cgroups. The OOM killer terminates the process if exceeded. | unlimited | MemoryMax=512M |
CPUQuota= | CPU time limit as a percentage of one core. | unlimited | CPUQuota=200% |
TasksMax= | Maximum number of tasks (processes + threads) the service may create. | 4096 | TasksMax=100 |
systemd [Timer] Section Directives
| Directive | Description | Default | Example |
|---|---|---|---|
OnCalendar= | Calendar-based schedule. Accepts systemd calendar syntax. | none | OnCalendar=*-*-* 02:00:00 |
OnBootSec= | Run this many seconds after boot. | none | OnBootSec=5min |
OnUnitActiveSec= | Run this many seconds after the unit was last activated. | none | OnUnitActiveSec=1h |
Persistent= | If
true, run the timer immediately if the system was off during the scheduled time. | false | Persistent=true |
RandomizedDelaySec= | Add a random delay (up to this value) to avoid all timers firing simultaneously. | 0 | RandomizedDelaySec=15min |
AccuracySec= | Coalesce timer events within this window for power efficiency. | 1min | AccuracySec=1s |
systemd [Install] Section Directives
| Directive | Description | Default | Example |
|---|---|---|---|
WantedBy= | Target that pulls in this unit when enabled. Creates a symlink in the target's
.wants/ directory. | none | WantedBy=multi-user.target |
RequiredBy= | Target that requires this unit when enabled. | none | RequiredBy=multi-user.target |
Alias= | Alternative name for the unit. | none | Alias=myapp.service |