github.com/kardianos/nomad@v0.1.3-0.20151022182107-b13df73ee850/client/executor/exec_universal.go (about) 1 // +build !linux 2 3 package executor 4 5 import ( 6 "fmt" 7 "os" 8 "strconv" 9 10 "github.com/hashicorp/nomad/client/allocdir" 11 "github.com/hashicorp/nomad/nomad/structs" 12 ) 13 14 func NewExecutor() Executor { 15 return &UniversalExecutor{} 16 } 17 18 // UniversalExecutor should work everywhere, and as a result does not include 19 // any resource restrictions or runas capabilities. 20 type UniversalExecutor struct { 21 cmd 22 } 23 24 func (e *UniversalExecutor) Limit(resources *structs.Resources) error { 25 if resources == nil { 26 return errNoResources 27 } 28 return nil 29 } 30 31 func (e *UniversalExecutor) ConfigureTaskDir(taskName string, alloc *allocdir.AllocDir) error { 32 // No-op 33 return nil 34 } 35 36 func (e *UniversalExecutor) Start() error { 37 // We don't want to call ourself. We want to call Start on our embedded Cmd 38 return e.cmd.Start() 39 } 40 41 func (e *UniversalExecutor) Open(pid string) error { 42 pidNum, err := strconv.Atoi(pid) 43 if err != nil { 44 return fmt.Errorf("Failed to parse pid %v: %v", pid, err) 45 } 46 47 process, err := os.FindProcess(pidNum) 48 if err != nil { 49 return fmt.Errorf("Failed to reopen pid %d: %v", pidNum, err) 50 } 51 e.Process = process 52 return nil 53 } 54 55 func (e *UniversalExecutor) Wait() error { 56 // We don't want to call ourself. We want to call Start on our embedded Cmd 57 return e.cmd.Wait() 58 } 59 60 func (e *UniversalExecutor) ID() (string, error) { 61 if e.cmd.Process != nil { 62 return strconv.Itoa(e.cmd.Process.Pid), nil 63 } else { 64 return "", fmt.Errorf("Process has finished or was never started") 65 } 66 } 67 68 func (e *UniversalExecutor) Shutdown() error { 69 return e.ForceStop() 70 } 71 72 func (e *UniversalExecutor) ForceStop() error { 73 return e.Process.Kill() 74 } 75 76 func (e *UniversalExecutor) Command() *cmd { 77 return &e.cmd 78 }