diff --git a/client/allocrunner/taskrunner/restarts/restarts.go b/client/allocrunner/taskrunner/restarts/restarts.go index 2449a90e3..7ea7f81a1 100644 --- a/client/allocrunner/taskrunner/restarts/restarts.go +++ b/client/allocrunner/taskrunner/restarts/restarts.go @@ -21,7 +21,7 @@ const ( ) func NewRestartTracker(policy *structs.RestartPolicy, jobType string, tlc *structs.TaskLifecycleConfig) *RestartTracker { - onSuccess := jobType == structs.JobTypeService + onSuccess := jobType != structs.JobTypeBatch if tlc != nil && tlc.Hook == structs.TaskLifecycleHookPrestart { onSuccess = tlc.BlockUntil != structs.TaskLifecycleBlockUntilCompleted } diff --git a/client/allocrunner/taskrunner/restarts/restarts_test.go b/client/allocrunner/taskrunner/restarts/restarts_test.go index fe877e418..b2fd58745 100644 --- a/client/allocrunner/taskrunner/restarts/restarts_test.go +++ b/client/allocrunner/taskrunner/restarts/restarts_test.go @@ -210,6 +210,13 @@ func TestClient_RestartTracker_Lifecycle(t *testing.T) { shouldRestartOnSuccess bool shouldRestartOnFailure bool }{ + { + name: "system job no lifecycle", + taskLifecycleConfig: nil, + jobType: structs.JobTypeSystem, + shouldRestartOnSuccess: true, + shouldRestartOnFailure: true, + }, { name: "service job no lifecycle", taskLifecycleConfig: nil, @@ -224,6 +231,26 @@ func TestClient_RestartTracker_Lifecycle(t *testing.T) { shouldRestartOnSuccess: false, shouldRestartOnFailure: true, }, + { + name: "system job w/ lifecycle completed", + taskLifecycleConfig: &structs.TaskLifecycleConfig{ + Hook: structs.TaskLifecycleHookPrestart, + BlockUntil: structs.TaskLifecycleBlockUntilCompleted, + }, + jobType: structs.JobTypeSystem, + shouldRestartOnSuccess: false, + shouldRestartOnFailure: true, + }, + { + name: "system job w/ lifecycle running", + taskLifecycleConfig: &structs.TaskLifecycleConfig{ + Hook: structs.TaskLifecycleHookPrestart, + BlockUntil: structs.TaskLifecycleBlockUntilRunning, + }, + jobType: structs.JobTypeSystem, + shouldRestartOnSuccess: true, + shouldRestartOnFailure: true, + }, { name: "service job w/ lifecycle completed", taskLifecycleConfig: &structs.TaskLifecycleConfig{