Class: ConfigOMat::SystemdInterface
- Inherits:
-
Object
- Object
- ConfigOMat::SystemdInterface
- Defined in:
- lib/config_o_mat/shared/systemd_interface.rb
Constant Summary collapse
- SERVICE_NAME =
'org.freedesktop.systemd1'
- OBJECT_PATH =
'/org/freedesktop/systemd1'
- MANAGER_INTERFACE =
'org.freedesktop.systemd1.Manager'
- UNIT_INTERFACE =
'org.freedesktop.systemd1.Unit'
- UNIT_STATE =
'ActiveState'
Instance Method Summary collapse
- #==(other) ⇒ Object
- #daemon_reload ⇒ Object
- #enable_restart_paths(units) ⇒ Object
- #enable_start_stop_paths(units) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(sysbus = nil) ⇒ SystemdInterface
constructor
A new instance of SystemdInterface.
- #service_interface(unit_name) ⇒ Object
- #service_status(unit_name) ⇒ Object
Constructor Details
#initialize(sysbus = nil) ⇒ SystemdInterface
Returns a new instance of SystemdInterface.
28 29 30 31 32 33 34 |
# File 'lib/config_o_mat/shared/systemd_interface.rb', line 28 def initialize(sysbus = nil) if sysbus @sysd_service = sysbus[SERVICE_NAME] obj = @sysd_service[OBJECT_PATH] @sysd_iface = obj[MANAGER_INTERFACE] end end |
Instance Method Details
#==(other) ⇒ Object
69 70 71 |
# File 'lib/config_o_mat/shared/systemd_interface.rb', line 69 def ==(other) eql?(other) end |
#daemon_reload ⇒ Object
65 66 67 |
# File 'lib/config_o_mat/shared/systemd_interface.rb', line 65 def daemon_reload @sysd_iface.Reload() end |
#enable_restart_paths(units) ⇒ Object
53 54 55 56 |
# File 'lib/config_o_mat/shared/systemd_interface.rb', line 53 def enable_restart_paths(units) path_units = units.map { |unit| "teak-configurator-restart-service@#{unit}.path" } enable_and_start(path_units) end |
#enable_start_stop_paths(units) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/config_o_mat/shared/systemd_interface.rb', line 58 def enable_start_stop_paths(units) path_units = units.flat_map do |unit| ["teak-configurator-start-service@#{unit}.path", "teak-configurator-stop-service@#{unit}.path"] end enable_and_start(path_units) end |
#eql?(other) ⇒ Boolean
73 74 75 76 77 |
# File 'lib/config_o_mat/shared/systemd_interface.rb', line 73 def eql?(other) return false if !other.is_a?(self.class) return false if other.instance_variable_get(:@sysd_service) != @sysd_service true end |
#service_interface(unit_name) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/config_o_mat/shared/systemd_interface.rb', line 36 def service_interface(unit_name) unit_path = @sysd_iface.GetUnit("#{unit_name}.service") unit_obj = @sysd_service[unit_path] unit_obj[UNIT_INTERFACE] rescue DBus::Error nil end |
#service_status(unit_name) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/config_o_mat/shared/systemd_interface.rb', line 44 def service_status(unit_name) iface = service_interface(unit_name) if iface iface[UNIT_STATE] else 'inactive' end end |