github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/uniter/runner/debug/common.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package debug
     5  
     6  import (
     7  	"fmt"
     8  	"path/filepath"
     9  
    10  	"gopkg.in/juju/names.v2"
    11  )
    12  
    13  const defaultFlockDir = "/tmp"
    14  
    15  type HooksContext struct {
    16  	Unit     string
    17  	FlockDir string
    18  }
    19  
    20  func NewHooksContext(unitName string) *HooksContext {
    21  	return &HooksContext{Unit: unitName, FlockDir: defaultFlockDir}
    22  }
    23  
    24  func (c *HooksContext) ClientFileLock() string {
    25  	basename := fmt.Sprintf("juju-%s-debug-hooks", names.NewUnitTag(c.Unit))
    26  	return filepath.Join(c.FlockDir, basename)
    27  }
    28  
    29  func (c *HooksContext) ClientExitFileLock() string {
    30  	return c.ClientFileLock() + "-exit"
    31  }
    32  
    33  func (c *HooksContext) tmuxSessionName() string {
    34  	return c.Unit
    35  }