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

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

Constant Summary

Constants included from Mixin::ShellOut

Mixin::ShellOut::DEPRECATED_OPTIONS

Instance Attribute Summary

Attributes inherited from Chef::Provider

#action, #current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods included from Mixin::ShellOut

#run_command_compatible_options, #shell_out, #shell_out!

Methods inherited from Chef::Provider::Service

#action_disable, #action_enable, #action_reload, #action_restart, #action_start, #action_stop, #define_resource_requirements, #load_new_resource_state, #shared_resource_requirements, #whyrun_supported?

Methods included from Mixin::Command

#chdir_or_tmpdir, #handle_command_failures, #output_of_command, #run_command, #run_command_and_return_stdout_stderr, #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, #cleanup_after_converge, #converge_by, #cookbook_name, #define_resource_requirements, #events, #node, #process_resource_requirements, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, #whyrun_mode?, #whyrun_supported?

Methods included from DSL::Recipe

#method_missing

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Constructor Details

#initialize(new_resource, run_context = nil) ⇒ Solaris

Returns a new instance of Solaris.



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

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::DSL::Recipe

Instance Method Details

#disable_serviceObject Also known as: stop_service



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

def disable_service
  shell_out!("#{default_init_command} disable -s #{@new_resource.service_name}")
end

#enable_serviceObject Also known as: start_service



46
47
48
# File 'lib/chef/provider/service/solaris.rb', line 46

def enable_service
  shell_out!("#{default_init_command} enable -s #{@new_resource.service_name}")
end

#load_current_resourceObject



36
37
38
39
40
41
42
43
44
# File 'lib/chef/provider/service/solaris.rb', line 36

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



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

def reload_service
  shell_out!("#{default_init_command} refresh #{@new_resource.service_name}")
end

#restart_serviceObject



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

def restart_service
  ## svcadm restart doesn't supports sync(-s) option
  disable_service
  return enable_service
end

#service_statusObject



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

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