github.com/jmitchell/nomad@v0.1.3-0.20151007230021-7ab84c2862d8/command/spawn_daemon.go (about) 1 package command 2 3 import ( 4 "encoding/json" 5 "os" 6 "strings" 7 ) 8 9 type SpawnDaemonCommand struct { 10 Meta 11 } 12 13 // Status of executing the user's command. 14 type SpawnStartStatus struct { 15 // ErrorMsg will be empty if the user command was started successfully. 16 // Otherwise it will have an error message. 17 ErrorMsg string 18 } 19 20 func (c *SpawnDaemonCommand) Help() string { 21 helpText := ` 22 Usage: nomad spawn-daemon [options] <daemon_config> 23 24 INTERNAL ONLY 25 26 Spawns a daemon process optionally inside a cgroup. The required daemon_config is a json 27 encoding of the DaemonConfig struct containing the isolation configuration and command to run. 28 SpawnStartStatus is json serialized to Stdout upon running the user command or if any error 29 prevents its execution. If there is no error, the process waits on the users 30 command and then json serializes SpawnExitStatus to Stdout after its termination. 31 32 General Options: 33 34 ` + generalOptionsUsage() 35 36 return strings.TrimSpace(helpText) 37 } 38 39 func (c *SpawnDaemonCommand) Synopsis() string { 40 return "Spawn a daemon command with configurable isolation." 41 } 42 43 // outputStartStatus is a helper function that outputs a SpawnStartStatus to 44 // Stdout with the passed error, which may be nil to indicate no error. It 45 // returns the passed status. 46 func (c *SpawnDaemonCommand) outputStartStatus(err error, status int) int { 47 startStatus := &SpawnStartStatus{} 48 enc := json.NewEncoder(os.Stdout) 49 50 if err != nil { 51 startStatus.ErrorMsg = err.Error() 52 } 53 54 enc.Encode(startStatus) 55 return status 56 }