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



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/resources/service.rb', line 334

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