Documentation
¶
Overview ¶
Package systemd provides a set of functions to manage systemd units
Index ¶
- Constants
- func DisableUnit(ctx context.Context, unit string) error
- func DisableUnits(ctx context.Context, units ...string) error
- func EnableUnit(ctx context.Context, unit string) error
- func IsRunning() (running bool, err error)
- func JournaldLogs(ctx context.Context, unit string, since time.Time) (string, error)
- func Reload(ctx context.Context) (err error)
- func RestartUnit(ctx context.Context, unit string, args ...string) error
- func StartUnit(ctx context.Context, unit string, args ...string) error
- func StopUnit(ctx context.Context, unit string, args ...string) error
- func StopUnits(ctx context.Context, units ...string) error
- func WriteUnitOverride(ctx context.Context, unit string, name string, content string) (err error)
Constants ¶
const (
// UserUnitsPath is the directory where systemd user unit files are stored
UserUnitsPath = "/etc/systemd/system"
)
Variables ¶
This section is empty.
Functions ¶
func DisableUnit ¶
DisableUnit disables a systemd unit
func DisableUnits ¶ added in v0.68.0
DisableUnits disables multiple systemd units
func EnableUnit ¶
EnableUnit enables a systemd unit
func IsRunning ¶
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
JournaldLogs returns the logs for a given unit since a given time
func RestartUnit ¶
RestartUnit restarts a systemd unit
Types ¶
This section is empty.