A system administrator needs to ensure that a specific process continues to run even if it crashes. The process is started by a systemd service unit. Which approach ensures the process is automatically restarted by systemd, with a delay of 30 seconds after each crash, and does not count restarts towards the failure limit?
Trap 1: Restart=on-failure and RestartSec=30
Restart=on-failure triggers a service restart only when the process exits with a non-zero status or is terminated by a signal such as SIGKILL, but it intentionally ignores clean exit codes (0) and signals like SIGTERM that indicate a normal shutdown. Since the requirement is to restart the service after every crash, including those that might be recorded as a clean exit, and because this directive does not disable systemd's default start rate limiting (StartLimitIntervalSec=10, StartLimitBurst=5), systemd will still cease restart attempts after 5 rapid starts. Consequently, the service is left dead after repeated failures, violating the indefinite restart requirement.
Trap 2: Restart=always and RestartSec=30
Restart=always does force a restart after any exit, whether clean or unclean, and RestartSec=30 inserts a 30-second pause between attempts. However, this configuration omits any override of systemd's start rate limit, so the default StartLimitIntervalSec=10 and StartLimitBurst=5 apply: if the service crashes and is restarted more than 5 times within 10 seconds, systemd marks the unit as failed and stops trying. Even though Restart=always would otherwise restart forever, the built-in rate limiter silently overrides that behavior, meaning the service will eventually stop restarting and enter a failed state.
- A
Restart=always, RestartSec=30, StartLimitIntervalSec=0, StartLimitBurst=0
Restart=always ensures the unit is restarted regardless of how it exits, RestartSec=30 adds a 30-second delay before each retry, and setting both StartLimitIntervalSec=0 and StartLimitBurst=0 completely disables systemd's start rate limiting. The combination of interval=0 and burst=0 is the documented way to remove any limit on how many times a unit may be started within a given period, so the service will restart indefinitely after every crash. This precisely satisfies the administrator's requirement of restarting the service every single time it crashes, with no counting toward a failure limit and no eventual give-up by systemd.
- B
Restart=on-failure and RestartSec=30
Why wrong: Restart=on-failure triggers a service restart only when the process exits with a non-zero status or is terminated by a signal such as SIGKILL, but it intentionally ignores clean exit codes (0) and signals like SIGTERM that indicate a normal shutdown. Since the requirement is to restart the service after every crash, including those that might be recorded as a clean exit, and because this directive does not disable systemd's default start rate limiting (StartLimitIntervalSec=10, StartLimitBurst=5), systemd will still cease restart attempts after 5 rapid starts. Consequently, the service is left dead after repeated failures, violating the indefinite restart requirement.
- C
Restart=always, RestartSec=30, StartLimitIntervalSec=0
Setting StartLimitIntervalSec=0 alone does not fully disable start rate limiting; systemd will still consider StartLimitBurst if it is not explicitly set to 0. Therefore, to prevent restarts from counting towards the failure limit, both must be set to 0.
- D
Restart=always and RestartSec=30
Why wrong: Restart=always does force a restart after any exit, whether clean or unclean, and RestartSec=30 inserts a 30-second pause between attempts. However, this configuration omits any override of systemd's start rate limit, so the default StartLimitIntervalSec=10 and StartLimitBurst=5 apply: if the service crashes and is restarted more than 5 times within 10 seconds, systemd marks the unit as failed and stops trying. Even though Restart=always would otherwise restart forever, the built-in rate limiter silently overrides that behavior, meaning the service will eventually stop restarting and enter a failed state.