Documentation
¶
Index ¶
Constants ¶
View Source
const ( UnitActiveStateActive = "active" UnitActiveStateInactive = "inactive" UnitActiveStateFailed = "failed" )
Variables ¶
View Source
var ErrUnitNotFound = errors.New("unit not found")
Functions ¶
func EnsureUnitRunning ¶ added in v0.0.13
func EnsureUnitRunning( ctx context.Context, m Manager, unitName string, reloadDaemon bool, restartUnit bool, ) error
EnsureUnitRunning ensures a systemd unit is active.
When reloadDaemon is true, the systemd daemon is reloaded first so that it picks up any unit file changes on disk. This must be set whenever the unit file (or a drop-in) has been created or modified.
When restartUnit is true and the unit is already active, it is reloaded/restarted (e.g. because associated configuration changed).
If the unit is not active regardless of the flags, it is started.
Types ¶
type Manager ¶
type Manager interface {
// DaemonReload triggers a systemd daemon reload to recognize new or changed unit files.
DaemonReload(ctx context.Context) error
// EnableUnit enables a systemd unit by name, allowing it to start on boot.
EnableUnit(ctx context.Context, unitName string) error
// StartUnit starts a systemd unit by name.
StartUnit(ctx context.Context, unitName string) error
// ReloadOrRestartUnit reloads or restarts a systemd unit by name.
ReloadOrRestartUnit(ctx context.Context, unitName string) error
// GetUnitStatus retrieves the status of a systemd unit by name.
// Returns ErrUnitNotFound if no unit with the specified name exists.
GetUnitStatus(ctx context.Context, unitName string) (dbus.UnitStatus, error)
// EnsureUnitFile idempotently ensures the systemd unit file in /etc/systemd/system/
// has the desired content. It writes the file only if the content differs from
// what's currently on disk. This is useful when overriding a vendor-provided unit
// file in /lib/systemd/system/ with a custom one.
// Returns true if the file was written (i.e., content changed or file was created).
EnsureUnitFile(ctx context.Context, unitName string, content []byte) (bool, error)
// EnsureDropInFile idempotently ensures a systemd drop-in file for the specified unit
// has the desired content. It writes the file only if the content differs from
// what's currently on disk.
// Returns true if the file was written (i.e., content changed or file was created).
EnsureDropInFile(ctx context.Context, unitName string, dropInName string, content []byte) (bool, error)
}
Manager defines the interface for interacting with systemd.
Click to show internal directories.
Click to hide internal directories.