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 collapse

Attributes inherited from Chef::Provider

#action, #cookbook_name, #current_resource, #new_resource, #recipe_name, #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, #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

#build_resource, #declare_resource, #describe_self_for_error, #evaluate_resource_definition, #has_resource_definition?, #have_resource_class_for?, #method_missing, #resource_class_for

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.



31
32
33
34
35
36
# File 'lib/chef/provider/service/solaris.rb', line 31

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::DSL::Recipe

Instance Attribute Details

#maintenanceObject (readonly)

Returns the value of attribute maintenance.



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

def maintenance
  @maintenance
end

Instance Method Details

#disable_serviceObject Also known as: stop_service



54
55
56
# File 'lib/chef/provider/service/solaris.rb', line 54

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

#enable_serviceObject Also known as: start_service



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

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

#load_current_resourceObject



39
40
41
42
43
44
45
46
47
# File 'lib/chef/provider/service/solaris.rb', line 39

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



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

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

#restart_serviceObject



65
66
67
68
69
# File 'lib/chef/provider/service/solaris.rb', line 65

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

#service_statusObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/chef/provider/service/solaris.rb', line 71

def service_status
  status = shell_out!("#{@status_command} #{@current_resource.service_name}", :returns => [0, 1])
  status.stdout.each_line do |line|
    case line
    when /state\s+online/
      @current_resource.enabled(true)
      @current_resource.running(true)
    when /state\s+maintenance/
      @maintenance = true
    end
  end
  unless @current_resource.enabled
    @current_resource.enabled(false)
    @current_resource.running(false)
  end
  @current_resource
end