Documentation
¶
Overview ¶
Package service manages init/service units through an injected exec.Runner.
Build a Manager for an explicit backend (systemd is the only one today) and a Runner, then call its methods. Query verbs (is-enabled/is-active) run unprivileged; mutations escalate through the Runner.
r, _ := exec.NewRunner(exec.Direct) svc, _ := service.New(service.Systemd, r) _ = svc.EnableNow(ctx, "nginx.service")
Detect reports whether systemd is usable on the host so a consumer can choose a backend explicitly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownBackend = fmt.Errorf("service: unknown backend")
ErrUnknownBackend is returned by New for the zero value or any Backend the SDK does not implement (fail-closed).
var ErrUnsafeUnitContent = fmt.Errorf("unsafe systemd unit content")
ErrUnsafeUnitContent is returned by WriteUnit when the unit body carries a directive that would turn the agent into a root persistence / dropper primitive. A unit file written to /etc/systemd/system is executed by PID 1 as root, so its content is as privileged as the executables it names — the content policy below is the gate that keeps an attacker-supplied unit from running `curl | sh`, preloading a hostile library into every service, or executing a payload out of a world-writable directory.
Functions ¶
func ValidateUnitName ¶
ValidateUnitName reports whether unit is a safe, well-formed systemd unit name.
Types ¶
type Backend ¶
type Backend int
Backend selects the service-manager implementation. Passed explicitly even though systemd is the only value today; the zero value is invalid (New → ErrUnknownBackend). The deleted OpenRC/Runit/S6 scaffolds — which only ever returned "not supported" — are not ported; a real second backend is appended here when actually written.
type Manager ¶
type Manager interface {
Status(ctx context.Context, unit string) (UnitStatus, error)
IsEnabled(ctx context.Context, unit string) (bool, error)
IsActive(ctx context.Context, unit string) (bool, error)
IsMasked(ctx context.Context, unit string) (bool, error)
Enable(ctx context.Context, unit string) error
Disable(ctx context.Context, unit string) error
EnableNow(ctx context.Context, unit string) error
DisableNow(ctx context.Context, unit string) error
Start(ctx context.Context, unit string) error
Stop(ctx context.Context, unit string) error
Restart(ctx context.Context, unit string) error
// Reload asks a running unit to re-read its configuration via its
// ExecReload command, without restarting it (so it keeps open connections
// and child processes). A unit that defines no ExecReload makes systemctl
// exit non-zero, returned as a *exec.CommandError — use Restart for those.
Reload(ctx context.Context, unit string) error
Mask(ctx context.Context, unit string) error
Unmask(ctx context.Context, unit string) error
DaemonReload(ctx context.Context) error
WriteUnit(ctx context.Context, unit, content string) error
RemoveUnit(ctx context.Context, unit string) error
}
Manager is the service-manager contract.