From ee520f29b012494ad367e3ad92bb72db65e11be1 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Sun, 30 Aug 2015 17:35:58 -0700 Subject: [PATCH] client: allocate alloc dir and cleanup --- client/alloc_runner.go | 15 ++++++++++++++- client/driver/driver.go | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/client/alloc_runner.go b/client/alloc_runner.go index bc1c7240c..336479ce1 100644 --- a/client/alloc_runner.go +++ b/client/alloc_runner.go @@ -144,6 +144,11 @@ func (r *AllocRunner) DestroyState() error { return os.RemoveAll(filepath.Dir(r.stateFilePath())) } +// DestroyContext is used to destroy the context +func (r *AllocRunner) DestroyContext() error { + return os.RemoveAll(r.ctx.AllocDir) +} + // Alloc returns the associated allocation func (r *AllocRunner) Alloc() *structs.Allocation { return r.alloc @@ -273,6 +278,7 @@ func (r *AllocRunner) Run() { // Create the execution context if r.ctx == nil { r.ctx = driver.NewExecContext() + r.ctx.AllocDir = filepath.Join(r.config.AllocDir, r.alloc.ID) } // Start the task runners @@ -329,7 +335,14 @@ OUTER: // Check if we should destroy our state if r.destroy { - r.DestroyState() + if err := r.DestroyContext(); err != nil { + r.logger.Printf("[ERR] client: failed to destroy context for alloc '%s': %v", + r.alloc.ID, err) + } + if err := r.DestroyState(); err != nil { + r.logger.Printf("[ERR] client: failed to destroy state for alloc '%s': %v", + r.alloc.ID, err) + } } r.logger.Printf("[DEBUG] client: terminating runner for alloc '%s'", r.alloc.ID) } diff --git a/client/driver/driver.go b/client/driver/driver.go index 262c3a71a..3fdd3f606 100644 --- a/client/driver/driver.go +++ b/client/driver/driver.go @@ -65,6 +65,10 @@ type DriverHandle interface { // ExecContext is shared between drivers within an allocation type ExecContext struct { sync.Mutex + + // AllocDir is the directory used for storing any state + // of this allocation. It will be purged on alloc destroy. + AllocDir string } // NewExecContext is used to create a new execution context