spawn

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2015 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logs

type Logs struct {
	Stdin, Stdout, Stderr string
}

Logs is used to define the filepaths the user command's logs should be redirected to. The files do not need to exist.

type Spawner

type Spawner struct {
	SpawnPid  int
	SpawnPpid int
	StateFile string
	UserPid   int

	// User configuration
	UserCmd *exec.Cmd
	Logs    *Logs
	Chroot  string
	// contains filtered or unexported fields
}

Spawner is used to start a user command in an isolated fashion that is resistent to Nomad agent failure.

func NewSpawner

func NewSpawner(stateFile string) *Spawner

NewSpawner takes a path to a state file. This state file can be used to create a new Spawner that can be used to wait on the exit status of a process even through Nomad restarts.

func (*Spawner) Alive

func (s *Spawner) Alive() bool

func (*Spawner) SetChroot

func (s *Spawner) SetChroot(root string)

SetChroot puts the user command into a chroot.

func (*Spawner) SetCommand

func (s *Spawner) SetCommand(cmd *exec.Cmd)

SetCommand sets the user command to spawn.

func (*Spawner) SetLogs

func (s *Spawner) SetLogs(l *Logs)

SetLogs sets the redirection of user command log files.

func (*Spawner) Spawn

func (s *Spawner) Spawn(cb func(pid int) error) error

Spawn does a double-fork to start and isolate the user command. It takes a call-back that is invoked with the pid of the intermediary process. If the call back returns an error, the user command is not started and the spawn is cancelled. This can be used to put the process into a cgroup or jail and cancel starting the user process if that was not successful. An error is returned if the call-back returns an error or the user-command couldn't be started.

func (*Spawner) Valid

func (s *Spawner) Valid() error

Valid checks that the state of the Spawner is valid and that a subsequent Wait could be called. This is useful to call when reopening a Spawner through client restarts. If Valid a nil error is returned.

func (*Spawner) Wait

func (s *Spawner) Wait() *structs.WaitResult

Wait returns the exit code of the user process or an error if the wait failed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL