systemd

package
v0.80.4 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package systemd provides a set of functions to manage systemd units

Index

Constants

View Source
const (
	// UserUnitsPath is the directory where systemd user unit files are stored
	UserUnitsPath = "/etc/systemd/system"
)

Variables

This section is empty.

Functions

func DisableUnit

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

DisableUnit disables a systemd unit

func DisableUnits added in v0.68.0

func DisableUnits(ctx context.Context, units ...string) error

DisableUnits disables multiple systemd units

func EnableUnit

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

EnableUnit enables a systemd unit

func IsRunning

func IsRunning() (running bool, err error)

IsRunning checks if systemd is running as PID 1. It first checks the documented sd_booted() sentinel directory (https://www.freedesktop.org/software/systemd/man/latest/sd_booted.html#Notes), then confirms via /proc/1/comm that systemd is actually the init process. The second check guards against container environments where /run/systemd/system exists but systemd is not PID 1, which causes systemctl to fail with "System has not been booted with systemd as init system (PID 1). Can't operate."

func JournaldLogs added in v0.68.0

func JournaldLogs(ctx context.Context, unit string, since time.Time) (string, error)

JournaldLogs returns the logs for a given unit since a given time

func Reload

func Reload(ctx context.Context) (err error)

Reload reloads the systemd daemon

func RestartUnit

func RestartUnit(ctx context.Context, unit string, args ...string) error

RestartUnit restarts a systemd unit

func StartUnit

func StartUnit(ctx context.Context, unit string, args ...string) error

StartUnit starts a systemd unit

func StopUnit

func StopUnit(ctx context.Context, unit string, args ...string) error

StopUnit starts a systemd unit

func StopUnits

func StopUnits(ctx context.Context, units ...string) error

StopUnits stops multiple systemd units

func WriteUnitOverride

func WriteUnitOverride(ctx context.Context, unit string, name string, content string) (err error)

WriteUnitOverride writes a systemd unit override

Types

This section is empty.

Jump to

Keyboard shortcuts

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