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,
lib/chef/provider/service/invokercd.rb

Direct Known Subclasses

Simple, Solaris, Windows

Defined Under Namespace

Classes: Arch, Debian, Freebsd, Gentoo, Init, Insserv, Invokercd, Redhat, Simple, Solaris, Systemd, 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, #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



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

def action_disable
  if @current_resource.enabled
    if disable_service
      @new_resource.updated_by_last_action(true)
      Chef::Log.info("#{@new_resource} disabled")
    end
  else
    Chef::Log.debug("#{@new_resource} already disabled - nothing to do")
  end
end

#action_enableObject



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

def action_enable
  if @current_resource.enabled
    Chef::Log.debug("#{@new_resource} already enabled - nothing to do")
  else
    if enable_service
      @new_resource.updated_by_last_action(true)
      Chef::Log.info("#{@new_resource} enabled")
    end
  end
end

#action_reloadObject



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/chef/provider/service.rb', line 84

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
    if reload_service
      @new_resource.updated_by_last_action(true)
      Chef::Log.info("#{@new_resource} reloaded")
    end
  end
end

#action_restartObject



77
78
79
80
81
82
# File 'lib/chef/provider/service.rb', line 77

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

#action_startObject



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

def action_start
  unless @current_resource.running
    if start_service
      @new_resource.updated_by_last_action(true)
      Chef::Log.info("#{@new_resource} started")
    end
  else
    Chef::Log.debug("#{@new_resource} already running - nothing to do")
  end 
end

#action_stopObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/chef/provider/service.rb', line 66

def action_stop
  if @current_resource.running
    if stop_service
      @new_resource.updated_by_last_action(true)
      Chef::Log.info("#{@new_resource} stopped")
    end
  else
    Chef::Log.debug("#{@new_resource} already stopped - nothing to do")
  end 
end

#disable_serviceObject



100
101
102
# File 'lib/chef/provider/service.rb', line 100

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

#enable_serviceObject



96
97
98
# File 'lib/chef/provider/service.rb', line 96

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

#reload_serviceObject



116
117
118
# File 'lib/chef/provider/service.rb', line 116

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

#restart_serviceObject



112
113
114
# File 'lib/chef/provider/service.rb', line 112

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

#start_serviceObject



104
105
106
# File 'lib/chef/provider/service.rb', line 104

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

#stop_serviceObject



108
109
110
# File 'lib/chef/provider/service.rb', line 108

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