Class: Upstart

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

Overview

Instance Attribute Summary

Attributes inherited from ServiceManager

#inspec

Instance Method Summary collapse

Methods inherited from ServiceManager

#initialize

Constructor Details

This class inherits a constructor from ServiceManager

Instance Method Details

#info(service_name) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/resources/service.rb', line 150

def info(service_name)
  # get the status of upstart service
  cmd = inspec.command("initctl status #{service_name}")
  return nil if cmd.exit_status != 0

  # @see: http://upstart.ubuntu.com/cookbook/#job-states
  # grep for running to indicate the service is there
  match_running = /running/.match(cmd.stdout)
  !match_running.nil? ? (running = true) : (running = false)

  # check if a service is enabled
  # http://upstart.ubuntu.com/cookbook/#determine-if-a-job-is-disabled
  # $ initctl show-config $job | grep -q "^  start on" && echo enabled || echo disabled
  # Ubuntu 10.04 show-config is not supported
  # @see http://manpages.ubuntu.com/manpages/maverick/man8/initctl.8.html
  config = inspec.command("initctl show-config #{service_name}")
  match_enabled = /^\s*start on/.match(config.stdout)
  !match_enabled.nil? ? (enabled = true) : (enabled = false)

  # implement fallback for Ubuntu 10.04
  if inspec.os[:family] == 'ubuntu' &&
     inspec.os[:release].to_f >= 10.04 &&
     inspec.os[:release].to_f < 12.04 &&
     cmd.exit_status == 0
    enabled = true
  end

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