Skip to main content

systemd Reference

v1.0.0

Unit file directives for [Unit], [Service], [Install], [Timer], and [Socket] sections.

21 entries found

Description
string[Unit]

A free-form string describing the unit. Shown in systemctl status output.

[Unit]
Description=My Application Server
After
string (space-separated)[Unit]

Ensures this unit starts after the listed units. Does not create a dependency itself — combine with Wants or Requires.

[Unit]
After=network.target postgresql.service
Before
string (space-separated)[Unit]

Ensures this unit starts before the listed units. The reverse of After.

[Unit]
Before=nginx.service
Requires
string (space-separated)[Unit]

Hard dependency. If any Requires unit fails to start, this unit is also deactivated.

[Unit]
Requires=postgresql.service
Wants
string (space-separated)[Unit]

Soft dependency. Starts the listed units together with this one but does not fail if they cannot start.

[Unit]
Wants=redis.service
ConditionPathExists
path[Unit]

Only starts the unit if the given path exists. Prefix with ! to invert. Useful for optional-component units.

[Unit]
ConditionPathExists=/etc/myapp/config.toml
PartOf
string (space-separated)[Unit]

Binds stop/restart propagation to the listed units. If the parent stops or restarts, so does this unit.

[Unit]
PartOf=myapp.target
Type
enum[Service]

Controls how systemd considers the service started. Values: simple (default), exec, forking, oneshot, notify, dbus, idle.

[Service]
Type=notify
ExecStart
command[Service]

Command to execute when starting the service. For oneshot services, multiple ExecStart entries are allowed.

[Service]
ExecStart=/usr/bin/node /opt/myapp/index.js
ExecStop
command[Service]

Command to run when stopping the service. Receives the same environment as ExecStart.

[Service]
ExecStop=/usr/bin/node /opt/myapp/stop.js
ExecReload
command[Service]

Command to reload the service's configuration without a full restart. Commonly sends SIGHUP.

[Service]
ExecReload=/bin/kill -HUP $MAINPID
Restart
enum[Service]

When to automatically restart the service. Values: no, always, on-success, on-failure, on-abnormal, on-watchdog, on-abort.

[Service]
Restart=on-failure
RestartSec=5s
User / Group
string[Service]

Sets the user (and group) to run the service as. Strongly recommended to avoid running services as root.

[Service]
User=myapp
Group=myapp
WorkingDirectory
path[Service]

Sets the working directory for ExecStart and related commands. Prefix ~ for the user's home directory.

[Service]
WorkingDirectory=/opt/myapp
Environment
string[Service]

Sets environment variables for the service process. Use EnvironmentFile to load from a file.

[Service]
Environment=NODE_ENV=production PORT=3000
EnvironmentFile=-/etc/myapp/env
StandardOutput / StandardError
enum[Service]

Where to send stdout/stderr. Values: journal, syslog, kmsg, null, inherit, file:<path>. Default is journal.

[Service]
StandardOutput=journal
StandardError=journal
LimitNOFILE
integer[Service]

Sets the maximum number of open file descriptors for the service. Useful for high-concurrency servers.

[Service]
LimitNOFILE=65536
WantedBy
string (space-separated)[Install]

Specifies which target to register the unit under when enabled. multi-user.target is the standard for most services.

[Install]
WantedBy=multi-user.target
Also
string (space-separated)[Install]

Additional units to enable/disable when this unit is enabled/disabled.

[Install]
WantedBy=multi-user.target
Also=myapp-watcher.service
OnCalendar
calendar expression[Timer]

Triggers activation at specified calendar times. Syntax: DayOfWeek Year-Month-Day Hour:Minute:Second. Use systemd-analyze calendar to validate.

[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true
OnBootSec
time span[Timer]

Triggers activation a specified time after the system was booted.

[Timer]
OnBootSec=10min
OnUnitActiveSec=1h