Merge pull request #31149 from YHNdnzj/restart-force-oneshot
core/service: allow RestartForceExitStatus= for oneshot service
This commit is contained in:
+9
-5
@@ -662,13 +662,9 @@ static int service_verify(Service *s) {
|
||||
if (s->type != SERVICE_ONESHOT && s->exec_command[SERVICE_EXEC_START]->command_next)
|
||||
return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.");
|
||||
|
||||
if (s->type == SERVICE_ONESHOT &&
|
||||
!IN_SET(s->restart, SERVICE_RESTART_NO, SERVICE_RESTART_ON_FAILURE, SERVICE_RESTART_ON_ABNORMAL, SERVICE_RESTART_ON_WATCHDOG, SERVICE_RESTART_ON_ABORT))
|
||||
if (s->type == SERVICE_ONESHOT && IN_SET(s->restart, SERVICE_RESTART_ALWAYS, SERVICE_RESTART_ON_SUCCESS))
|
||||
return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has Restart= set to either always or on-success, which isn't allowed for Type=oneshot services. Refusing.");
|
||||
|
||||
if (s->type == SERVICE_ONESHOT && !exit_status_set_is_empty(&s->restart_force_status))
|
||||
return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has RestartForceExitStatus= set, which isn't allowed for Type=oneshot services. Refusing.");
|
||||
|
||||
if (s->type == SERVICE_ONESHOT && s->exit_type == SERVICE_EXIT_CGROUP)
|
||||
return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(ENOEXEC), "Service has ExitType=cgroup set, which isn't allowed for Type=oneshot services. Refusing.");
|
||||
|
||||
@@ -1901,6 +1897,7 @@ static int cgroup_good(Service *s) {
|
||||
|
||||
static bool service_shall_restart(Service *s, const char **reason) {
|
||||
assert(s);
|
||||
assert(reason);
|
||||
|
||||
/* Don't restart after manual stops */
|
||||
if (s->forbid_restart) {
|
||||
@@ -1916,6 +1913,13 @@ static bool service_shall_restart(Service *s, const char **reason) {
|
||||
|
||||
/* Restart if the exit code/status are configured as restart triggers */
|
||||
if (exit_status_set_test(&s->restart_force_status, s->main_exec_status.code, s->main_exec_status.status)) {
|
||||
/* Don't allow Type=oneshot services to restart on success. Note that Restart=always/on-success
|
||||
* is already rejected in service_verify. */
|
||||
if (s->type == SERVICE_ONESHOT && s->result == SERVICE_SUCCESS) {
|
||||
*reason = "service type and exit status";
|
||||
return false;
|
||||
}
|
||||
|
||||
*reason = "forced by exit status";
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user