client: allocate alloc dir and cleanup

This commit is contained in:
Armon Dadgar
2015-08-30 17:35:58 -07:00
parent 0d101001cb
commit ee520f29b0
2 changed files with 18 additions and 1 deletions

View File

@@ -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)
}

View File

@@ -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