systemd Unit Generator
Generate an online systemd service unit from presets, command paths, restart policy, dependencies, and hardening notes for safer Linux service setup.Generated systemd Service
- {{ err }}
{{ unitFileText }}
| Section | Directive | Value | Rationale | Copy |
|---|---|---|---|---|
| {{ row.section }} | {{ row.directive }} | {{ row.value || '-' }} | {{ row.rationale }} |
| Step | Command | Purpose | Copy |
|---|---|---|---|
| {{ row.step }} | {{ row.command }} |
{{ row.purpose }} |
| Severity | Check | Note | Copy |
|---|---|---|---|
| {{ row.severity }} | {{ row.check }} | {{ row.note }} |
Introduction
A systemd service unit tells the Linux service manager how to start, supervise, stop, and enable a process. The file usually needs three kinds of information: a short human label, the command and runtime environment for the process, and the target that should pull the service in when it is enabled.
This matters because a command that works in an interactive shell can fail under the service manager. The service may run as a different user, start from a different directory, miss environment variables, begin before a dependency is ready, or restart in a way that hides the original failure. A good unit file makes those choices explicit before the service reaches production.
Service units are often written during deployment handoff: a web worker moves from a terminal session into a managed daemon, a compiled API binary needs a boot-time target, or a maintenance command needs a one-shot service before a timer is added. In each case, the unit file is both a startup recipe and an operations note for the next person reading status output or journal logs.
A generated unit is still a draft until the target host accepts it. The service manager can validate syntax, but only the host can prove that the account exists, paths are readable, the binary starts, security restrictions fit the runtime, and logs show the expected behavior.
Technical Details:
Unit files are INI-style text files. A service unit combines generic unit settings, service-specific process settings, and install settings used by enable and disable operations. The important distinction is that dependency choice and startup order are separate. A weak dependency can pull another unit into the same start transaction, while ordering decides which unit starts first.
The service process is governed mainly by Type=, ExecStart=, identity settings such as User= and Group=, restart policy, timeouts, and optional runtime directories. Type=exec is a practical default for many foreground services because the start job can fail if the executable cannot be invoked. Type=forking is for legacy daemons that detach and usually needs PIDFile=. Type=oneshot fits commands that run to completion instead of staying alive.
Rule Core:
The generated service file follows a fixed section model. Optional directives appear only when the corresponding value is present or the selected policy requires them.
| Section | Directive family | Meaning | Review cue |
|---|---|---|---|
[Unit] |
Description=, Wants=, After= |
Names the service for status output and sets optional startup relationship with another target. | After= changes order; it does not pull a dependency in by itself. |
[Service] |
Type=, ExecStart=, User=, WorkingDirectory= |
Defines how the process is launched, who owns it, and where the command starts. | Prefer absolute command paths and verify the account and directory on the host. |
[Service] |
Restart=, RestartSec=, TimeoutStartSec=, TimeoutStopSec= |
Controls automatic recovery and bounded start or stop time. | on-failure fits many daemons; always can hide repeated one-shot mistakes. |
[Service] |
Environment=, EnvironmentFile=, StateDirectory=, RuntimeDirectory= |
Provides process variables and lets the manager create state or runtime directories. | Keep secret-bearing values out of inline unit text whenever possible. |
[Service] |
NoNewPrivileges=, PrivateTmp=, ProtectSystem=, ProtectHome= |
Adds sandboxing and file-system protection for the service process. | Strict file-system protection needs explicit writable paths for services that write data. |
[Install] |
WantedBy= |
Controls which target gains a weak dependency when the service is enabled. | multi-user.target is common for server services; user services may need a different target. |
Validation and Warning Boundaries:
Validation catches fields that would make the generated service unsafe to copy directly. Warnings are different: they point to host-dependent choices that can still produce valid unit syntax.
| Condition | Output behavior | Why it matters |
|---|---|---|
Missing Service name or ExecStart |
Shows a red validation error and disables direct service-file copy or download. | A unit without a filename or main command cannot be installed sensibly. |
| Invalid service type, restart policy, startup dependency, or hardening profile | Shows a validation error and keeps the result in a fix-first state. | Only the listed choices are emitted, so corrupted page state is not silently trusted. |
Environment line lacks KEY=value or has an invalid key |
Reports the exact line issue. | Each inline environment entry becomes one Environment= directive. |
| Command, working directory, or environment file uses a suspicious path form | Adds a warning or review note. | Host services should usually use absolute paths so startup does not depend on shell context. |
Type=forking without PIDFile |
Adds a warning. | Legacy forking daemons are easier for the manager to identify when the main PID path is declared. |
| Strict hardening without writable paths | Adds a warning. | ProtectSystem=strict makes the file system read-only except explicit write allowances and managed directories. |
| Strict hardening with common just-in-time runtimes | Adds a review note. | MemoryDenyWriteExecute=yes can break runtimes or libraries that need writable executable memory. |
| Root user or secret-looking inline variables | Adds a review note. | A dedicated service account and protected environment file are usually safer when permissions allow them. |
The install checklist is intentionally conservative. Writing the file under /etc/systemd/system, running systemd-analyze verify, reloading the manager, enabling and starting, checking status, and following logs are separate steps because each one answers a different operational question.
A clean generated file means the page did not find a blocking input error or built-in warning. It does not prove the service binary exists, the account can access the path, sandboxing is compatible, or the selected startup relationship is right for the boot graph on that host.
Everyday Use & Decision Guide:
Start with the service preset closest to your workload. Node worker, Python worker, and Go binary are good first passes for foreground services. Docker Compose app keeps hardening off because container tooling often needs broader host access. One-shot maintenance job sets Type=oneshot and disables automatic restarts.
Fill Service name, Description, and ExecStart before tuning the rest. The normalized filename in the summary is the name you will install, so check it if you pasted spaces, punctuation, or an existing .service suffix. A warning about filename normalization is not a failure, but it is a sign to confirm that runbooks and commands use the final filename.
- Use
Run as userfor a dedicated service account whenever root is not required. - Set
Working directorywhen relative paths, config discovery, or app startup expects a project directory. - Choose
Restart policywith the failure mode in mind. Long-running workers usually start withon-failure; maintenance jobs usually start withno. - Keep
Hardening profileonstandardfor a first review, then trystrictonly after write paths and runtime needs are clear. - Use advanced fields for
EnvironmentFile,StateDirectory,RuntimeDirectory,ReadWritePaths, and reload or stop commands when the service really needs them.
The first stop-and-verify cue is the summary badge. Needs edit means a red validation message must be fixed before the service file is ready to copy. Review warnings means the unit text exists, but at least one operational choice deserves attention. Ready to verify means the next check belongs on the host, not in the page.
Avoid secrets in inline environment variables. Generation happens in the browser page, but copied text, downloaded outputs, screenshots, and the page URL can still expose values. Put credentials in a protected file on the target host and reference that file only when the host permission model is ready.
Step-by-Step Guide:
Build the service unit from the main command outward, then use the review surfaces before installing it.
- Choose
Service preset. Confirm the summary updates to the expected filename and badges such asType=exec,Restart=on-failure, orHardening=standard. - Enter
Service nameandDescription. CheckGenerated systemd Servicefor the normalized.servicefilename that will appear in install commands. - Fill
ExecStart,Run as user, andWorking directory. If a path warning appears inReview Notes, switch to absolute paths or confirm the target host deliberately supports that form. - Set
Service type,Restart policy,Restart delay,Startup dependency,Hardening profile, andInstall target. Watch the badges and directive count change as directives are added or removed. - Open
Advancedonly for settings the service needs: group override, environment file, reload or stop command, PID file, timeouts, managed directories, writable paths, or journal identifier. - Read the red validation panel if it appears. Fix missing
ExecStart, invalid option choices, or malformed environment entries before usingService Unit. - Open
Directive Ledgerand confirm each section, directive, value, and rationale matches the intended service behavior. - Open
Review Notes. Resolve root-user, strict-hardening, forking-PID, suspicious path, and secret-looking environment notes before handoff when they apply. - Use
Install Checklistfor the host-side commands, then verify with status and logs before treating the service as ready.
Interpreting Results:
The service file text is the artifact that would be installed, but the surrounding tables explain whether it deserves trust. Read the generated unit for exact syntax, then use the ledger and review notes to catch choices that look valid but may fail or surprise operators on the target host.
| Output cue | Meaning | What to check next |
|---|---|---|
Service Unit |
The complete generated text grouped into [Unit], [Service], and [Install]. |
Verify every command, path, user, dependency, and hardening directive before install. |
Directive Ledger |
A row-by-row explanation of each emitted directive. | Use it to catch accidental settings, missing writable paths, or directives added by a preset. |
Install Checklist |
Suggested host-side commands for writing, verifying, reloading, enabling, checking status, and following logs. | Run them on a suitable test host or maintenance window, not blindly on a production shell. |
Review Notes |
Validation errors, warnings, and lower-severity review prompts. | Treat red errors as blockers. Treat warnings as prompts for host-specific confirmation. |
JSON |
A structured record of inputs, derived rows, review notes, install steps, and generated text. | Use it for review or handoff, but keep secrets out of it. |
A green review does not mean the service is running. It means the generated draft passed the page's checks. The final confidence check is still systemd-analyze verify, systemctl status, and journalctl -fu on the host where the service will run.
Worked Examples:
Foreground Node worker
The Node worker preset produces example-worker.service with Type=exec, ExecStart=/usr/bin/node /var/www/example/current/worker.js, User=www-data, Restart=on-failure, RestartSec=5s, and standard hardening. The summary reports 14 directives for an exec service and no review notes that block copying. The useful next step is to run the install checklist on a test host and confirm the account can read the app directory.
Strict Go API service
The Go binary preset sets api-service.service, ExecStart=/usr/local/bin/api-service --config /etc/api-service/config.yaml, User=api-service, Restart=on-failure, and strict hardening. Review notes warn when strict file-system protection has no writable path allowances. If the API writes state, add StateDirectory=api-service or a suitable ReadWritePaths value before relying on ProtectSystem=strict.
Forking daemon repair
A legacy daemon with Service type set to forking and a blank PIDFile still generates a unit, but Review Notes warns that the main process may be hard to identify. Add a runtime path such as /run/example-worker.pid, then check that the daemon actually writes that file. If ExecStart is blank as well, the red validation panel reports ExecStart is required. and the service-file copy buttons stay disabled until a command is entered.
FAQ:
Does this install the service for me?
No. It generates the unit text and shows an install checklist. Writing to /etc/systemd/system, running verification, reloading the manager, enabling the service, and checking logs still happen on your Linux host.
Which service type should I choose first?
Use exec for most foreground services, notify only when the daemon sends readiness notifications, forking for legacy daemons that detach, and oneshot for commands that finish instead of staying active.
Why does a network-ready startup choice still get a note?
That dependency is useful only when the host has a wait service enabled and the application truly needs configured connectivity before startup. Many local services should use a lighter startup relationship or no network dependency.
Why are secret-looking environment values flagged?
Inline Environment= values become part of the unit text and can appear in copied output, downloads, review exports, or shell history. Use a protected EnvironmentFile on the host for passwords, tokens, and keys.
What should I do when validation fails?
Fix the red validation message first. The most common blockers are missing Service name, missing ExecStart, invalid option values, or malformed environment rows that do not use KEY=value.
Glossary:
- Unit
- A named systemd object such as a service, target, socket, timer, or mount.
- Service unit
- A unit type that starts and supervises one or more service processes.
- Target
- A grouping and synchronization point used to pull related units into startup or another operating state.
ExecStart- The command line systemd invokes as the main service process.
- Restart policy
- The rule that decides whether systemd should try to start the service again after an exit or failure.
- Hardening directive
- A service setting that restricts privileges, temporary directories, home access, kernel controls, or write access.
WantedBy- An install setting that creates a weak dependency from the listed target when the service is enabled.
References:
- systemd.unit(5), Linux man-pages project.
- systemd.service(5), Linux man-pages project.
- systemd.exec(5), Linux man-pages project.
- systemd-analyze(1), Linux man-pages project.
- Using systemd unit files to customize and optimize your system, Red Hat.