Class: SystemdMon::DBusManager

Inherits:
Object
  • Object
show all
Defined in:
lib/systemd_mon/dbus_manager.rb

Instance Method Summary collapse

Constructor Details

#initializeDBusManager

Returns a new instance of DBusManager.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/systemd_mon/dbus_manager.rb', line 7

def initialize
  self.dbus            = DBus::SystemBus.instance
  self.systemd_service = dbus.service("org.freedesktop.systemd1")
  self.systemd_object  = systemd_service.object("/org/freedesktop/systemd1")
  systemd_object.introspect
  if systemd_object.respond_to?("Subscribe")
    systemd_object.Subscribe
  else
    raise SystemdMon::SystemdError, "Systemd is not installed, or is an incompatible version. It must provide the Subscribe dbus method: version 204 is the minimum recommended version."
  end
end

Instance Method Details

#fetch_unit(unit_name) ⇒ Object



19
20
21
22
23
24
# File 'lib/systemd_mon/dbus_manager.rb', line 19

def fetch_unit(unit_name)
  path = systemd_object.GetUnit(unit_name).first
  DBusUnit.new(unit_name, path, systemd_service.object(path))
rescue DBus::Error
  raise SystemdMon::UnknownUnitError, "Unknown or unloaded systemd unit '#{unit_name}'"
end

#runnerObject



26
27
28
29
30
# File 'lib/systemd_mon/dbus_manager.rb', line 26

def runner
  main = DBus::Main.new
  main << dbus
  main
end