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.
231 232 233 234 |
# File 'lib/resources/service.rb', line 231 def initialize(inspec, service_ctl = nil) @service_ctl = service_ctl || 'systemctl' super end |
Instance Method Details
#info(service_name) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/resources/service.rb', line 236 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 = %w{enabled static}.include? params['UnitFileState'] { name: params['Id'], description: params['Description'], installed: installed, running: running, enabled: enabled, type: 'systemd', params: params, } end |