Help us shape the future of Go! Take the 2026 Go Developer Survey

unitmon

package
v0.37.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package unitmon lists the units a systemd manager reports failed and tells when any unit's ActiveState may have changed, over D-Bus. One Monitor watches one manager: the system manager on the system bus or the user manager on the session bus. Policy (notify, clear, log) is the caller's: this package only reports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Monitor

type Monitor struct {
	// contains filtered or unexported fields
}

Monitor lists one systemd manager's failed units and reports when a unit's ActiveState may have changed. It is safe for concurrent use.

func Absent

func Absent() *Monitor

Absent returns a Monitor for a manager that is not watched (no bus, the monitor disabled, or the manager not running): Present is false, Failed is empty, neither returns an error, and Changed never fires.

func New

func New(conn *dbus.Conn, log *slog.Logger) *Monitor

New watches the systemd manager on conn, a bus connection the caller keeps open and closes. It adds match rules for unit ActiveState changes and UnitRemoved, then calls Manager.Subscribe, without which systemd emits no unit signal. Changes that happen before New returns are not reported: list them with Failed after New.

A failed match rule or Subscribe is logged once at WARN naming the bus name and leaves Changed silent; Present and Failed still work. A Subscribe refused because nothing owns the name (the manager is absent) logs nothing, so the caller's own report of the absence is the only line. Nothing else is ever logged. The caller passes log.With("manager", ...) so the WARN names the manager. A nil log discards.

func (*Monitor) Changed

func (m *Monitor) Changed() <-chan struct{}

Changed fires after the manager reports a unit ActiveState change or an unloaded unit. Changes that arrive before the receiver reads coalesce into one. The channel is closed when the bus connection is lost (or closed by the caller); it is never closed by Absent or after a failed setup, where it simply never fires.

func (*Monitor) Failed

func (m *Monitor) Failed(ctx context.Context) ([]Unit, error)

Failed lists the units the manager reports in the failed state. Names come from the manager's reply, never from the escaped unit object paths.

func (*Monitor) Present

func (m *Monitor) Present(ctx context.Context) (bool, error)

Present reports whether the manager's name is owned on the bus.

type Unit

type Unit struct {
	Name string // the unit name as systemd reports it, e.g. "sshd.service"
}

Unit is one unit the manager reports failed.

Jump to

Keyboard shortcuts

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