Class: Svcs

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

Overview

Solaris services

Instance Attribute Summary

Attributes inherited from ServiceManager

#inspec, #service_ctl

Instance Method Summary collapse

Constructor Details

#initialize(service_name, service_ctl = nil) ⇒ Svcs

Returns a new instance of Svcs.



500
501
502
503
# File 'lib/resources/service.rb', line 500

def initialize(service_name, service_ctl = nil)
  @service_ctl ||= 'svcs'
  super
end

Instance Method Details

#info(service_name) ⇒ Object



505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# File 'lib/resources/service.rb', line 505

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

  params = SimpleConfig.new(
    cmd.stdout.chomp,
    assignment_re: /^(\w+)\s*(.*)$/,
    multiple_values: false,
  ).params

  installed = cmd.exit_status == 0
  running = installed && (params['state'] == 'online')
  enabled = installed && (params['enabled'] == 'true')

  {
    name: service_name,
    description: params['name'],
    installed: installed,
    running: running,
    enabled: enabled,
    type: 'svcs',
  }
end