dbus package - github.com/coreos/go-systemd/v22/dbus - Go Packages (original) (raw)

Integration with the systemd D-Bus API. See http://www.freedesktop.org/wiki/Software/systemd/dbus/

This section is empty.

This section is empty.

PathBusEscape sanitizes a constituent string of a dbus ObjectPath using the rules that systemd uses for serializing special characters.

Conn is a connection to systemd's dbus endpoint.

Deprecated: use NewWithContext instead.

func NewConnection(dialBus func() (dbus.Conn, error)) (Conn, error)

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() (*Conn, error)

Deprecated: use NewSystemConnectionContext instead.

NewSystemConnectionContext establishes a connection to the system bus and authenticates. Callers should call Close() when done with the connection.

func NewSystemdConnection() (*Conn, error)

Deprecated: use NewSystemdConnectionContext instead.

NewSystemdConnectionContext 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.

func NewUserConnection() (*Conn, error)

Deprecated: use NewUserConnectionContext instead.

NewUserConnectionContext 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.

NewWithContext establishes a connection to any available bus and authenticates. Callers should call Close() when done with the connection.

Close closes an established connection.

func (c *Conn) Connected() bool

Connected returns whether conn is connected

Deprecated: use DisableUnitFilesContext instead.

DisableUnitFilesContext 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 EnableUnitFilesContext instead.

EnableUnitFilesContext 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.

Freeze the cgroup associated with the unit. Note that FreezeUnit and ThawUnit are only supported on systems running with cgroup v2.

Deprecated: use GetAllPropertiesContext instead.

GetAllPropertiesContext takes the (unescaped) unit name and returns all of its dbus object properties.

Deprecated: use GetServicePropertyContext instead.

GetServiceProperty returns property for given service name and property name.

GetUnitByPID returns the unit object path of the unit a process ID belongs to. It takes a UNIX PID and returns the object path. The PID must refer to an existing system process

GetUnitNameByPID returns the name of the unit a process ID belongs to. It takes a UNIX PID and returns the object path. The PID must refer to an existing system process

func (c *Conn) GetUnitPathProperties(path dbus.ObjectPath) (map[string]interface{}, error)

Deprecated: use GetUnitPathPropertiesContext instead.

GetUnitPathPropertiesContext takes the (escaped) unit path and returns all of its dbus object properties.

Deprecated: use GetUnitPropertiesContext instead.

GetUnitPropertiesContext takes the (unescaped) unit name and returns all of its dbus object properties.

Deprecated: use GetUnitPropertyContext instead.

GetUnitPropertyContext takes an (unescaped) unit name, and a property name, and returns the property value.

Deprecated: use GetUnitTypePropertiesContext instead.

GetUnitTypePropertiesContext 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. Returns "dbus.Error: Unknown interface" error if the unitType is not the correct type of the unit.

Deprecated: use GetUnitTypePropertyContext instead.

GetUnitTypePropertyContext takes a property name, a unit name, and a unit type, and returns a property value. For valid values of unitType, see GetUnitTypePropertiesContext.

Deprecated: use KillUnitContext instead.

KillUnitContext takes the unit name and a UNIX signal number to send. All of the unit's processes are killed.

KillUnitWithTarget is like KillUnitContext, but allows you to specify which process in the unit to send the signal to.

Deprecated: use LinkUnitFilesContext instead.

LinkUnitFilesContext 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.

func (c *Conn) ListJobs() ([]JobStatus, error)

Deprecated: use ListJobsContext instead.

ListJobsContext returns an array with all currently queued jobs.

func (c *Conn) ListUnitFiles() ([]UnitFile, error)

Deprecated: use ListUnitFilesContext instead.

Deprecated: use ListUnitFilesByPatternsContext instead.

ListUnitFilesByPatternsContext returns an array of all available units on disk matched the patterns.

ListUnitFiles returns an array of all available units on disk.

func (c *Conn) ListUnits() ([]UnitStatus, error)

Deprecated: use ListUnitsContext instead.

Deprecated: use ListUnitsByNamesContext instead.

