systemd

package
v0.0.0-...-ac9d2ad Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NotifySocketEnvVar = "NOTIFY_SOCKET"
	NotifyWatchdog     = "WATCHDOG=1"
	NotifyReloading    = "RELOADING=1"
	NotifyStopping     = "STOPPING=1"
	NotifyReady        = "READY=1"

	ServiceStateActive = "active"
	JobResultDone      = "done"

	BusObjectPropertyActiveState = "ActiveState"

	BusObjectSystemdDest     = "org.freedesktop.systemd1"
	BusObjectSystemdDestUnit = BusObjectSystemdDest + ".Unit"
	BusObjectSystemdPath     = "/org/freedesktop/systemd1"
	BusObjectSystemdUnitTmpl = "/org/freedesktop/systemd1/unit/%s"

	BusMemberGetProp = "org.freedesktop.DBus.Properties.Get"

	// Systemd Manager actions
	BusManagerInterface     = BusObjectSystemdDest + ".Manager"
	BusInterfaceStartUnit   = BusManagerInterface + ".StartUnit"
	BusInterfaceStopUnit    = BusManagerInterface + ".StopUnit"
	BusInterfaceRestartUnit = BusManagerInterface + ".RestartUnit"

	// Signals
	BusMemberJobRemoved      = "JobRemoved"
	BusSignalJobRemoved      = BusManagerInterface + "." + BusMemberJobRemoved
	BusMemberJobNew          = "JobNew"
	BusMemberUnitNew         = "UnitNew"
	BusMemberUnitRemoved     = "UnitRemoved"
	BusMemberStartupFinished = "StartupFinished"

	NetworkManagerUserConfigDirectory = "/etc/NetworkManager/system-connections/"
	NetworkManagerActivationTimeout   = 60 * time.Second
)

Variables

This section is empty.

Functions

func EntertainWatchdog

func EntertainWatchdog() error

EntertainWatchdog sends a notification to the systemd watchdog

func EscapeObjectPath

func EscapeObjectPath(path string) string

EscapeObjectPath sanitizes a D-Bus ObjectPath string. This function replaces any characters that are not letters or digits with their corresponding hexadecimal encoding, preceded by an underscore character. If the input string is empty, this function returns an underscore character.

func Notify

func Notify(msg string) error

Notify sends the provided msg to the systemd socket

Types

type Connector

type Connector struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewConnector

func NewConnector() (*Connector, error)

Create a new connector for systemd

func (*Connector) AddMatchSignal

func (c *Connector) AddMatchSignal(options ...dbus.MatchOption) error

AddMatchSignal adds a match signal

func (*Connector) CheckUnitState

func (c *Connector) CheckUnitState(unitName string, ctx context.Context) (string, error)

Retrieves the unit state for a specified unit

func (*Connector) Connected

func (c *Connector) Connected() bool

Connected returns if the client is correctly connected

func (*Connector) GetRawDbusClient

func (c *Connector) GetRawDbusClient() *dbuscon.Client

GetRawDbusClient returns the underlying dbus client of this instance, use wisely!

func (*Connector) GetRawDbusConnection

func (c *Connector) GetRawDbusConnection() *dbus.Conn

GetRawDbusConnection returns the currently active dbus connection

func (*Connector) RemoveMatchSignal

func (c *Connector) RemoveMatchSignal(options ...dbus.MatchOption) error

RemoveMatchSignal removes a match signal

func (*Connector) RemoveSignal

func (c *Connector) RemoveSignal(ch chan<- *dbus.Signal) error

RemoveSignal removes a signal channel from the list

func (*Connector) ReqRestartUnit

func (c *Connector) ReqRestartUnit(unitName string, ctx context.Context, cb chan<- string) error

ReqRestartUnit performs a restart and offers to pass on the data to the callback channel

func (*Connector) ReqStartUnit

func (c *Connector) ReqStartUnit(unitName string, ctx context.Context, cb chan<- string) error

ReqStartUnit performs a start and offers to pass on the data to the callback channel

func (*Connector) ReqStopUnit

func (c *Connector) ReqStopUnit(unitName string, ctx context.Context, cb chan<- string) error

ReqStopUnit performs a stop and offers to pass on the data to the callback channel

func (*Connector) RequestReconnect

func (c *Connector) RequestReconnect() error

This function requests a reconnect

func (*Connector) RestartUnit

func (c *Connector) RestartUnit(unitName string, ctx context.Context) (bool, error)

RestartUnit synchronously restarts an unit and returns true if it succeded

func (*Connector) Shutdown

func (c *Connector) Shutdown() error

func (*Connector) Signal

func (c *Connector) Signal(ch chan<- *dbus.Signal) error

Signal registers a signal channel

func (*Connector) StartUnit

func (c *Connector) StartUnit(unitName string, ctx context.Context) (bool, error)

StartUnit synchronously starts an unit and returns true if it succeded

func (*Connector) StopUnit

func (c *Connector) StopUnit(unitName string, ctx context.Context) (bool, error)

StopUnit synchronously stops an unit and returns true if it succeded

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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