Documentation
¶
Overview ¶
Package sdunit runs a command in a transient systemd service unit, whose properties sandbox it, and ends the processes of the unit without queuing a stop job.
A stop job is never queued, as systemctl stop would: at a reboot, the stop of the units is one transaction, where the stop job of a unit ordered before the one of the om daemon waits for the daemon to stop, while the daemon waits for the command stopping the unit. The processes of a unit are signaled instead, which is no job, and the unit becomes inactive once they are gone.
Index ¶
- Constants
- func AnyPID(ctx context.Context, unit string) (int, bool, error)
- func EnvFile(env []string) ([]byte, error)
- func EscapeArg(s string) string
- func Journal(ctx context.Context, invocationID string, n int) []string
- func Kill(ctx context.Context, unit string, sig syscall.Signal) error
- func NsenterArgs(pid int) []string
- func PIDs(controlGroup string) []int
- func Refused(key string) (string, bool)
- func ResetFailed(ctx context.Context, unit string) error
- func Terminate(ctx context.Context, log Logger, unit string, timeout time.Duration) error
- func Validate(s string) error
- func WaitInactive(ctx context.Context, unit string, timeout time.Duration) (bool, error)
- type Logger
- type Property
- type Run
- type State
Constants ¶
const ServerUnit = "opensvc-server.service"
ServerUnit is the unit of the om daemon, the units of the commands are ordered before: their stop jobs, at a reboot, come after the one of the daemon, which stops the commands first, in the order of the resources.
Variables ¶
This section is empty.
Functions ¶
func AnyPID ¶
AnyPID returns a process of the unit, its main one if it has one, whose namespaces are the ones of the unit, false when it runs none.
func EnvFile ¶
EnvFile renders env, a list of NAME=VALUE, as an environment file systemd reads, each value double quoted with its \, ", $ and ` escaped, so any value comes back as it is, its newlines included. A variable whose name systemd refuses is an error.
func EscapeArg ¶
EscapeArg returns s as a word of the command of a unit, which systemd expands the variables of: a $ is doubled to stay one.
func Journal ¶
Journal returns the last n lines the invocation of a unit logged, as a command failing to start in it says why there.
func NsenterArgs ¶
NsenterArgs returns the command entering the namespaces of the process pid, the mount, network, ipc and uts ones a unit sandboxes its processes in, to run what follows: a command sees then the files of the unit, as the ones of its private /tmp.
func ResetFailed ¶
ResetFailed forgets a unit that failed, which a unit of the same name starting again needs. A unit not loaded is no error.
func Terminate ¶
Terminate ends the processes of the unit still running, with a SIGTERM, then a SIGKILL to those still running after timeout, and forgets the unit if it failed, so a unit of the name can start again. No stop job is queued.
Types ¶
type Property ¶
Property is a unit property, as systemd-run -p takes it.
func Parse ¶
Parse returns the properties of s, as the systemd_properties keyword sets them: words separated by blanks, quoted as in a shell, a word starting with a property name and = starting a property, the others added to the value of the property before them, separated by a space. So
ProtectSystem=strict ReadWritePaths=/srv/data /var/log/app PrivateTmp=yes
is three properties, the second of two paths.
type Run ¶
type Run struct {
// Unit is the name of the service unit.
Unit string
// Slice is the slice unit the service is placed in, empty for
// the default one.
Slice string
// Description is the description of the unit.
Description string
// Type is the type of the service: notify, forking or exec.
Type string
// Wait makes systemd-run wait for the command to end, its
// standard input and outputs connected to the ones of
// systemd-run, and exit with its exit code.
Wait bool
// Properties are the properties of the configuration, the
// sandbox of the command.
Properties []Property
// OwnProperties are the properties om sets.
OwnProperties []Property
// Argv is the command.
Argv []string
}
Run is a command to run in a transient service unit.