DevTools Logo

Systemd Service & Timer Builder

Systemd Service & Timer Builder

Build systemd unit files with optional hardening and timer schedules.

Runs in your browser
Try an example

Unit settings

Hardening (optional, suggested)

my-app.service

Type=simple: the unit counts as started as soon as the process is forked, even if the program then fails to execute. Type=exec waits for execve() to succeed.
NoNewPrivileges=true blocks setuid/setgid binaries and sudo from gaining privileges inside the service.
PrivateTmp=true gives the service its own /tmp and /var/tmp, so files are not shared with other processes.
[Unit]
Description=My application

[Service]
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/my-app
Environment=APP_ENV=production
NoNewPrivileges=true
ProtectSystem=full
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Examples

Deterministic service with sorted environment

Input
buildSystemdUnits({ type: "exec", restart: "on-failure", environment: { ZED: "2", APP_ENV: "prod" }, execStart: "/srv/app/bin/server" })
Output
Environment=APP_ENV=prod\nEnvironment=ZED=2 plus Type=exec and Restart=on-failure

Environment entries sort by key with localeCompare, so any insertion order renders the identical unit.

Oneshot restart conflict

Input
buildSystemdUnits({ type: "oneshot", restart: "always", execStart: "/usr/bin/backup" })
Output
warnings: ["Type=oneshot cannot be combined with Restart=always; ..."]

oneshot units cannot restart always; the builder keeps the values but flags the conflict in warnings.

About this tool

Systemd Service Builder emits unit files with buildSystemdUnits(config) (aliased as generateSystemdUnits): a [Unit] section with Description and After, a [Service] section with Type (default simple), Restart (default on-failure), User, WorkingDirectory, ExecStartPre/ExecStart/ExecStartPost, alphabetically sorted Environment=KEY=value lines, hardening flags (NoNewPrivileges, ProtectSystem, PrivateTmp), and an [Install] section defaulting to WantedBy=multi-user.target. Newlines inside values are flattened to spaces.

Timer support is built in: passing timer produces a companion unit with its own Description, OnCalendar, OnBootSec, RandomizedDelaySec, and Persistent fields plus WantedBy=timers.target. OnCalendar strings validate through validateCalendarEvent, which accepts *-*-* *:*:* style expressions, weekday ranges like Mon..Fri 09:30, and HH:MM[:SS] times with 00:00:00–23:59:59 range checks — invalid values still emit but add their message to warnings.

The builder warns rather than throws on the classic conflict: Type=oneshot with Restart=always yields "Type=oneshot cannot be combined with Restart=always; systemd rejects it. Use Restart=on-failure or no." Environment ordering is fully deterministic — the same keys in any insertion order produce byte-identical service text.

How to use this tool

  1. Describe the service

    Provide execStart plus optional description, type, restart, user, workingDirectory, and environment; unset fields fall back to simple/on-failure/multi-user.target defaults.

  2. Harden the unit

    Set noNewPrivileges, protectSystem (no/full/strict), and privateTmp to emit their NoNewPrivileges/ProtectSystem/PrivateTmp lines.

  3. Add a timer if needed

    Pass timer with onCalendar (e.g. *-*-* *:*:*), onBootSec, randomizedDelaySec, or persistent; check validateCalendarEvent or warnings for schedule errors.

  4. Heed the warnings

    A Type=oneshot plus Restart=always combination or an invalid OnCalendar surfaces in warnings — switch to Restart=on-failure or no, or fix the calendar expression.

Use cases

Shipping app services

Generate [Unit]/[Service]/[Install] blocks with user, working directory, environment, and ExecStart for daemons.

Scheduling with timers

Pair the service with a timer unit using OnCalendar expressions validated against systemd.time rules.

Applying sandbox hardening

Emit NoNewPrivileges, ProtectSystem=strict, and PrivateTmp to lock down services with private /tmp and read-only system paths.

Common mistakes

Mistake:Pairing Type=oneshot with Restart=always.

Fix:oneshot units exit by design — use Restart=on-failure or no instead, as the warnings message instructs.

Mistake:Writing free-form OnCalendar strings like "tomorrow-ish".

Fix:Use *-*-* *:*:* or weekday HH:MM[:SS] forms; validateCalendarEvent rejects anything else with a Geçersiz OnCalendar message.

Mistake:Relying on environment insertion order.

Fix:Keys always sort alphabetically, so diff-based reviews stay stable — do not encode meaning in the order you typed them.

Frequently asked questions

What does this tool do?

It generates a systemd service unit ([Unit], [Service], [Install] sections with sorted Environment= lines and hardening flags) and, when you supply a timer, a companion timer unit — with warnings for conflicts like Type=oneshot with Restart=always and for invalid OnCalendar expressions.

Why does Type=oneshot with Restart=always produce a warning?

oneshot units are expected to exit after running, so always restarting them is a configuration error. The builder keeps your values but warns in Turkish to pick Restart=on-failure or no instead.

Is my unit configuration uploaded or stored?

No. Unit text is assembled from your inputs with local string templating — nothing leaves your device.

Which OnCalendar formats are accepted?

Systemd calendar forms such as *-*-* *:*:* and weekday ranges like Mon..Fri 09:30, with HH:MM[:SS] times range-checked to 00:00:00–23:59:59. Free-form strings like tomorrow-ish fail validation and surface their message in warnings while the timer still emits.

References & standards