class DBus::Systemd::Manager

Constants

INTERFACE

systemd manager dbus interface

JOB_INDICES

index map of job array returned by ListJobs

NODE

systemd manager object dbus node path

UNIT_INDICES

index map of unit array returned by ListUnits

Attributes

service[R]

@return [DBus::Service] @api private

Public Class Methods

new(bus = Systemd::Helpers.system_bus) click to toggle source

Create a systemd manager dbus proxy object

@param bus [DBus::SystemBus, DBus::SessionBus] bus instance

# File lib/dbus/systemd/manager.rb, line 77
def initialize(bus = Systemd::Helpers.system_bus)
  @service = bus.service(Systemd::SERVICE)
  @object = @service.object(NODE)
  @object.default_iface = INTERFACE
  @object.introspect
end

Public Instance Methods

get_job_by_object_path(path) click to toggle source

get job by dbus node path

@param path [String] job dbus node path @return [DBus::Systemd::Job] job dbus proxy object

# File lib/dbus/systemd/manager.rb, line 143
def get_job_by_object_path(path)
  obj = @service.object(path)
                .tap(&:introspect)
  Job.new(obj.Get(Job::INTERFACE, 'Id').first, self)
end
get_unit_by_object_path(path) click to toggle source

get unit object by dbus node path

@param path [String] unit dbus node path @return [DBus::Systemd::Unit] unit dbus proxy object

# File lib/dbus/systemd/manager.rb, line 106
def get_unit_by_object_path(path)
  obj = @service.object(path)
                .tap(&:introspect)
  Unit.new(obj.Get(Unit::INTERFACE, 'Id').first, self)
end
job(id) click to toggle source

get job by id

@param id [Integer] job id @return [DBus::Systemd::Job] job dbus proxy object

# File lib/dbus/systemd/manager.rb, line 134
def job(id)
  Job.new(id, self)
end
jobs() click to toggle source

array of jobs from ListJobs mapped to property hashes

@return [Array] array of job property hashes

# File lib/dbus/systemd/manager.rb, line 125
def jobs
  self.ListJobs.first.map { |j| map_job(j) }
end
map_job(job_array) click to toggle source

map job array from ListJobs to property hash

@param job_array [Array] job property array as returned by ListJobs @return [Hash] mapped job property hash

# File lib/dbus/systemd/manager.rb, line 154
def map_job(job_array)
  Helpers.map_array(job_array, JOB_INDICES)
end
map_unit(unit_array) click to toggle source

map unit array from ListUnits to property hash

@param unit_array [Array] array as returned from ListUnits @return [Hash] unit property hash

# File lib/dbus/systemd/manager.rb, line 117
def map_unit(unit_array)
  Helpers.map_array(unit_array, UNIT_INDICES)
end
unit(name) click to toggle source

get a unit dbus proxy object by name

@param name [String] unit name (e.g. 'sshd.service') @return [DBus::Systemd::Unit] unit dbus proxy object

# File lib/dbus/systemd/manager.rb, line 97
def unit(name)
  Unit.new(name, self)
end
units() click to toggle source

get an array of mapped units/unit properties

@return [Array] array of mapped unit property hashes

# File lib/dbus/systemd/manager.rb, line 88
def units
  self.ListUnits.first.map { |u| map_unit(u) }
end