ListUnitsByNamesContext returns an array with units. It takes a list of units' names and returns an UnitStatus array. Comparing to ListUnitsByPatternsContext method, this method returns statuses even for inactive or non-existing units. Input array should contain exact unit names, but not patterns.

Requires systemd v230 or higher.

Deprecated: use ListUnitsByPatternsContext instead.

ListUnitsByPatternsContext 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.

ListUnitsContext 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 ListUnitsFilteredContext instead.

ListUnitsFilteredContext returns an array with units filtered by state. It takes a list of units' statuses to filter.

Deprecated: use MaskUnitFilesContext instead.

MaskUnitFilesContext masks one or more units in the system.

The files argument contains a 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).

The runtime argument is used to specify whether the unit was enabled for runtime only (true, /run/systemd/..), or persistently (false, /etc/systemd/..).

func (conn *Conn) NewSubscriptionSet() *SubscriptionSet

NewSubscriptionSet returns a new subscription set.

Deprecated: use ReloadContext instead.

ReloadContext instructs systemd to scan for and reload unit files. This is an equivalent to systemctl daemon-reload.

Deprecated: use ReloadOrRestartUnitContext instead.

ReloadOrRestartUnitContext attempts a reload if the unit supports it and use a restart otherwise.

Deprecated: use ReloadOrTryRestartUnitContext instead.

ReloadOrTryRestartUnitContext attempts a reload if the unit supports it, and use a "Try" flavored restart otherwise.

Deprecated: use ReloadUnitContext instead.

ReloadUnitContext reloads a unit. Reloading is done only if the unit is already running, and fails otherwise.

Deprecated: use ResetFailedUnitContext instead.

ResetFailedUnitContext resets the "failed" state of a specific unit.

Deprecated: use RestartUnitContext instead.

RestartUnitContext restarts a service. If a service is restarted that isn't running it will be started.

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 (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.

Deprecated: use SetUnitPropertiesContext instead.

SetUnitPropertiesContext 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 StartTransientUnitContext instead.

StartTransientUnitContext 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 StartUnitContext, properties contains properties of the unit.

Deprecated: use StartUnitContext instead.

StartUnitContext 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 StopUnitContext instead.

StopUnitContext is similar to StartUnitContext, but stops the specified unit rather than starting it.

func (c *Conn) Subscribe() error

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().

SubscribeUnits returns two unbuffered channels which will receive all changed units every interval. Deleted units are sent as nil.

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 (c Conn) SystemState() (Property, error)

Deprecated: use SystemStateContext instead.

SystemStateContext returns the systemd state. Equivalent to systemctl is-system-running.

Unfreeze the cgroup associated with the unit.

Deprecated: use TryRestartUnitContext instead.

TryRestartUnitContext is like RestartUnitContext, except that a service that isn't running is not affected by the restart.

Deprecated: use UnmaskUnitFilesContext instead.

UnmaskUnitFilesContext unmasks one or more units in the system.

It takes the 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), and a boolean runtime flag to specify whether the unit was enabled for runtime only (true, /run/systemd/..), or persistently (false, /etc/systemd/..).

func (c *Conn) Unsubscribe() error

Unsubscribe this connection from systemd dbus events.

type JobStatus struct { Id uint32
Unit string
JobType string
Status string
JobPath dbus.ObjectPath UnitPath dbus.ObjectPath }

JobStatus holds a currently queued job definition.

type LinkUnitFileChange EnableUnitFileChange

type PropertiesUpdate struct { UnitName string Changed map[string]dbus.Variant }

PropertiesUpdate holds a map of a unit's changed properties

type Property struct { Name string Value dbus.Variant }

type PropertyCollection struct { Name string Properties []Property }

type SubStateUpdate struct { UnitName string SubState string }

type SubscriptionSet struct {

}

SubscriptionSet returns a subscription set which is like conn.Subscribe but can filter to only return events for a set of units.

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)

Subscribe starts listening for dbus events for all of the units in the set. Returns channels identical to conn.SubscribeUnits.

func (s SubscriptionSet) Values() (values []string)

Who can be used to specify which process to kill in the unit via the KillUnitWithTarget API

const (

All [Who](#Who) = "all"

Main [Who](#Who) = "main"

Control [Who](#Who) = "control"

)