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

DirectiveDescriptionDefaultExample
Description=Human-readable description of the unit, shown in systemctl status output.noneDescription=My Web App
After=Ordering directive — start this unit after the listed units. Does not create a dependency.noneAfter=network.target postgresql.service
Before=Ordering directive — start this unit before the listed units.noneBefore=nginx.service
Requires=Hard dependency — if the required unit fails, this unit fails too.noneRequires=postgresql.service
Wants=Soft dependency — systemd tries to start the wanted unit but continues if it fails.noneWants=redis.service
BindsTo=Like Requires=, but also stops this unit when the bound unit stops.noneBindsTo=docker.service
Conflicts=This unit cannot run at the same time as the conflicting unit.noneConflicts=iptables.service

systemd [Service] Section Directives

DirectiveDescriptionDefaultExample
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.simpleType=forking
ExecStart=The command to run when starting the service. Must be an absolute path.noneExecStart=/usr/sbin/nginx
ExecStartPre=Command to run before ExecStart. Prefix with - to ignore failures.noneExecStartPre=/usr/sbin/nginx -t
ExecReload=Command to run when systemctl reload is called.noneExecReload=/bin/kill -HUP $MAINPID
ExecStop=Command to run when stopping the service.SIGTERMExecStop=/usr/sbin/nginx -s quit
Restart=When to restart the service. no, on-success, on-failure, on-abnormal, on-abort, always.noRestart=on-failure
RestartSec=Delay in seconds between restart attempts.100msRestartSec=5
User=Run the service as this user.rootUser=www-data
Group=Run the service as this group.rootGroup=www-data
WorkingDirectory=Set the working directory before starting the service./WorkingDirectory=/opt/myapp
Environment=Set environment variables for the service process.noneEnvironment=NODE_ENV=production
EnvironmentFile=Read environment variables from a file.noneEnvironmentFile=/etc/myapp/env
MemoryMax=Hard memory limit enforced by cgroups. The OOM killer terminates the process if exceeded.unlimitedMemoryMax=512M
CPUQuota=CPU time limit as a percentage of one core.unlimitedCPUQuota=200%
TasksMax=Maximum number of tasks (processes + threads) the service may create.4096TasksMax=100

systemd [Timer] Section Directives

DirectiveDescriptionDefaultExample
OnCalendar=Calendar-based schedule. Accepts systemd calendar syntax.noneOnCalendar=*-*-* 02:00:00
OnBootSec=Run this many seconds after boot.noneOnBootSec=5min
OnUnitActiveSec=Run this many seconds after the unit was last activated.noneOnUnitActiveSec=1h
Persistent=If true, run the timer immediately if the system was off during the scheduled time.falsePersistent=true
RandomizedDelaySec=Add a random delay (up to this value) to avoid all timers firing simultaneously.0RandomizedDelaySec=15min
AccuracySec=Coalesce timer events within this window for power efficiency.1minAccuracySec=1s

systemd [Install] Section Directives

DirectiveDescriptionDefaultExample
WantedBy=Target that pulls in this unit when enabled. Creates a symlink in the target's .wants/ directory.noneWantedBy=multi-user.target
RequiredBy=Target that requires this unit when enabled.noneRequiredBy=multi-user.target
Alias=Alternative name for the unit.noneAlias=myapp.service