A custom service runs a preparation script in ExecStart and a cleanup script in ExecStop. The preparation script exits with status code 2, so systemd marks the service as failed and skips cleanup on stop. Which setting added to the unit file will treat exit code 2 as normal and permit the cleanup script to run?
Systemd treats any exit code other than zero as failure by default, preventing ExecStop tasks from executing. The SuccessExitStatus directive overrides this by listing exit codes that indicate successful completion. Specifying ‘2’ lets systemd consider the startup step successful, so the service can be stopped cleanly and invoke ExecStop. Using Restart=on-failure would retry the service rather than adjust success criteria. Changing the Type does not redefine which exit codes are acceptable. ValidExitCodes is not a valid option.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the SuccessExitStatus directive in systemd?
Open an interactive chat with Bash
How does the ExecStart and ExecStop work within a systemd service unit?
Open an interactive chat with Bash
What happens if I set Restart=on-failure in a systemd service unit?