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 considers any non-zero exit status a failure by default, so ExecStop commands are skipped after a failed start. The SuccessExitStatus directive overrides this behavior by listing exit codes that should be regarded as clean exits. Adding SuccessExitStatus=2 makes code 2 a normal exit, allowing the service to stop cleanly and execute ExecStop. Restart=on-failure would restart the unit rather than adjust success criteria. Changing the Type does not affect acceptable exit codes. ValidExitCodes is not a valid directive.
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 does the SuccessExitStatus directive do in systemd?
Open an interactive chat with Bash
What is the purpose of the ExecStop directive in systemd unit files?
Open an interactive chat with Bash
Why is the Restart=on-failure setting not suitable in this scenario?