Class: LaunchCtl

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

Overview

MacOS / Darwin new launctl on macos 10.10

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



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/resources/service.rb', line 285

def info(service_name)
  # get the status of upstart service
  cmd = inspec.command('launchctl list')
  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?

  # extract values from service
  parsed_srv = /^([0-9]+)\s*(\w*)\s*(\S*)/.match(srv[0])
  !parsed_srv.nil? ? (enabled = true) : (enabled = false)

  # check if the service is running
  pid = parsed_srv[0]
  !pid.nil? ? (running = true) : (running = false)

  # extract service label
  srv = parsed_srv[3] || service_name

  {
    name: srv,
    description: nil,
    installed: true,
    running: running,
    enabled: enabled,
    type: 'darwin',
  }
end