Class: Chef::Provider::Service

Inherits:
Chef::Provider show all
Includes:
Mixin::Command
Defined in:
lib/chef/provider/service.rb,
lib/chef/provider/service/init.rb,
lib/chef/provider/service/debian.rb,
lib/chef/provider/service/redhat.rb,
lib/chef/provider/service/simple.rb,
lib/chef/provider/service/freebsd.rb,
lib/chef/provider/service/insserv.rb,
lib/chef/provider/service/solaris.rb,
lib/chef/provider/service/upstart.rb

Direct Known Subclasses

Simple, Solaris

Defined Under Namespace

Classes: Arch, Debian, Freebsd, Gentoo, Init, Insserv, Redhat, Simple, Solaris, Upstart, Windows

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #run_context

Instance Method Summary collapse

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, #load_current_resource, #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) ⇒ Service

Returns a new instance of Service.



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

def initialize(new_resource, run_context)
  super
  @enabled = nil
end

Dynamic Method Handling

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

Instance Method Details

#action_disableObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chef/provider/service.rb', line 45

def action_disable
  if @current_resource.enabled
    Chef::Log.debug("#{@new_resource}: attempting to disable")
    if disable_service
      @new_resource.updated_by_last_action(true)
      Chef::Log.info("#{@new_resource}: disabled successfully")
    end
  else
    Chef::Log.debug("#{@new_resource}: not disabling, already disabled")
  end
end

#action_enableObject



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

def action_enable
  if @current_resource.enabled
    Chef::Log.debug("#{@new_resource}: not enabling, already enabled")
  else
    Chef::Log.debug("#{@new_resource}: attempting to enable")
    if enable_service
      @new_resource.updated_by_last_action(true)
      Chef::Log.info("#{@new_resource}: enabled successfully")
    end
  end
end

#action_reloadObject



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/chef/provider/service.rb', line 89

def action_reload
  unless (@new_resource.supports[:reload] || @new_resource.reload_command)
    raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :reload"
  end
  if @current_resource.running
    Chef::Log.debug("#{@new_resource}: attempting to reload")
    if reload_service
      @new_resource.updated_by_last_action(true)
      Chef::Log.info("#{@new_resource}: reloaded successfully")
    end
  end
end

#action_restartObject



81
82
83
84
85
86
87
# File 'lib/chef/provider/service.rb', line 81

def action_restart
  Chef::Log.debug("#{@new_resource}: attempting to restart")
  if restart_service
    @new_resource.updated_by_last_action(true)
    Chef::Log.info("#{@new_resource}: restarted successfully")
  end
end

#action_startObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/chef/provider/service.rb', line 57

def action_start
  unless @current_resource.running
    Chef::Log.debug("#{@new_resource}: attempting to start")
    if start_service
      @new_resource.updated_by_last_action(true)
      Chef::Log.info("Started service #{@new_resource} successfully")
    end
  else
    Chef::Log.debug("#{@new_resource}: not starting, already running")
  end 
end

#action_stopObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/chef/provider/service.rb', line 69

def action_stop
  if @current_resource.running
    Chef::Log.debug("#{@new_resource}: attempting to stop")
    if stop_service
      @new_resource.updated_by_last_action(true)
      Chef::Log.info("#{@new_resource}: stopped successfully")
    end
  else
    Chef::Log.debug("#{@new_resource}: not stopping, already stopped")
  end 
end

#disable_serviceObject



106
107
108
# File 'lib/chef/provider/service.rb', line 106

def disable_service
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :disable"
end

#enable_serviceObject



102
103
104
# File 'lib/chef/provider/service.rb', line 102

def enable_service
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :enable"
end

#reload_serviceObject



122
123
124
# File 'lib/chef/provider/service.rb', line 122

def reload_service
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :restart"
end

#restart_serviceObject



118
119
120
# File 'lib/chef/provider/service.rb', line 118

def restart_service
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :restart"
end

#start_serviceObject



110
111
112
# File 'lib/chef/provider/service.rb', line 110

def start_service
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :start"
end

#stop_serviceObject



114
115
116
# File 'lib/chef/provider/service.rb', line 114

def stop_service
  raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :stop"
end