Introduction
A long-running service on systemd needs three things to behave correctly: the right Type=, a restart policy that does not hammer the service in a boot loop, and log output that lands in the journal with enough context to debug a crash at 03:00. Most broken unit files fail on one of those three, and the way they fail tells you which one. An status=203/EXEC in systemctl status means the exec path is wrong. A start request repeated too quickly message means the restart limits fired. Empty journalctl -u foo.service output means the service never attached to the journal, or the log is going somewhere you are not looking. This article builds a working unit file for a long-running daemon, walks through the restart policy knobs that matter, wires the logging correctly, and finishes with the troubleshooting steps for the errors you will actually see.
The shape of a unit file
A service unit commonly has three sections. [Unit] holds metadata and dependencies, [Service] configures the process, and [Install] controls enablement links. Directives belong in the section specified by their manual page. Unknown options generally produce a warning, but a misplaced directive may not have the effect you expect. Use systemd-analyze verify and the installed manuals to validate the unit.
A minimal unit for a daemon like a Python HTTP service or a Go binary looks like this:
[Unit]Description=Inventory sync workerAfter=network-online.targetWants=network-online.target
[Service]Type=simpleExecStart=/opt/inventory/bin/sync-worker --config /etc/inventory/worker.tomlRestart=on-failureRestartSec=5sUser=inventoryGroup=inventoryWorkingDirectory=/opt/inventoryStandardOutput=journalStandardError=journal
[Install]WantedBy=multi-user.targetUse an absolute executable path in ExecStart= and provide arguments as separate words. systemd does not invoke a shell, so shell operators such as &&, pipes, redirections, and shell variable expansion are not interpreted. Prefer a small dedicated script when shell logic is required, and configure it as the executable with an appropriate shebang and permissions. Avoid bash -lc as a general workaround because it introduces shell startup behavior and quoting complexity.
After= controls ordering; Wants= and Requires= pull another unit into the transaction with different failure semantics. After=network-online.target does not guarantee end-to-end connectivity. Wants=network-online.target requests that target, but the distribution’s matching wait-online service must be enabled for the target to delay startup. Even then, a remote database or API can become unavailable later. Network clients should handle retries and reconnection rather than treating this dependency as a connectivity guarantee.
Choosing the correct Type
The Type= directive tells systemd what to expect from the process. Getting it wrong causes a service to be reported as active while it is still starting, or as dead while it is still running.
Type=simple is the default for most services that specify ExecStart=. systemd considers the unit started after it forks the service process, before it has necessarily completed execve() or finished initialization. This is appropriate when the program stays in the foreground and does not provide a readiness notification. If dependent units must wait until the service is actually ready, use Type=notify only when the daemon supports sd_notify(); otherwise, use a socket or another documented readiness mechanism.
Type=notify is for a daemon that sends READY=1 through sd_notify() when startup is complete. systemd waits for that notification before proceeding with dependent jobs. TimeoutStartSec= bounds the start operation; its effective value depends on manager configuration and unit settings, so inspect the target system rather than assuming a universal default. If the daemon does not implement the notification protocol, this type will not report readiness correctly.
Type=forking is for software whose ExecStart= process forks during startup and exits after initialization while a child continues. If systemd cannot reliably identify the main process, configure a correct PIDFile=; the daemon should create and update it as documented by its vendor. For new services, prefer a foreground process with Type=exec, Type=simple, or Type=notify, depending on whether successful execve() or application readiness must gate dependent units.
Type=oneshot waits for the configured command to exit, then considers its start action complete. It suits tasks such as migrations or setup scripts, not a daemon that must remain running. With RemainAfterExit=yes, the unit remains active after the command exits, which can be useful for one-time setup actions. Restart behavior has restrictions for oneshot services; check the Restart= documentation before configuring it.
Restart policies that behave under failure
Restart=no is the default. For a daemon that should recover from unexpected failures, Restart=on-failure is a common choice. It covers non-zero exits, abnormal signals, timeouts, watchdog failures, and resource-limit failures, subject to the service type and other settings. It does not restart after a clean exit, or when an operator stops the unit. Check the systemd manual for exceptions and the exact behavior on your installed version.
Restart=on-abnormal covers abnormal termination such as signals and timeouts, but not an ordinary non-zero exit. Restart=always also restarts after clean exits, except for an explicit stop request. Restart=on-watchdog restricts restarts to watchdog failures. WatchdogSec= requires the service to implement the systemd watchdog notification protocol; Type=notify is generally used when the daemon also reports readiness.
RestartSec= sets the delay before a restart. Its default is 100 ms, which can produce rapid retries. Choose a delay that fits the service and its dependencies, then configure the start-rate limit so persistent failures do not trigger unlimited restarts. For example:
[Unit]Description=Inventory sync workerAfter=network-online.targetWants=network-online.targetStartLimitIntervalSec=60sStartLimitBurst=3This limits starts to three within the configured interval. When the limit is reached, the unit can enter a failed state until it is reset or otherwise retriggered. Directive names and compatibility may vary across systemd releases; validate the file with systemd-analyze verify on the target system and consult its installed manual pages.
After a start limit is reached, inspect the service logs and fix the cause before resetting it. systemctl reset-failed inventory-worker.service clears the failed state and resets the rate-limit counter; it does not repair the underlying service.
When a start is rejected by rate limiting, inspect systemctl status and the unit journal to find the original failure before clearing the failed state. After correcting the cause, use systemctl reset-failed inventory-worker.service if needed, then start the unit and verify it reaches the expected state. Do not have deployment tooling reset failure state blindly; that can conceal a broken configuration and trigger repeated attempts.
Logging into the journal correctly
systemd captures whatever the process writes to stdout and stderr and forwards it to the journal by default. The StandardOutput= and StandardError= directives are often unnecessary because journal is the default. They become relevant when you want to route logs to syslog, to a file via StandardOutput=append:/var/log/foo.log, or to null. For most services, leaving the default and adding SyslogIdentifier= is the cleanest setup:
[Service]SyslogIdentifier=inventory-workerEnvironment=NODE_ENV=productionEnvironmentFile=-/etc/inventory/worker.envSyslogIdentifier= sets the SYSLOG_IDENTIFIER field on each journal entry so journalctl -t inventory-worker finds the logs even when the process name does not match the unit name. It is useful when the unit’s ExecStart= points to a wrapper script or an interpreter like python or node, because then the journal would otherwise tag entries with the interpreter’s name.
Environment= and EnvironmentFile= pass configuration to the process. A leading - in EnvironmentFile=-/etc/inventory/worker.env makes a missing file non-fatal; without it, failure to read the file can prevent startup. The file uses systemd’s environment-file syntax, not a shell script: do not add export or expect shell variable expansion, command substitution, or shell execution. Follow the installed systemd.exec manual for quoting and escaping rules.
Query the journal with commands that match the question:
journalctl -u inventory-worker.service -b --since "30 minutes ago"journalctl -u inventory-worker.service -p errjournalctl -u inventory-worker.service -fjournalctl -u inventory-worker.service -o json-pretty-p err filters by priority, -f follows new entries, and -o json-pretty displays structured journal fields such as _PID, _UID, SYSLOG_IDENTIFIER, and _SYSTEMD_UNIT. Journal retention and storage location depend on journald configuration and whether persistent storage is enabled. If disk usage needs a cap, review the installed journald.conf manual, set an appropriate SystemMaxUse= policy, and restart systemd-journald according to the distribution’s guidance. Do not assume a particular default or that the journal grows without bounds.
For most services, leave stdout and stderr directed to the journal. Use StandardOutput=syslog only when the service specifically needs syslog-style handling; verify the destination and forwarding behavior on the target system. A missing journalctl entry can also mean the application writes to a file, redirects its own output, or logs through another mechanism, so check the service configuration and its actual output path.
Example sandboxing directives
systemd’s sandboxing directives can reduce a service’s access to the host, but they must match the application and installed systemd version. Test them under a representative workload before production. This example assumes the daemon stays in the foreground, implements sd_notify() readiness/watchdog messages and SIGHUP reload, uses TCP/Unix sockets, and writes only to /var/cache/inventory. Ensure that directory exists and is writable by inventory, or adjust the service account and path. Remove any directive that does not match the application:
[Unit]Description=Inventory sync workerDocumentation=https://internal.example/inventory/workerAfter=network-online.targetWants=network-online.targetStartLimitIntervalSec=60StartLimitBurst=3
[Service]Type=notifyNotifyAccess=mainExecStart=/opt/inventory/bin/sync-worker --config /etc/inventory/worker.tomlExecReload=/bin/kill -HUP $MAINPIDRestart=on-failureRestartSec=5sTimeoutStopSec=30KillSignal=SIGTERMUser=inventoryGroup=inventoryWorkingDirectory=/opt/inventoryEnvironmentFile=-/etc/inventory/worker.envSyslogIdentifier=inventory-workerStandardOutput=journalStandardError=journalWatchdogSec=60NoNewPrivileges=yesProtectSystem=strictProtectHome=yesPrivateTmp=yesReadWritePaths=/var/cache/inventoryProtectKernelTunables=yesProtectKernelModules=yesProtectControlGroups=yesRestrictAddressFamilies=AF_INET AF_INET6 AF_UNIXLockPersonality=yes
[Install]WantedBy=multi-user.targetProtectSystem=strict makes most of the filesystem read-only inside the service’s mount namespace, subject to systemd’s documented exceptions and other sandbox settings. ReadWritePaths= can grant write access to specific paths, but it does not create them or fix Unix ownership and permissions. Provision /var/cache/inventory and verify that the configured service account can write there. PrivateTmp=yes gives the service a private temporary directory; files there are not shared with other services that also use PrivateTmp=.
WatchdogSec=60 enables watchdog monitoring when the service sends the required WATCHDOG=1 notifications at the expected interval. If the watchdog expires, systemd records a watchdog failure and applies the configured failure/restart policy. The service must implement the protocol; do not enable this setting as a substitute for health checks the process cannot report.
NotifyAccess=main restricts notifications to the main process. Use the setting required by the daemon’s notification design; widening it changes which processes may report readiness or watchdog status. Consult the systemd manual before changing it, especially for forking services.
RestrictAddressFamilies= limits address families available to the service; confirm the application only needs the listed families. Sandbox controls are not free of compatibility costs. Test every directive against the actual service and provide the filesystem permissions it needs.
Loading, enabling, and iterating
After creating /etc/systemd/system/inventory-worker.service, systemd needs to be told the file changed. systemctl daemon-reload re-reads unit files. Without it, systemctl start uses the cached version, and you will spend an hour debugging a config that is not the one systemd is running.
sudo systemctl daemon-reloadsudo systemctl enable --now inventory-worker.servicesystemctl status inventory-worker.servicesystemd-analyze verify /etc/systemd/system/inventory-worker.servicesystemd-analyze verify parses unit files and can report some unknown directives, missing executables, and dependency problems. Results depend on the tool version and the environment available to it; a clean result does not prove that the service will work at runtime. Use it alongside systemctl cat, service logs, and a controlled start test.
For edits on a live system, systemctl edit inventory-worker.service creates or edits a drop-in under the unit’s .d/ directory. Drop-ins let you override selected settings without replacing a vendor unit. Inspect the merged configuration with systemctl cat inventory-worker.service.
Troubleshooting service startup
When startup fails, inspect the actual unit, its status, and recent logs:
systemctl status inventory-worker.servicejournalctl -u inventory-worker.service -b --no-pagersystemctl cat inventory-worker.servicesystemd-analyze verify /etc/systemd/system/inventory-worker.serviceAn execution failure such as 203/EXEC commonly points to an invalid executable path, permissions, interpreter, or execution environment. Check the ExecStart= target and script shebang on the host. systemd-analyze verify can help but does not replace checking the real file and runtime user.
A non-zero exit status means the process failed; use the journal and the application’s own diagnostics to identify why. A message that the unit was started too frequently indicates start-rate limiting. Find and fix the repeated failure before using systemctl reset-failed inventory-worker.service; raising the start burst may hide the cause.
If systemd cannot find a unit, check the unit name, manager context, and search paths. User units are managed with systemctl --user; system units use the system manager. Put administrator-managed units in /etc/systemd/system/, and avoid editing vendor-managed files in /usr/lib/systemd/system/ directly. Verify paths on the target distribution.
If the service runs but logs are missing, check whether the application writes to stdout/stderr, redirects output, or uses its own logging destination. Confirm the effective StandardOutput=, StandardError=, and SyslogIdentifier= values with systemctl cat and inspect the configured destination. Do not widen NotifyAccess= as a logging diagnostic; it controls access to systemd notifications, not ordinary log output.
What this buys you
A unit with a suitable process type, a bounded restart policy, and a known logging path gives operators a consistent way to supervise and inspect a daemon. Hardening settings can reduce the process’s access, but only when tested against the application’s actual file and network needs.
After editing a unit, run systemd-analyze verify where available, reload systemd with systemctl daemon-reload, and inspect the effective unit. If the unit is already in a failed state, inspect the reason and reset it only after correcting the cause. Start or restart it under a controlled change window, then check status and logs; a successful parse alone does not confirm runtime behavior.