Class: Inspec::Resources::Systemd
- Inherits:
-
ServiceManager
- Object
- ServiceManager
- Inspec::Resources::Systemd
- Defined in:
- lib/resources/service.rb
Overview
Instance Attribute Summary
Attributes inherited from ServiceManager
Instance Method Summary collapse
- #info(service_name) ⇒ Object
-
#initialize(inspec, service_ctl = nil) ⇒ Systemd
constructor
A new instance of Systemd.
Constructor Details
#initialize(inspec, service_ctl = nil) ⇒ Systemd
Returns a new instance of Systemd.
194 195 196 197 |
# File 'lib/resources/service.rb', line 194 def initialize(inspec, service_ctl = nil) @service_ctl = service_ctl || 'systemctl' super end |
Instance Method Details
#info(service_name) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/resources/service.rb', line 199 def info(service_name) cmd = inspec.command("#{service_ctl} 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 installed = params['LoadState'] == 'loaded' # test via 'systemctl is-active service' # SubState values running running = params['SubState'] == 'running' # test via systemctl --quiet is-enabled # ActiveState values eg.g inactive, active enabled = params['UnitFileState'] == 'enabled' { name: params['Id'], description: params['Description'], installed: installed, running: running, enabled: enabled, type: 'systemd', } end |