systemd

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package systemd provides utilities for interacting with systemd units.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v0.30.0

type Client interface {
	Start(ctx context.Context, units ...string) error
	Stop(ctx context.Context, units ...string) error
	Restart(ctx context.Context, units ...string) error
	Reload(ctx context.Context, units ...string) error
	DaemonReload(ctx context.Context) error
	Enable(ctx context.Context, units ...string) error
	Disable(ctx context.Context, units ...string) error
	Close() error
}

Client provides operations for managing systemd units via D-Bus.

func New added in v0.30.0

func New(ctx context.Context, scope Scope) (Client, error)

New creates a new systemd Client with the given scope. If scope is ScopeAuto, it uses ScopeUser when running as non-root.

type Error added in v0.21.0

type Error struct {
	Op    string
	Unit  string
	Scope Scope
	Err   error
}

Error represents a systemd operation error with context.

func (*Error) Error added in v0.21.0

func (e *Error) Error() string

func (*Error) Unwrap added in v0.21.0

func (e *Error) Unwrap() error

type Scope added in v0.30.0

type Scope int

Scope represents the systemd connection scope.

const (
	// ScopeAuto automatically selects user or system based on UID.
	ScopeAuto Scope = iota
	// ScopeSystem connects to the system bus (requires root).
	ScopeSystem
	// ScopeUser connects to the user session bus.
	ScopeUser
)

func (Scope) String added in v0.30.0

func (s Scope) String() string

type Unit

type Unit struct {
	Name string
	File *ini.File
}

Unit represents a systemd unit file.

func BuildContainer added in v0.30.0

func BuildContainer(projectName, serviceName string, svc *types.ServiceConfig, projectNetworks types.Networks, projectVolumes types.Volumes) Unit

BuildContainer converts a compose service into a container unit file. projectNetworks provides the project-level network configs so that external networks can be referenced by name rather than as Quadlet unit files.

func BuildNetwork added in v0.30.0

func BuildNetwork(projectName, netName string, net *types.NetworkConfig) Unit

BuildNetwork converts a compose network into a network unit file.

func BuildVolume added in v0.30.0

func BuildVolume(projectName, volName string, vol *types.VolumeConfig) Unit

BuildVolume converts a compose volume into a volume unit file.

func Convert added in v0.30.0

func Convert(project *types.Project) ([]Unit, error)

Convert transforms a loaded compose project into systemd unit files.

func (*Unit) WriteUnit added in v0.30.0

func (u *Unit) WriteUnit(w io.Writer) error

WriteUnit serializes a unit file to the given writer using go-ini.

Jump to

Keyboard shortcuts

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