Class: BSDInit
- Inherits:
-
ServiceManager
- Object
- ServiceManager
- BSDInit
- 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
235 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 |
# File 'lib/resources/service.rb', line 235 def info(service_name) # check if service is enabled # services are enabled in /etc/rc.conf and /etc/defaults/rc.conf # via #{service_name}_enable="YES" # service SERVICE status returns the following result if not activated: # Cannot 'status' sshd. Set sshd_enable to YES in /etc/rc.conf or use 'onestatus' instead of 'status'. # gather all enabled services cmd = inspec.command('service -e') return nil if cmd.exit_status != 0 # search for the service srv = /(^.*#{service_name}$)/.match(cmd.stdout) return nil if srv.nil? || srv[0].nil? enabled = true # check if the service is running # if the service is not available or not running, we always get an error code cmd = inspec.command("service #{service_name} onestatus") cmd.exit_status == 0 ? (running = true) : (running = false) { name: service_name, description: nil, installed: true, running: running, enabled: enabled, type: 'bsd-init', } end |