Documentation
¶
Index ¶
- func AutostartUserUnits() []string
- func DBusActiveState(name string) string
- func DBusDaemonReload() error
- func DBusDisableService(name string) error
- func DBusEnableService(name string) error
- func DBusIsEnabled(name string) bool
- func DBusResetFailed(name string) error
- func DBusRestartUnit(name string) error
- func DBusStartUnit(name string) error
- func DBusStopUnit(name string) error
- func DisableService(name string) error
- func EnableService(name string) error
- func FindOrphanedWorkers(siteName string, known map[string]bool) []string
- func GetUnit(name string) (string, error)
- func IsAutostartEnabled() bool
- func IsServiceActive(name string) bool
- func IsServiceActiveOrRestarting(name string) bool
- func IsServiceEnabled(name string) bool
- func IsTimerActive(name string) bool
- func NotifyReady()
- func NotifyStopping()
- func RemoveTimer(name string) error
- func RestartService(name string) error
- func SessionIsIdle() bool
- func SessionIsIdleOrLocked() bool
- func SessionIsLocked() bool
- func StartService(name string) error
- func SubscribeLerdUnitStateChanges(ctx context.Context, onChange func(unitName string)) error
- func WriteService(name, content string) error
- func WriteServiceIfChanged(name, content string) (bool, error)
- func WriteTimerIfChanged(name, content string) (bool, error)
- type UnitStateWatcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutostartUserUnits ¶ added in v1.9.0
func AutostartUserUnits() []string
AutostartUserUnits returns the lerd-* systemd user units (NOT podman quadlets) that participate in "autostart at login": lerd-ui, lerd-watcher, lerd-tray, and every per-site worker/queue/schedule/ horizon/reverb/stripe service file currently present in the user's systemd/user/ directory. These can be enabled/disabled with `systemctl --user enable/disable` because they are real on-disk unit files (not generator output).
Container quadlets are NOT in this list because their auto-start behaviour is controlled by stripping the [Install] section from the .container file (see podman.StripInstallSection), not by systemctl enable/disable. The autostart toggle handles quadlets via the global config flag and a quadlet rewrite pass.
func DBusActiveState ¶
DBusActiveState returns the ActiveState property ("active", "inactive", "failed", "activating", …) for the named unit, or "" when the unit is unknown. Unit name may be bare (e.g. "lerd-foo") or fully-qualified ("lerd-foo.service", "lerd-foo.timer").
func DBusDaemonReload ¶
func DBusDaemonReload() error
DBusDaemonReload runs systemctl --user daemon-reload over DBus.
func DBusDisableService ¶
DBusDisableService removes a user service from the login start set.
func DBusEnableService ¶
DBusEnableService marks a user service to start at login.
func DBusIsEnabled ¶
DBusIsEnabled returns true when the unit-file state resolves to "enabled".
func DBusResetFailed ¶
DBusResetFailed clears any "failed" state for the named unit so the next start is not blocked by Restart= rate-limits.
func DBusRestartUnit ¶
DBusRestartUnit restarts a user unit via DBus.
func DBusStartUnit ¶
DBusStartUnit starts a user unit via DBus and waits for the job to finish.
func DisableService ¶ added in v0.3.0
DisableService disables a systemd user service.
func EnableService ¶
EnableService enables a systemd user service.
func FindOrphanedWorkers ¶ added in v1.10.0
FindOrphanedWorkers scans systemd unit files for worker units belonging to the given site that are running but not present in the known workers set.
func IsAutostartEnabled ¶ added in v1.9.0
func IsAutostartEnabled() bool
IsAutostartEnabled reports whether lerd is configured to come up at login. This is the inverse of cfg.Autostart.Disabled — the config flag is the canonical source of truth, not the live `systemctl is-enabled` state of any individual unit, because (a) container quadlets always report "generated" regardless of the wants symlink and (b) the flag must be readable even when no units exist on disk yet (fresh install).
func IsServiceActive ¶ added in v1.0.0
IsServiceActive returns true if the systemd user service is currently active.
func IsServiceActiveOrRestarting ¶ added in v1.5.0
IsServiceActiveOrRestarting returns true if the service is active or in a restart loop (activating). Used to detect workers that should be stopped on unlink.
func IsServiceEnabled ¶ added in v0.3.0
IsServiceEnabled returns true if the systemd user service is enabled.
func IsTimerActive ¶ added in v1.12.0
IsTimerActive returns true if the worker's sibling .timer is active.
func NotifyReady ¶
func NotifyReady()
NotifyReady tells systemd the current process has finished its startup work and is ready to serve. Used by Type=notify units so systemctl start blocks until the service is actually up, not just spawned. No-op outside a systemd-managed process (returns false without error).
func NotifyStopping ¶
func NotifyStopping()
NotifyStopping tells systemd the process is winding down, letting dependent units start their own teardown early instead of waiting for the process to actually exit.
func RemoveTimer ¶ added in v1.12.0
RemoveTimer removes a systemd user timer unit file.
func RestartService ¶ added in v0.6.0
RestartService restarts a systemd user service.
func SessionIsIdle ¶
func SessionIsIdle() bool
SessionIsIdle returns true when systemd-logind reports the current user's active session as idle (the compositor hasn't seen input for the configured idle timeout). Returns false when logind is unreachable or the session can't be identified, so callers behave as if the user is active when the signal is unavailable.
func SessionIsIdleOrLocked ¶
func SessionIsIdleOrLocked() bool
SessionIsIdleOrLocked is a convenience combining both states.
func SessionIsLocked ¶
func SessionIsLocked() bool
SessionIsLocked returns true when the user's session is locked by the screen locker. Returns false when the property is unreadable.
func StartService ¶
StartService starts a systemd user service.
func SubscribeLerdUnitStateChanges ¶
SubscribeLerdUnitStateChanges keeps the previous one-shot subscription helper for non-UI callers (e.g. tests). New code should prefer the stoppable UnitStateWatcher.
func WriteService ¶
WriteService writes a systemd user service unit file.
func WriteServiceIfChanged ¶ added in v0.8.0
WriteServiceIfChanged writes the unit file only when the content differs from what is already on disk. Returns true if the file was written (caller should run daemon-reload), false if it was unchanged (daemon-reload not needed).
func WriteTimerIfChanged ¶ added in v1.12.0
WriteTimerIfChanged writes a systemd user timer unit file when its content differs from what is already on disk. Returns true when the file was written so the caller knows to run daemon-reload.
Types ¶
type UnitStateWatcher ¶
type UnitStateWatcher struct {
// contains filtered or unexported fields
}
UnitStateWatcher manages the DBus SubState subscription. The subscription is expensive at idle: go-systemd's dispatch goroutine receives a PropertiesChanged signal for every property of every active unit and calls GetUnitProperties on each, which on a host with many lerd-* units burns a noticeable chunk of CPU even when nobody is watching the dashboard.
To pay that cost only when it produces value, the daemon starts the watcher when a UI tab connects and stops it when the last one disconnects. Stop closes a dedicated DBus connection so the underlying signal traffic stops at the systemd side rather than just being dropped on our side.
func NewUnitStateWatcher ¶
func NewUnitStateWatcher(onChange func(unitName string)) *UnitStateWatcher
NewUnitStateWatcher returns a watcher that calls onChange on every SubState transition of a lerd-* unit while running. The watcher starts in the stopped state; call Start to begin receiving notifications.
func (*UnitStateWatcher) Start ¶
func (w *UnitStateWatcher) Start() error
Start begins receiving SubState notifications. Calling Start while already running is a no-op. Each Start opens its own DBus connection so a paired Stop can close it cleanly.
func (*UnitStateWatcher) Stop ¶
func (w *UnitStateWatcher) Stop()
Stop tears down the DBus subscription so go-systemd's dispatch goroutine stops fetching unit properties. Safe to call when already stopped.