Class: Inspec::Resources::Upstart

Inherits:
ServiceManager show all
Includes:
FileReader
Defined in:
lib/inspec/resources/service.rb

Overview

Instance Attribute Summary

Attributes inherited from ServiceManager

#inspec, #service_ctl

Instance Method Summary collapse

Methods included from FileReader

#read_file_content

Constructor Details

#initialize(service_name, service_ctl = nil) ⇒ Upstart

Returns a new instance of Upstart.



377
378
379
380
# File 'lib/inspec/resources/service.rb', line 377

def initialize(service_name, service_ctl = nil)
  @service_ctl = service_ctl || "initctl"
  super
end

Instance Method Details

#info(service_name) ⇒ Object



382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/inspec/resources/service.rb', line 382

def info(service_name)
  # get the status of upstart service
  status = inspec.command("#{service_ctl} status #{service_name}")

  # fallback for systemv services, those are not handled via `initctl`
  return SysV.new(inspec).info(service_name) if status.exit_status.to_i != 0 || status.stdout == ""

  # @see: http://upstart.ubuntu.com/cookbook/#job-states
  # grep for running to indicate the service is there
  running = !status.stdout[%r{start/running}].nil?
  enabled = info_enabled(service_name)

  {
    name: service_name,
    description: nil,
    installed: true,
    running: running,
    enabled: enabled,
    type: "upstart",
  }
end