Class: Systemd
- Inherits:
-
ServiceManager
- Object
- ServiceManager
- Systemd
- Defined in:
- lib/resources/service.rb
Overview
Instance Attribute Summary
Attributes inherited from ServiceManager
Instance Method Summary collapse
Methods inherited from ServiceManager
Constructor Details
This class inherits a constructor from ServiceManager
Instance Method Details
#info(service_name) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/resources/service.rb', line 117 def info(service_name) cmd = inspec.command("systemctl show --all #{service_name}") return nil if cmd.exit_status.to_i != 0 # parse data params = SimpleConfig.new( cmd.stdout.chomp, assignment_re: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/, multiple_values: false, ).params # LoadState values eg. loaded, not-found params['LoadState'] == 'loaded' ? (installed = true) : (installed = false) # test via 'systemctl is-active service' # SubState values running params['SubState'] == 'running' ? (running = true) : (running = false) # test via systemctl --quiet is-enabled # ActiveState values eg.g inactive, active params['ActiveState'] == 'active' ? (enabled = true) : (enabled = false) { name: params['Id'], description: params['Description'], installed: installed, running: running, enabled: enabled, type: 'systemd', } end |