Context
A program works when started from a terminal but cannot find its configuration when systemd starts it. The terminal and the service are different execution environments. An environment variable is a named value passed to a process; the service manager does not reconstruct an administrator's interactive shell session.
This guide addresses configuration delivery rather than application startup logic. Before investigating, identify the exact unit, installed systemd version, application owner and intended non-secret settings. Have permission to inspect unit configuration, and use a staging service if changing a setting would interrupt production.
Inspect the configuration path
- Run
systemctl cat example.serviceto read the unit and its drop-ins. Replace the example name with the actual service. Look forEnvironment=,EnvironmentFile=,User=andWorkingDirectory=. A setting in an unexpected drop-in may explain why editing the main unit had no effect. Unit files can contain sensitive arguments, so review output locally before sharing it. - Inspect the named environment file without publishing its contents. Compare its syntax with the installed
systemd.execmanual. Values such asDATA_DIR=$BASE/datado not behave like a shell script sourced after another assignment. Quoting also follows systemd's rules. Prefer an explicit absolute directory when the application requires one, or let an application-owned configuration loader construct it. - Check what configuration the application actually reports through a redacted diagnostic or startup message.
systemctl show example.service -p Environment -p EnvironmentFilesdescribes configured properties, but it does not prove every runtime value after application code has modified its environment. Do not dump/proc/PID/environinto a ticket containing credentials.
An illustrative configuration failure
Consider an illustrative document processor with BASE=/srv/documents and OUTPUT=$BASE/output in its environment file. The developer expects /srv/documents/output; the service passes a literal dollar expression that the application treats as a relative filename. Fixing directory ownership would change the wrong boundary. The relevant question is which component is responsible for expanding the value.
| Observation | Diagnostic check | Likely boundary |
|---|---|---|
| Works only in a login terminal | Compare explicit service settings with shell initialization | Missing declared configuration |
| Dollar expression appears literally | Review environment-file parsing | Expansion expectation |
| Old value survives a deployment | Inspect drop-in order and running process age | Configuration activation |
| Correct value, wrong destination | Review application interpretation and working directory | Application path handling |
Correct and verify deliberately
Keep environment files for ordinary configuration. The systemd manual recommends credential facilities for secrets because environment values can spread to child processes and management interfaces. Do not solve a missing password by placing it in a broadly readable drop-in.
Record the old file, change one demonstrated setting, and validate the unit using the distribution's supported checks. Reload the service manager when unit definitions change; restart or reload the application only according to its documented configuration behavior. Editing an environment file alone does not alter a process that is already running.
Verify through a new controlled application operation, not merely an active service status. Confirm the resolved directory, effective non-secret value and expected output. Test a normal deployment too, because a one-off manual edit can disappear at the next release.
Maintain a configuration contract
Assign ownership of every environment file and document whether changes need a process restart. Add a redacted startup diagnostic for essential paths and feature flags. Review deployment templates whenever application settings change, and retain the correction with its rollback condition in the operating procedure. Clouvenix Linux administration can help align unit files and application configuration with a repeatable release process.
Technical reference
systemd execution environment documentation. Check the manual shipped with the server for version-specific parsing details.