Class: Chef::Provider::Service::Solaris

Inherits:
Chef::Provider::Service show all
Defined in:
lib/chef/provider/service/solaris.rb

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods inherited from Chef::Provider::Service

#action_disable, #action_enable, #action_reload, #action_restart, #action_start, #action_stop

Methods included from Mixin::Command

#chdir_or_tmpdir, #handle_command_failures, #not_if, #only_if, #output_of_command, #run_command, #run_command_with_systems_locale

Methods included from Mixin::Command::Windows

#popen4

Methods included from Mixin::Command::Unix

#popen4

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #cookbook_name, #node, #resource_collection

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Methods included from Mixin::Language

#data_bag, #data_bag_item, #platform?, #search, #value_for_platform

Constructor Details

#initialize(new_resource, run_context = nil) ⇒ Solaris

Returns a new instance of Solaris.



27
28
29
30
31
# File 'lib/chef/provider/service/solaris.rb', line 27

def initialize(new_resource, run_context=nil)
  super
  @init_command = "/usr/sbin/svcadm"
  @status_command = "/bin/svcs -l"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore

Instance Method Details

#disable_serviceObject Also known as: stop_service



48
49
50
51
# File 'lib/chef/provider/service/solaris.rb', line 48

def disable_service
  run_command(:command => "#{@init_command} disable #{@new_resource.service_name}")
  return service_status.enabled
end

#enable_serviceObject Also known as: start_service



43
44
45
46
# File 'lib/chef/provider/service/solaris.rb', line 43

def enable_service
  run_command(:command => "#{@init_command} enable #{@new_resource.service_name}")
  return service_status.enabled
end

#load_current_resourceObject



33
34
35
36
37
38
39
40
41
# File 'lib/chef/provider/service/solaris.rb', line 33

def load_current_resource
  @current_resource = Chef::Resource::Service.new(@new_resource.name)
  @current_resource.service_name(@new_resource.service_name)
  unless ::File.exists? "/bin/svcs"
    raise Chef::Exceptions::Service, "/bin/svcs does not exist!"
  end
  @status = service_status.enabled
  @current_resource
end

#reload_serviceObject



56
57
58
# File 'lib/chef/provider/service/solaris.rb', line 56

def reload_service
  run_command(:command => "#{@init_command} refresh #{@new_resource.service_name}")
end

#restart_serviceObject



60
61
62
63
# File 'lib/chef/provider/service/solaris.rb', line 60

def restart_service
  disable_service
  return enable_service
end

#service_statusObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/chef/provider/service/solaris.rb', line 65

def service_status
  status = popen4("#{@status_command} #{@current_resource.service_name}") do |pid, stdin, stdout, stderr|
    stdout.each do |line|
      case line
      when /state\s+online/
        @current_resource.enabled(true)
        @current_resource.running(true)
      end
    end
  end
  unless @current_resource.enabled
    @current_resource.enabled(false)
    @current_resource.running(false)
  end
  @current_resource
end