systemd Unit Builder

Generate a production-ready systemd service unit with sane restart, ordering, and security hardening.

Start from

Unit

The file is saved as this name plus .service.

network-online also adds Wants= so the network is pulled in.

Service

The command to run, with an absolute path.

Leave empty to let systemd send SIGTERM.

Seconds to wait before a restart.

Leave empty to run as root.

One KEY=value per line.

Install and schedule

The boot target that pulls this service in.

Generates a second file that starts the service on a calendar schedule.

Hardening (8 of 12 on)

The service and its children can never gain privileges through setuid binaries or capabilities.

Mounts nearly the whole filesystem read-only. An app that writes outside /var needs ReadWritePaths= added by hand.

Hides /home, /root and /run/user. Turn it off for a service that works on files in a home directory.

Gives the service its own /tmp and /var/tmp, invisible to other processes.

Makes /proc/sys and /sys read-only so the service cannot change kernel settings.

Makes the cgroup tree read-only. Leave it off for container runtimes.

Blocks creating setuid or setgid files.

Locks the execution domain, closing an obscure class of kernel emulation bugs.

Hides physical devices, leaving only /dev/null and friends. Breaks services that use serial ports, GPUs or disks directly.

The service cannot load or unload kernel modules.

Blocks creating new namespaces. Breaks container runtimes and some sandboxes (Chromium, bubblewrap).

Blocks memory that is both writable and executable. Breaks JIT runtimes such as Node, Java and PyPy.

23 lines, 468 B
5 lines, 175 B

Related tools

What it does

Builds a complete systemd .service unit file from a sectioned form: description, ExecStart and ExecStop, working directory, user and group, restart policy with a configurable RestartSec, ordering against the network target, and environment variables. Twelve security hardening directives (NoNewPrivileges, ProtectSystem=strict, ProtectHome, PrivateTmp, and more) are individual switches, each with a line on what it does and what it can break, with a conservative set on by default. It can also generate a matching .timer unit as a systemd-native alternative to cron, shown as its own file.

How to use it

Start from a preset (simple service, one-shot script, timer job, Docker container, Node or Python app) or fill in the form, and watch the unit update as you type. A problem such as a relative ExecStart path or a malformed Environment line is flagged next to the field that caused it. Copy or download the .service file, and the .timer file when the schedule switch is on, then run the install commands listed underneath, which use your unit name.

Why this one

Most systemd unit examples online are stale gists copy-pasted from a decade-old blog post, with no hardening and no thought given to the restart policy. This generator produces a current, opinionated unit with security hardening on by default, built entirely in your browser: your files and inputs never leave your device.

FAQ
What does Restart=on-failure do?
It restarts the service automatically when it exits with a nonzero code, is killed by a signal, or times out, but not when it exits cleanly (code 0) or is stopped intentionally with systemctl stop. That makes it the safest default for long-running daemons: crashes recover on their own, deliberate stops stay stopped.
Is the hardening safe to leave on?
The defaults here are a sane, conservative baseline that works for most services out of the box. The one directive to watch is ProtectSystem=strict, which makes almost the entire filesystem read-only to the service: if your app writes files outside /var, you will need to add ReadWritePaths=/your/path to the unit.
Can it make a timer instead of a long-running service?
Yes. Turn on "Run on a schedule" and pick a schedule chip (hourly, daily, weekdays at 9, every 15 minutes) or type any OnCalendar expression. You get a separate .timer file with Persistent=true, so a missed run fires as soon as the system is back up, similar to anacron. The service then has no [Install] section, because the timer is what you enable.

Keyboard shortcuts: press ? anywhere on this page to see them.