Documentation
¶
Overview ¶
Package shelltask runs shell commands in process groups of their own and keeps their output in a size-capped file.
Index ¶
- Constants
- func Excerpt(path string, limit int) (string, bool, error)
- func KillGroup(pgid int) error
- func KillLeftover(leader Leader) error
- func LoginEnvironment(environ []string, timeout time.Duration) ([]string, error)
- func Tail(path string, limit int) (string, error)
- type Chunk
- type Leader
- type Output
- type Process
- func (p *Process) Done() <-chan struct{}
- func (p *Process) ExitCode() int
- func (p *Process) Exited() <-chan struct{}
- func (p *Process) KillLeftovers() bool
- func (p *Process) Leader() Leader
- func (p *Process) Output() *Output
- func (p *Process) PID() int
- func (p *Process) StartedAt() time.Time
- func (p *Process) Stop(grace time.Duration) error
- func (p *Process) WaitOutput(delay time.Duration)
- type Ran
Constants ¶
const ( MaxBytes = 20 << 20 HeadBytes = 1 << 20 )
An output file holds at most MaxBytes: once full it keeps the first HeadBytes, a marker naming how much was dropped, and the newest output after it.
Variables ¶
This section is empty.
Functions ¶
func Excerpt ¶ added in v0.2.1
Excerpt returns the output at path whole when it fits in limit bytes, and otherwise its head, a line naming how many bytes are left out, and its tail, which gets two thirds of the room as failures are usually reported last. Both parts end or start at a line break when one is near.
func KillLeftover ¶
KillLeftover kills the process group a daemon that is gone started. The group is left alone when its leader is gone, is another process that got its PID, or cannot be checked; its processes then outlive the task.
func LoginEnvironment ¶ added in v0.2.1
LoginEnvironment is the environment a bash login shell started with environ sets up, such as the PATH entries of profile scripts; read once, it lets commands run with a plain bash -c, which is faster and prints nothing extra.
Types ¶
type Chunk ¶
type Chunk struct {
Text string
// Next is the cursor after Text; Skipped counts bytes dropped before it.
Next int64
Skipped int64
// More is set when output past Next was already written.
More bool
}
Chunk is output read from a cursor on.
type Leader ¶
Leader identifies a process group's leader across daemon restarts: the boot it ran in and its start within it tell it apart from a later process with its PID. Empty fields could not be read.
type Output ¶
type Output struct {
// contains filtered or unexported fields
}
Output is the file a command writes its stdout and stderr to.
func CreateOutput ¶
CreateOutput creates the file at path, readable by the owner only.
type Process ¶
type Process struct {
// contains filtered or unexported fields
}
Process is a running shell command; its process group has the ID of its PID.
func Start ¶
Start runs command with bash -c in dir and env (nil inherits the daemon's) under box, a resolved sandbox policy, in a process group of its own and with stdin from /dev/null, its stdout and stderr going to out until every process that has them, the shell and the commands it left running, closed them.
func (*Process) Done ¶
func (p *Process) Done() <-chan struct{}
Done is closed once the process exited and its output is closed.
func (*Process) ExitCode ¶
ExitCode is the shell's exit code once Done is closed; -1 when a signal ended it.
func (*Process) Exited ¶
func (p *Process) Exited() <-chan struct{}
Exited is closed once the shell exited; commands it left running may still write.
func (*Process) KillLeftovers ¶ added in v0.2.1
KillLeftovers kills the processes the shell left running in its group once it exited, and reports whether there were any.
func (*Process) Stop ¶
Stop asks every process of the group to end with SIGTERM and kills the group with SIGKILL when the command is not done within grace.
func (*Process) WaitOutput ¶
WaitOutput waits for the shell to exit and then at most delay for the commands it left running to close the output; after that it stops reading what they write. It returns once Done is closed.
type Ran ¶ added in v0.2.1
Ran is what a command Run waited for printed, cut at its limit, and its exit code.
func Run ¶ added in v0.2.1
func Run(ctx context.Context, command, dir string, env []string, stdin []byte, limit int) (Ran, error)
Run runs command with bash -c in dir and env (nil inherits the daemon's), in a process group of its own, with stdin as its input, and waits for it. When ctx stops first its group is killed and ctx's error returned. Processes it leaves in its group are killed; each output keeps at most limit bytes.