From 09c8ee621b258432c01b51a8ec8c1d02dd9726eb Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Thu, 20 Jul 2017 12:02:04 -0700 Subject: [PATCH] Destroy tasks that are part of terminal alloc --- client/alloc_runner.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client/alloc_runner.go b/client/alloc_runner.go index 19657342d..4d58e1a1a 100644 --- a/client/alloc_runner.go +++ b/client/alloc_runner.go @@ -283,6 +283,7 @@ func (r *AllocRunner) RestoreState() error { } // Restore the task runners + taskDestroyEvent := structs.NewTaskEvent(structs.TaskKilled) var mErr multierror.Error for _, task := range tg.Tasks { name := task.Name @@ -300,14 +301,14 @@ func (r *AllocRunner) RestoreState() error { td = r.allocDir.NewTaskDir(name) } - tr := NewTaskRunner(r.logger, r.config, r.stateDB, r.setTaskState, td, r.Alloc(), task, r.vaultClient, r.consulClient) - r.tasks[name] = tr - // Skip tasks in terminal states. if state.State == structs.TaskStateDead { continue } + tr := NewTaskRunner(r.logger, r.config, r.stateDB, r.setTaskState, td, r.Alloc(), task, r.vaultClient, r.consulClient) + r.tasks[name] = tr + if restartReason, err := tr.RestoreState(); err != nil { r.logger.Printf("[ERR] client: failed to restore state for alloc %s task %q: %v", r.allocID, name, err) mErr.Errors = append(mErr.Errors, err) @@ -326,6 +327,8 @@ func (r *AllocRunner) RestoreState() error { r.logger.Printf("[INFO] client: restarting alloc %s task %s: %v", r.allocID, name, restartReason) tr.Restart("upgrade", restartReason) } + } else { + tr.Destroy(taskDestroyEvent) } }