mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
add systemd implementation for service
This commit is contained in:
parent
204e6f5021
commit
b8d0edecfb
1 changed files with 34 additions and 0 deletions
|
@ -55,6 +55,40 @@ class ServiceManager
|
|||
end
|
||||
end
|
||||
|
||||
# @see: http://www.freedesktop.org/software/systemd/man/systemctl.html
|
||||
# @see: http://www.freedesktop.org/software/systemd/man/systemd-system.conf.html
|
||||
class Systemd < ServiceManager
|
||||
def info(service_name)
|
||||
|
||||
cmd = @vulcano.run_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['LoadState'] == '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
|
||||
end
|
||||
# Determine the service state from Windows
|
||||
# Uses Powershell to retrieve the information
|
||||
class WindowsSrv < ServiceManager
|
||||
|
|
Loading…
Add table
Reference in a new issue