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 KillGroup(pgid int) error
- func KillLeftover(leader Leader) 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) 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)
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 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.
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 -lc in dir, in a process group of its own, 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) 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.