sdunit

package
v3.0.0-rc71 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func AnyPID(ctx context.Context, unit string) (int, bool, error)

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

func EnvFile(env []string) ([]byte, error)

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

func EscapeArg(s string) string

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

func Journal(ctx context.Context, invocationID string, n int) []string

Journal returns the last n lines the invocation of a unit logged, as a command failing to start in it says why there.

func Kill

func Kill(ctx context.Context, unit string, sig syscall.Signal) error

Kill sends sig to every process of the unit, which is no job.

func NsenterArgs

func NsenterArgs(pid int) []string

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 PIDs

func PIDs(controlGroup string) []int

PIDs returns the processes of the cgroup of a unit.

func Refused

func Refused(key string) (string, bool)

Refused returns why the property key is refused, if it is.

func ResetFailed

func ResetFailed(ctx context.Context, unit string) error

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

func Terminate(ctx context.Context, log Logger, unit string, timeout time.Duration) error

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.

func Validate

func Validate(s string) error

Validate refuses s when it is not a list of properties, or names one om sets itself.

func WaitInactive

func WaitInactive(ctx context.Context, unit string, timeout time.Duration) (bool, error)

WaitInactive waits for the unit to run no process, up to timeout, and says whether it does.

Types

type Logger

type Logger interface {
	Infof(format string, args ...any)
	Warnf(format string, args ...any)
}

Logger is what Terminate logs to.

type Property

type Property struct {
	Key   string
	Value string
}

Property is a unit property, as systemd-run -p takes it.

func Parse

func Parse(s string) ([]Property, error)

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.

func (Property) String

func (t Property) String() string

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.

func (Run) Args

func (t Run) Args() []string

Args returns the systemd-run command running t.

type State

type State struct {
	ActiveState  string
	Result       string
	MainPID      int
	ControlGroup string
	InvocationID string
}

State is the state of a unit, as systemctl show reports it.

func GetState

func GetState(ctx context.Context, unit string) (State, error)

GetState returns the state of the unit, inactive for a unit not loaded.

func (State) IsActive

func (t State) IsActive() bool

IsActive says the unit runs processes, or is about to.

Jump to

Keyboard shortcuts

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