systemd

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 20 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

func CollectBindMountHashes added in v0.31.1

func CollectBindMountHashes(svc *types.ServiceConfig, workingDir, repoPath string) map[string]string

CollectBindMountHashes computes SHA256 hashes for bind-mounted regular files within the project directory for a single service. Files outside the project dir, directories, and unreadable files are skipped.

func ComputeUnitState added in v0.31.1

func ComputeUnitState(unit Unit, svc *types.ServiceConfig, workingDir, repoPath string) state.UnitState

ComputeUnitState computes content and bind mount hashes for change detection. It hashes the rendered unit file content and any bind-mounted regular files whose source paths are within the project directory.

func WriteUnits added in v0.31.1

func WriteUnits(units []Unit, quadletDir string) error

WriteUnits writes each unit to a separate file in the quadlet directory.

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 RepositoryMeta added in v0.32.0

type RepositoryMeta struct {
	Name       string
	URL        string
	Ref        string
	ComposeDir string
}

RepositoryMeta holds repository metadata used to generate fixed labels on all Quadlet unit types (containers, volumes, networks).

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, repo RepositoryMeta) 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, repo RepositoryMeta) 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, repo RepositoryMeta) Unit

BuildVolume converts a compose volume into a volume unit file.

func Convert added in v0.30.0

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

Convert transforms a loaded compose project into systemd unit files. The repo parameter provides repository metadata for fixed labels applied to all units.

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