condition-file-exists and condition-file-missing gate a service on the
state of a file: the first runs the process only if the path exists, the
second only if it doesn't. Setting both means both must hold. The classic use
is a preparation oneshot that must run only when its work is not done yet —
no sh -c 'if [ ! -e ... ]' wrapper needed.
condition-file-exists: /etc/app/enable # run only if present
condition-file-missing: /etc/app/done # run only if absentRules and semantics:
- Paths must be absolute; a relative path is rejected at load.
- The condition is re-evaluated at every start attempt: initial startup,
on-failure/on-successrestarts, each scheduled cron tick, and manualstartvia the control socket. A restart loop therefore stops on its own once the watched file state changes. - An unmet condition skips the start: it is logged with the reason, shown
by
status <name>asskipped (...), and counts as success — services withafter:/requires:on it start normally, and noon-success/on-failureaction fires (nothing ran). - Symlinks are followed (
os.Stat), so a k8s configmap/secret key resolved through..data/gives the right answer; a dangling symlink counts as missing. Astaterror other than not-exist (e.g. permission denied) leaves the condition unmet with the error in the skip reason, so it never silently masquerades as a missing file. - The check is advisory, not a lock: the file state can change between the probe and the exec.
processes:
- name: aux-cfg
condition-file-missing: /etc/haproxy/haproxy-aux.cfg
command: /bin/sh
args:
- -c
- |
touch /etc/haproxy/haproxy-aux.cfg
chmod g+w /etc/haproxy/haproxy-aux.cfg
startup: oneshot
- name: app
command: /usr/sbin/haproxy
requires: [aux-cfg]- First boot: the file is missing,
aux-cfgruns and creates it,appstarts after it completes. - Later boots: the file exists,
aux-cfgis skipped (aux-cfg skipped (condition-file-missing: ... exists)), andappstill starts — skip satisfiesrequires:. status aux-cfgreportsskipped (condition-file-missing: ... exists); a manualstart aux-cfgreports the same instead of running it.
Run level. Boots the daemon twice against the same directory and asserts the run/skip split above. SIGTERM yields a clean exit 0.
go test ./documentation/service-conditions/ -v