mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
client: allocate alloc dir and cleanup
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user