Documentation ¶
Overview ¶
Integration with the systemd D-Bus API. See http://www.freedesktop.org/wiki/Software/systemd/dbus/
Index ¶
- func PathBusEscape(path string) string
- type Conn
- func New() (*Conn, error)
- func NewConnection(dialBus func() (*dbus.Conn, error)) (*Conn, error)
- func NewSystemConnection() (*Conn, error)
- func NewSystemConnectionContext(ctx context.Context) (*Conn, error)
- func NewSystemdConnection() (*Conn, error)
- func NewSystemdConnectionContext(ctx context.Context) (*Conn, error)
- func NewUserConnection() (*Conn, error)
- func NewUserConnectionContext(ctx context.Context) (*Conn, error)
- func NewWithContext(ctx context.Context) (*Conn, error)
- func (c *Conn) Close()
- func (c *Conn) DisableUnitFiles(files []string, runtime bool) ([]DisableUnitFileChange, error)
- func (c *Conn) DisableUnitFilesContext(ctx context.Context, files []string, runtime bool) ([]DisableUnitFileChange, error)
- func (c *Conn) EnableUnitFiles(files []string, runtime bool, force bool) (bool, []EnableUnitFileChange, error)
- func (c *Conn) EnableUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) (bool, []EnableUnitFileChange, error)
- func (c *Conn) GetAllProperties(unit string) (map[string]interface{}, error)
- func (c *Conn) GetAllPropertiesContext(ctx context.Context, unit string) (map[string]interface{}, error)
- func (c *Conn) GetManagerProperty(prop string) (string, error)
- func (c *Conn) GetServiceProperty(service string, propertyName string) (*Property, error)
- func (c *Conn) GetServicePropertyContext(ctx context.Context, service string, propertyName string) (*Property, error)
- func (c *Conn) GetUnitPathProperties(path dbus.ObjectPath) (map[string]interface{}, error)
- func (c *Conn) GetUnitPathPropertiesContext(ctx context.Context, path dbus.ObjectPath) (map[string]interface{}, error)
- func (c *Conn) GetUnitProperties(unit string) (map[string]interface{}, error)
- func (c *Conn) GetUnitPropertiesContext(ctx context.Context, unit string) (map[string]interface{}, error)
- func (c *Conn) GetUnitProperty(unit string, propertyName string) (*Property, error)deprecated
- func (c *Conn) GetUnitPropertyContext(ctx context.Context, unit string, propertyName string) (*Property, error)
- func (c *Conn) GetUnitTypeProperties(unit string, unitType string) (map[string]interface{}, error)
- func (c *Conn) GetUnitTypePropertiesContext(ctx context.Context, unit string, unitType string) (map[string]interface{}, error)
- func (c *Conn) GetUnitTypeProperty(unit string, unitType string, propertyName string) (*Property, error)deprecated
- func (c *Conn) GetUnitTypePropertyContext(ctx context.Context, unit string, unitType string, propertyName string) (*Property, error)
- func (c *Conn) KillUnit(name string, signal int32)
- func (c *Conn) KillUnitContext(ctx context.Context, name string, signal int32)
- func (c *Conn) KillUnitWithTarget(ctx context.Context, name string, target Who, signal int32) error
- func (c *Conn) LinkUnitFiles(files []string, runtime bool, force bool) ([]LinkUnitFileChange, error)
- func (c *Conn) LinkUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) ([]LinkUnitFileChange, error)
- func (c *Conn) ListJobs() ([]JobStatus, error)
- func (c *Conn) ListJobsContext(ctx context.Context) ([]JobStatus, error)
- func (c *Conn) ListUnitFiles() ([]UnitFile, error)
- func (c *Conn) ListUnitFilesByPatterns(states []string, patterns []string) ([]UnitFile, error)
- func (c *Conn) ListUnitFilesByPatternsContext(ctx context.Context, states []string, patterns []string) ([]UnitFile, error)
- func (c *Conn) ListUnitFilesContext(ctx context.Context) ([]UnitFile, error)
- func (c *Conn) ListUnits() ([]UnitStatus, error)
- func (c *Conn) ListUnitsByNames(units []string) ([]UnitStatus, error)
- func (c *Conn) ListUnitsByNamesContext(ctx context.Context, units []string) ([]UnitStatus, error)
- func (c *Conn) ListUnitsByPatterns(states []string, patterns []string) ([]UnitStatus, error)
- func (c *Conn) ListUnitsByPatternsContext(ctx context.Context, states []string, patterns []string) ([]UnitStatus, error)
- func (c *Conn) ListUnitsContext(ctx context.Context) ([]UnitStatus, error)
- func (c *Conn) ListUnitsFiltered(states []string) ([]UnitStatus, error)
- func (c *Conn) ListUnitsFilteredContext(ctx context.Context, states []string) ([]UnitStatus, error)
- func (c *Conn) MaskUnitFiles(files []string, runtime bool, force bool) ([]MaskUnitFileChange, error)
- func (c *Conn) MaskUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) ([]MaskUnitFileChange, error)
- func (conn *Conn) NewSubscriptionSet() *SubscriptionSet
- func (c *Conn) Reload() error
- func (c *Conn) ReloadContext(ctx context.Context) error
- func (c *Conn) ReloadOrRestartUnit(name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) ReloadOrRestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) ReloadOrTryRestartUnit(name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) ReloadOrTryRestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) ReloadUnit(name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) ReloadUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) ResetFailedUnit(name string) error
- func (c *Conn) ResetFailedUnitContext(ctx context.Context, name string) error
- func (c *Conn) RestartUnit(name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) RestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) SetPropertiesSubscriber(updateCh chan<- *PropertiesUpdate, errCh chan<- error)
- func (c *Conn) SetSubStateSubscriber(updateCh chan<- *SubStateUpdate, errCh chan<- error)
- func (c *Conn) SetUnitProperties(name string, runtime bool, properties ...Property) error
- func (c *Conn) SetUnitPropertiesContext(ctx context.Context, name string, runtime bool, properties ...Property) error
- func (c *Conn) StartTransientUnit(name string, mode string, properties []Property, ch chan<- string) (int, error)
- func (c *Conn) StartTransientUnitContext(ctx context.Context, name string, mode string, properties []Property, ...) (int, error)
- func (c *Conn) StartUnit(name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) StartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) StopUnit(name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) StopUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) Subscribe() error
- func (c *Conn) SubscribeUnits(interval time.Duration) (<-chan map[string]*UnitStatus, <-chan error)
- func (c *Conn) SubscribeUnitsCustom(interval time.Duration, buffer int, ...) (<-chan map[string]*UnitStatus, <-chan error)
- func (c *Conn) SystemState() (*Property, error)
- func (c *Conn) SystemStateContext(ctx context.Context) (*Property, error)
- func (c *Conn) TryRestartUnit(name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) TryRestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
- func (c *Conn) UnmaskUnitFiles(files []string, runtime bool) ([]UnmaskUnitFileChange, error)
- func (c *Conn) UnmaskUnitFilesContext(ctx context.Context, files []string, runtime bool) ([]UnmaskUnitFileChange, error)
- func (c *Conn) Unsubscribe() error
- type DisableUnitFileChange
- type EnableUnitFileChange
- type JobStatus
- type LinkUnitFileChange
- type MaskUnitFileChange
- type PropertiesUpdate
- type Property
- func PropAfter(units ...string) Property
- func PropBefore(units ...string) Property
- func PropBindsTo(units ...string) Property
- func PropBoundBy(units ...string) Property
- func PropConflictedBy(units ...string) Property
- func PropConflicts(units ...string) Property
- func PropDescription(desc string) Property
- func PropExecStart(command []string, uncleanIsFailure bool) Property
- func PropOnFailure(units ...string) Property
- func PropPids(pids ...uint32) Property
- func PropPropagatesReloadTo(units ...string) Property
- func PropRemainAfterExit(b bool) Property
- func PropRequiredBy(units ...string) Property
- func PropRequiredByOverridable(units ...string) Property
- func PropRequires(units ...string) Property
- func PropRequiresMountsFor(units ...string) Property
- func PropRequiresOverridable(units ...string) Property
- func PropRequisite(units ...string) Property
- func PropRequisiteOverridable(units ...string) Property
- func PropSlice(slice string) Property
- func PropTriggeredBy(units ...string) Property
- func PropTriggers(units ...string) Property
- func PropType(t string) Property
- func PropWantedBy(units ...string) Property
- func PropWants(units ...string) Property
- type PropertyCollection
- type SubStateUpdate
- type SubscriptionSet
- func (s SubscriptionSet) Add(value string)
- func (s SubscriptionSet) Contains(value string) (exists bool)
- func (s SubscriptionSet) Length() int
- func (s SubscriptionSet) Remove(value string)
- func (s *SubscriptionSet) Subscribe() (<-chan map[string]*UnitStatus, <-chan error)
- func (s SubscriptionSet) Values() (values []string)
- type UnitFile
- type UnitStatus
- type UnmaskUnitFileChange
- type Who
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PathBusEscape ¶
PathBusEscape sanitizes a constituent string of a dbus ObjectPath using the rules that systemd uses for serializing special characters.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a connection to systemd's dbus endpoint.
func New ¶
New establishes a connection to any available bus and authenticates. Callers should call Close() when done with the connection. Deprecated: use NewWithContext instead
func NewConnection ¶
NewConnection establishes a connection to a bus using a caller-supplied function. This allows connecting to remote buses through a user-supplied mechanism. The supplied function may be called multiple times, and should return independent connections. The returned connection must be fully initialised: the org.freedesktop.DBus.Hello call must have succeeded, and any authentication should be handled by the function.
func NewSystemConnection ¶
NewSystemConnection establishes a connection to the system bus and authenticates. Callers should call Close() when done with the connection Deprecated: use NewSystemConnectionContext instead
func NewSystemConnectionContext ¶ added in v22.2.0
NewSystemConnectionContext same as NewSystemConnection with context
func NewSystemdConnection ¶
NewSystemdConnection establishes a private, direct connection to systemd. This can be used for communicating with systemd without a dbus daemon. Callers should call Close() when done with the connection. Deprecated: use NewSystemdConnectionContext instead
func NewSystemdConnectionContext ¶ added in v22.2.0
NewSystemdConnectionContext same as NewSystemdConnection with context
func NewUserConnection ¶
NewUserConnection establishes a connection to the session bus and authenticates. This can be used to connect to systemd user instances. Callers should call Close() when done with the connection. Deprecated: use NewUserConnectionContext instead
func NewUserConnectionContext ¶ added in v22.2.0
NewUserConnectionContext same as NewUserConnection with context
func NewWithContext ¶ added in v22.2.0
NewWithContext same as New with context
func (*Conn) DisableUnitFiles ¶
func (c *Conn) DisableUnitFiles(files []string, runtime bool) ([]DisableUnitFileChange, error)
DisableUnitFiles() may be used to disable one or more units in the system (by removing symlinks to them from /etc or /run).
It takes a list of unit files to disable (either just file names or full absolute paths if the unit files are residing outside the usual unit search paths), and one boolean: whether the unit was enabled for runtime only (true, /run), or persistently (false, /etc).
This call returns an array with the changes made. The changes list consists of structures with three strings: the type of the change (one of symlink or unlink), the file name of the symlink and the destination of the symlink. Deprecated: use DisableUnitFilesContext instead
func (*Conn) DisableUnitFilesContext ¶ added in v22.2.0
func (c *Conn) DisableUnitFilesContext(ctx context.Context, files []string, runtime bool) ([]DisableUnitFileChange, error)
DisableUnitFilesContext same as DisableUnitFiles with context
func (*Conn) EnableUnitFiles ¶
func (c *Conn) EnableUnitFiles(files []string, runtime bool, force bool) (bool, []EnableUnitFileChange, error)
EnableUnitFiles() may be used to enable one or more units in the system (by creating symlinks to them in /etc or /run).
It takes a list of unit files to enable (either just file names or full absolute paths if the unit files are residing outside the usual unit search paths), and two booleans: the first controls whether the unit shall be enabled for runtime only (true, /run), or persistently (false, /etc). The second one controls whether symlinks pointing to other units shall be replaced if necessary.
This call returns one boolean and an array with the changes made. The boolean signals whether the unit files contained any enablement information (i.e. an [Install]) section. The changes list consists of structures with three strings: the type of the change (one of symlink or unlink), the file name of the symlink and the destination of the symlink. Deprecated: use EnableUnitFilesContext instead
func (*Conn) EnableUnitFilesContext ¶ added in v22.2.0
func (c *Conn) EnableUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) (bool, []EnableUnitFileChange, error)
EnableUnitFilesContext same as EnableUnitFiles with context
func (*Conn) GetAllProperties ¶
GetAllProperties takes the (unescaped) unit name and returns all of its dbus object properties. Deprecated: use GetAllPropertiesContext instead
func (*Conn) GetAllPropertiesContext ¶ added in v22.2.0
func (c *Conn) GetAllPropertiesContext(ctx context.Context, unit string) (map[string]interface{}, error)
GetAllPropertiesContext same as GetAllProperties with context
func (*Conn) GetManagerProperty ¶
GetManagerProperty returns the value of a property on the org.freedesktop.systemd1.Manager interface. The value is returned in its string representation, as defined at https://developer.gnome.org/glib/unstable/gvariant-text.html
func (*Conn) GetServiceProperty ¶
GetServiceProperty returns property for given service name and property name Deprecated: use GetServicePropertyContext instead
func (*Conn) GetServicePropertyContext ¶ added in v22.2.0
func (c *Conn) GetServicePropertyContext(ctx context.Context, service string, propertyName string) (*Property, error)
GetServicePropertyContext same as GetServiceProperty with context
func (*Conn) GetUnitPathProperties ¶
GetUnitPathProperties takes the (escaped) unit path and returns all of its dbus object properties. Deprecated: use GetUnitPathPropertiesContext instead
func (*Conn) GetUnitPathPropertiesContext ¶ added in v22.2.0
func (c *Conn) GetUnitPathPropertiesContext(ctx context.Context, path dbus.ObjectPath) (map[string]interface{}, error)
GetUnitPathPropertiesContext same as GetUnitPathProperties with context
func (*Conn) GetUnitProperties ¶
GetUnitProperties takes the (unescaped) unit name and returns all of its dbus object properties. Deprecated: use GetUnitPropertiesContext instead
func (*Conn) GetUnitPropertiesContext ¶ added in v22.2.0
func (c *Conn) GetUnitPropertiesContext(ctx context.Context, unit string) (map[string]interface{}, error)
GetUnitPropertiesContext same as GetUnitPropertiesContext with context
func (*Conn) GetUnitPropertyContext ¶ added in v22.2.0
func (c *Conn) GetUnitPropertyContext(ctx context.Context, unit string, propertyName string) (*Property, error)
GetUnitPropertyContext same as GetUnitProperty with context
func (*Conn) GetUnitTypeProperties ¶
GetUnitTypeProperties returns the extra properties for a unit, specific to the unit type. Valid values for unitType: Service, Socket, Target, Device, Mount, Automount, Snapshot, Timer, Swap, Path, Slice, Scope return "dbus.Error: Unknown interface" if the unitType is not the correct type of the unit Deprecated: use GetUnitTypePropertiesContext instead
func (*Conn) GetUnitTypePropertiesContext ¶ added in v22.2.0
func (c *Conn) GetUnitTypePropertiesContext(ctx context.Context, unit string, unitType string) (map[string]interface{}, error)
GetUnitTypePropertiesContext same as GetUnitTypeProperties with context
func (*Conn) GetUnitTypePropertyContext ¶ added in v22.2.0
func (c *Conn) GetUnitTypePropertyContext(ctx context.Context, unit string, unitType string, propertyName string) (*Property, error)
GetUnitTypePropertyContext same as GetUnitTypeProperty with context
func (*Conn) KillUnit ¶
KillUnit takes the unit name and a UNIX signal number to send. All of the unit's processes are killed. Deprecated: use KillUnitContext instead
func (*Conn) KillUnitContext ¶ added in v22.2.0
KillUnitContext same as KillUnit with context
func (*Conn) KillUnitWithTarget ¶ added in v22.3.0
KillUnitWithTarget is like KillUnitContext, but allows you to specify which process in the unit to send the signal to
func (*Conn) LinkUnitFiles ¶
func (c *Conn) LinkUnitFiles(files []string, runtime bool, force bool) ([]LinkUnitFileChange, error)
LinkUnitFiles() links unit files (that are located outside of the usual unit search paths) into the unit search path.
It takes a list of absolute paths to unit files to link and two booleans. The first boolean controls whether the unit shall be enabled for runtime only (true, /run), or persistently (false, /etc). The second controls whether symlinks pointing to other units shall be replaced if necessary.
This call returns a list of the changes made. The list consists of structures with three strings: the type of the change (one of symlink or unlink), the file name of the symlink and the destination of the symlink. Deprecated: use LinkUnitFilesContext instead
func (*Conn) LinkUnitFilesContext ¶ added in v22.2.0
func (c *Conn) LinkUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) ([]LinkUnitFileChange, error)
LinkUnitFilesContext same as LinkUnitFiles with context
func (*Conn) ListJobs ¶ added in v22.2.0
ListJobs returns an array with all currently queued jobs Deprecated: use ListJobsContext instead
func (*Conn) ListJobsContext ¶ added in v22.2.0
ListJobsContext same as ListJobs with context
func (*Conn) ListUnitFiles ¶
ListUnitFiles returns an array of all available units on disk. Deprecated: use ListUnitFilesContext instead
func (*Conn) ListUnitFilesByPatterns ¶
ListUnitFilesByPatterns returns an array of all available units on disk matched the patterns. Deprecated: use ListUnitFilesByPatternsContext instead
func (*Conn) ListUnitFilesByPatternsContext ¶ added in v22.2.0
func (c *Conn) ListUnitFilesByPatternsContext(ctx context.Context, states []string, patterns []string) ([]UnitFile, error)
ListUnitFilesByPatternsContext same as ListUnitFilesByPatterns with context
func (*Conn) ListUnitFilesContext ¶ added in v22.2.0
ListUnitFilesContext same as ListUnitFiles with context
func (*Conn) ListUnits ¶
func (c *Conn) ListUnits() ([]UnitStatus, error)
ListUnits returns an array with all currently loaded units. Note that units may be known by multiple names at the same time, and hence there might be more unit names loaded than actual units behind them. Also note that a unit is only loaded if it is active and/or enabled. Units that are both disabled and inactive will thus not be returned. Deprecated: use ListUnitsContext instead
func (*Conn) ListUnitsByNames ¶
func (c *Conn) ListUnitsByNames(units []string) ([]UnitStatus, error)
ListUnitsByNames returns an array with units. It takes a list of units' names and returns an UnitStatus array. Comparing to ListUnitsByPatterns method, this method returns statuses even for inactive or non-existing units. Input array should contain exact unit names, but not patterns. Note: Requires systemd v230 or higher Deprecated: use ListUnitsByNamesContext instead
func (*Conn) ListUnitsByNamesContext ¶ added in v22.2.0
ListUnitsByNamesContext same as ListUnitsByNames with context
func (*Conn) ListUnitsByPatterns ¶
func (c *Conn) ListUnitsByPatterns(states []string, patterns []string) ([]UnitStatus, error)
ListUnitsByPatterns returns an array with units. It takes a list of units' statuses and names to filter. Note that units may be known by multiple names at the same time, and hence there might be more unit names loaded than actual units behind them. Deprecated: use ListUnitsByPatternsContext instead
func (*Conn) ListUnitsByPatternsContext ¶ added in v22.2.0
func (c *Conn) ListUnitsByPatternsContext(ctx context.Context, states []string, patterns []string) ([]UnitStatus, error)
ListUnitsByPatternsContext same as ListUnitsByPatterns with context
func (*Conn) ListUnitsContext ¶ added in v22.2.0
func (c *Conn) ListUnitsContext(ctx context.Context) ([]UnitStatus, error)
ListUnitsContext same as ListUnits with context
func (*Conn) ListUnitsFiltered ¶
func (c *Conn) ListUnitsFiltered(states []string) ([]UnitStatus, error)
ListUnitsFiltered returns an array with units filtered by state. It takes a list of units' statuses to filter. Deprecated: use ListUnitsFilteredContext instead
func (*Conn) ListUnitsFilteredContext ¶ added in v22.2.0
ListUnitsFilteredContext same as ListUnitsFiltered with context
func (*Conn) MaskUnitFiles ¶
func (c *Conn) MaskUnitFiles(files []string, runtime bool, force bool) ([]MaskUnitFileChange, error)
MaskUnitFiles masks one or more units in the system
It takes three arguments:
- list of units to mask (either just file names or full absolute paths if the unit files are residing outside the usual unit search paths)
- runtime to specify whether the unit was enabled for runtime only (true, /run/systemd/..), or persistently (false, /etc/systemd/..)
- force flag
Deprecated: use MaskUnitFilesContext instead
func (*Conn) MaskUnitFilesContext ¶ added in v22.2.0
func (c *Conn) MaskUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) ([]MaskUnitFileChange, error)
MaskUnitFilesContext same as MaskUnitFiles with context
func (*Conn) NewSubscriptionSet ¶
func (conn *Conn) NewSubscriptionSet() *SubscriptionSet
NewSubscriptionSet returns a new subscription set.
func (*Conn) Reload ¶
Reload instructs systemd to scan for and reload unit files. This is equivalent to a 'systemctl daemon-reload'. Deprecated: use ReloadContext instead
func (*Conn) ReloadContext ¶ added in v22.2.0
ReloadContext same as Reload with context
func (*Conn) ReloadOrRestartUnit ¶
ReloadOrRestartUnit attempts a reload if the unit supports it and use a restart otherwise. Deprecated: use ReloadOrRestartUnitContext instead
func (*Conn) ReloadOrRestartUnitContext ¶ added in v22.2.0
func (c *Conn) ReloadOrRestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
ReloadOrRestartUnitContext same as ReloadOrRestartUnit with context
func (*Conn) ReloadOrTryRestartUnit ¶
ReloadOrTryRestartUnit attempts a reload if the unit supports it and use a "Try" flavored restart otherwise. Deprecated: use ReloadOrTryRestartUnitContext instead
func (*Conn) ReloadOrTryRestartUnitContext ¶ added in v22.2.0
func (c *Conn) ReloadOrTryRestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
ReloadOrTryRestartUnitContext same as ReloadOrTryRestartUnit with context
func (*Conn) ReloadUnit ¶
ReloadUnit reloads a unit. Reloading is done only if the unit is already running and fails otherwise. Deprecated: use ReloadUnitContext instead
func (*Conn) ReloadUnitContext ¶ added in v22.2.0
func (c *Conn) ReloadUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
ReloadUnitContext same as ReloadUnit with context
func (*Conn) ResetFailedUnit ¶
ResetFailedUnit resets the "failed" state of a specific unit. Deprecated: use ResetFailedUnitContext instead
func (*Conn) ResetFailedUnitContext ¶ added in v22.2.0
ResetFailedUnitContext same as ResetFailedUnit with context
func (*Conn) RestartUnit ¶
RestartUnit restarts a service. If a service is restarted that isn't running it will be started. Deprecated: use RestartUnitContext instead
func (*Conn) RestartUnitContext ¶ added in v22.2.0
func (c *Conn) RestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
RestartUnitContext same as RestartUnit with context
func (*Conn) SetPropertiesSubscriber ¶
func (c *Conn) SetPropertiesSubscriber(updateCh chan<- *PropertiesUpdate, errCh chan<- error)
SetPropertiesSubscriber writes to updateCh when any unit's properties change. Every property change reported by systemd will be sent; that is, no transitions will be "missed" (as they might be with SetSubStateSubscriber). However, state changes will only be written to the channel with non-blocking writes. If updateCh is full, it attempts to write an error to errCh; if errCh is full, the error passes silently.
func (*Conn) SetSubStateSubscriber ¶
func (c *Conn) SetSubStateSubscriber(updateCh chan<- *SubStateUpdate, errCh chan<- error)
SetSubStateSubscriber writes to updateCh when any unit's substate changes. Although this writes to updateCh on every state change, the reported state may be more recent than the change that generated it (due to an unavoidable race in the systemd dbus interface). That is, this method provides a good way to keep a current view of all units' states, but is not guaranteed to show every state transition they go through. Furthermore, state changes will only be written to the channel with non-blocking writes. If updateCh is full, it attempts to write an error to errCh; if errCh is full, the error passes silently.
func (*Conn) SetUnitProperties ¶
SetUnitProperties() may be used to modify certain unit properties at runtime. Not all properties may be changed at runtime, but many resource management settings (primarily those in systemd.cgroup(5)) may. The changes are applied instantly, and stored on disk for future boots, unless runtime is true, in which case the settings only apply until the next reboot. name is the name of the unit to modify. properties are the settings to set, encoded as an array of property name and value pairs. Deprecated: use SetUnitPropertiesContext instead
func (*Conn) SetUnitPropertiesContext ¶ added in v22.2.0
func (c *Conn) SetUnitPropertiesContext(ctx context.Context, name string, runtime bool, properties ...Property) error
SetUnitPropertiesContext same as SetUnitProperties with context
func (*Conn) StartTransientUnit ¶
func (c *Conn) StartTransientUnit(name string, mode string, properties []Property, ch chan<- string) (int, error)
StartTransientUnit() may be used to create and start a transient unit, which will be released as soon as it is not running or referenced anymore or the system is rebooted. name is the unit name including suffix, and must be unique. mode is the same as in StartUnit(), properties contains properties of the unit. Deprecated: use StartTransientUnitContext instead
func (*Conn) StartTransientUnitContext ¶ added in v22.2.0
func (c *Conn) StartTransientUnitContext(ctx context.Context, name string, mode string, properties []Property, ch chan<- string) (int, error)
StartTransientUnitContext same as StartTransientUnit with context
func (*Conn) StartUnit ¶
StartUnit enqueues a start job and depending jobs, if any (unless otherwise specified by the mode string).
Takes the unit to activate, plus a mode string. The mode needs to be one of replace, fail, isolate, ignore-dependencies, ignore-requirements. If "replace" the call will start the unit and its dependencies, possibly replacing already queued jobs that conflict with this. If "fail" the call will start the unit and its dependencies, but will fail if this would change an already queued job. If "isolate" the call will start the unit in question and terminate all units that aren't dependencies of it. If "ignore-dependencies" it will start a unit but ignore all its dependencies. If "ignore-requirements" it will start a unit but only ignore the requirement dependencies. It is not recommended to make use of the latter two options.
If the provided channel is non-nil, a result string will be sent to it upon job completion: one of done, canceled, timeout, failed, dependency, skipped. done indicates successful execution of a job. canceled indicates that a job has been canceled before it finished execution. timeout indicates that the job timeout was reached. failed indicates that the job failed. dependency indicates that a job this job has been depending on failed and the job hence has been removed too. skipped indicates that a job was skipped because it didn't apply to the units current state.
If no error occurs, the ID of the underlying systemd job will be returned. There does exist the possibility for no error to be returned, but for the returned job ID to be 0. In this case, the actual underlying ID is not 0 and this datapoint should not be considered authoritative.
If an error does occur, it will be returned to the user alongside a job ID of 0. Deprecated: use StartUnitContext instead
func (*Conn) StartUnitContext ¶ added in v22.2.0
func (c *Conn) StartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
StartUnitContext same as StartUnit with context
func (*Conn) StopUnit ¶
StopUnit is similar to StartUnit but stops the specified unit rather than starting it. Deprecated: use StopUnitContext instead
func (*Conn) StopUnitContext ¶ added in v22.2.0
func (c *Conn) StopUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
StopUnitContext same as StopUnit with context
func (*Conn) Subscribe ¶
Subscribe sets up this connection to subscribe to all systemd dbus events. This is required before calling SubscribeUnits. When the connection closes systemd will automatically stop sending signals so there is no need to explicitly call Unsubscribe().
func (*Conn) SubscribeUnits ¶
SubscribeUnits returns two unbuffered channels which will receive all changed units every interval. Deleted units are sent as nil.
func (*Conn) SubscribeUnitsCustom ¶
func (c *Conn) SubscribeUnitsCustom(interval time.Duration, buffer int, isChanged func(*UnitStatus, *UnitStatus) bool, filterUnit func(string) bool) (<-chan map[string]*UnitStatus, <-chan error)
SubscribeUnitsCustom is like SubscribeUnits but lets you specify the buffer size of the channels, the comparison function for detecting changes and a filter function for cutting down on the noise that your channel receives.
func (*Conn) SystemState ¶
SystemState returns the systemd state. Equivalent to `systemctl is-system-running`. Deprecated: use SystemStateContext instead
func (*Conn) SystemStateContext ¶ added in v22.2.0
SystemStateContext same as SystemState with context
func (*Conn) TryRestartUnit ¶
TryRestartUnit is like RestartUnit, except that a service that isn't running is not affected by the restart. Deprecated: use TryRestartUnitContext instead
func (*Conn) TryRestartUnitContext ¶ added in v22.2.0
func (c *Conn) TryRestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error)
TryRestartUnitContext same as TryRestartUnit with context
func (*Conn) UnmaskUnitFiles ¶
func (c *Conn) UnmaskUnitFiles(files []string, runtime bool) ([]UnmaskUnitFileChange, error)
UnmaskUnitFiles unmasks one or more units in the system
It takes two arguments:
- list of unit files to mask (either just file names or full absolute paths if the unit files are residing outside the usual unit search paths)
- runtime to specify whether the unit was enabled for runtime only (true, /run/systemd/..), or persistently (false, /etc/systemd/..)
Deprecated: use UnmaskUnitFilesContext instead
func (*Conn) UnmaskUnitFilesContext ¶ added in v22.2.0
func (c *Conn) UnmaskUnitFilesContext(ctx context.Context, files []string, runtime bool) ([]UnmaskUnitFileChange, error)
UnmaskUnitFilesContext same as UnmaskUnitFiles with context
func (*Conn) Unsubscribe ¶
Unsubscribe this connection from systemd dbus events.
type DisableUnitFileChange ¶
type EnableUnitFileChange ¶
type JobStatus ¶ added in v22.2.0
type JobStatus struct { Id uint32 // The numeric job id Unit string // The primary unit name for this job JobType string // The job type as string Status string // The job state as string JobPath dbus.ObjectPath // The job object path UnitPath dbus.ObjectPath // The unit object path }
Currently queued job definition
type LinkUnitFileChange ¶
type LinkUnitFileChange EnableUnitFileChange
type MaskUnitFileChange ¶
type PropertiesUpdate ¶
PropertiesUpdate holds a map of a unit's changed properties
type Property ¶
type Property struct { Name string Value dbus.Variant }
func PropAfter ¶
PropAfter sets the After unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#After=
func PropBefore ¶
PropBefore sets the Before unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Before=
func PropBindsTo ¶
PropBindsTo sets the BindsTo unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#BindsTo=
func PropBoundBy ¶
PropBoundBy sets the BoundBy unit property. See http://www.freedesktop.org/software/systemd/main/systemd.unit.html#BoundBy=
func PropConflictedBy ¶
PropConflictedBy sets the ConflictedBy unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#ConflictedBy=
func PropConflicts ¶
PropConflicts sets the Conflicts unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Conflicts=
func PropDescription ¶
PropDescription sets the Description unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit#Description=
func PropExecStart ¶
PropExecStart sets the ExecStart service property. The first argument is a slice with the binary path to execute followed by the arguments to pass to the executed command. See http://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecStart=
func PropOnFailure ¶
PropOnFailure sets the OnFailure unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#OnFailure=
func PropPids ¶
PropPids sets the PIDs field of scope units used in the initial construction of the scope only and specifies the initial PIDs to add to the scope object. See https://www.freedesktop.org/wiki/Software/systemd/ControlGroupInterface/#properties
func PropPropagatesReloadTo ¶
PropPropagatesReloadTo sets the PropagatesReloadTo unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#PropagatesReloadTo=
func PropRemainAfterExit ¶
PropRemainAfterExit sets the RemainAfterExit service property. See http://www.freedesktop.org/software/systemd/man/systemd.service.html#RemainAfterExit=
func PropRequiredBy ¶
PropRequiredBy sets the RequiredBy unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiredBy=
func PropRequiredByOverridable ¶
PropRequiredByOverridable sets the RequiredByOverridable unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiredByOverridable=
func PropRequires ¶
PropRequires sets the Requires unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Requires=
func PropRequiresMountsFor ¶
PropRequiresMountsFor sets the RequiresMountsFor unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiresMountsFor=
func PropRequiresOverridable ¶
PropRequiresOverridable sets the RequiresOverridable unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiresOverridable=
func PropRequisite ¶
PropRequisite sets the Requisite unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Requisite=
func PropRequisiteOverridable ¶
PropRequisiteOverridable sets the RequisiteOverridable unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequisiteOverridable=
func PropSlice ¶
PropSlice sets the Slice unit property. See http://www.freedesktop.org/software/systemd/man/systemd.resource-control.html#Slice=
func PropTriggeredBy ¶
PropTriggeredBy sets the TriggeredBy unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#TriggeredBy=
func PropTriggers ¶
PropTriggers sets the Triggers unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Triggers=
func PropType ¶
PropType sets the Type service property. See http://www.freedesktop.org/software/systemd/man/systemd.service.html#Type=
func PropWantedBy ¶
PropWantedBy sets the WantedBy unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#WantedBy=
func PropWants ¶
PropWants sets the Wants unit property. See http://www.freedesktop.org/software/systemd/man/systemd.unit.html#Wants=
type PropertyCollection ¶
type SubStateUpdate ¶
type SubscriptionSet ¶
type SubscriptionSet struct {
// contains filtered or unexported fields
}
SubscriptionSet returns a subscription set which is like conn.Subscribe but can filter to only return events for a set of units.
func (*SubscriptionSet) Subscribe ¶
func (s *SubscriptionSet) Subscribe() (<-chan map[string]*UnitStatus, <-chan error)
Subscribe starts listening for dbus events for all of the units in the set. Returns channels identical to conn.SubscribeUnits.
type UnitStatus ¶
type UnitStatus struct { Name string // The primary unit name as string Description string // The human readable description string LoadState string // The load state (i.e. whether the unit file has been loaded successfully) ActiveState string // The active state (i.e. whether the unit is currently started or not) SubState string // The sub state (a more fine-grained version of the active state that is specific to the unit type, which the active state is not) Followed string // A unit that is being followed in its state by this unit, if there is any, otherwise the empty string. Path dbus.ObjectPath // The unit object path JobId uint32 // If there is a job queued for the job unit the numeric job id, 0 otherwise JobType string // The job type as string JobPath dbus.ObjectPath // The job object path }