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

Direct Known Subclasses

Simple

Defined Under Namespace

Classes: Debian, Freebsd, Gentoo, Init, Redhat, Simple

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #node

Instance Method Summary collapse

Methods included from Mixin::Command

handle_command_failures, not_if, only_if, output_of_command, popen4, run_command, run_command_with_systems_locale

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #load_current_resource

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string

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(node, new_resource, collection = nil, definitions = nil, cookbook_loader = nil) ⇒ Service

Returns a new instance of Service.



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

def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
  super(node, new_resource, collection, definitions, cookbook_loader)
  @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



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

def action_disable
  if @current_resource.enabled
    Chef::Log.debug("#{@new_resource}: attempting to disable")
    status = disable_service()
    if status
      @new_resource.updated = 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
44
# File 'lib/chef/provider/service.rb', line 33

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

#action_reloadObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/chef/provider/service.rb', line 94

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

#action_restartObject



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

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

#action_startObject



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

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

#action_stopObject



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

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

#disable_service(name) ⇒ Object



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

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

#enable_service(name) ⇒ Object



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

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

#reload_service(name) ⇒ Object



129
130
131
# File 'lib/chef/provider/service.rb', line 129

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

#restart_service(name) ⇒ Object



125
126
127
# File 'lib/chef/provider/service.rb', line 125

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

#start_service(name) ⇒ Object



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

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

#stop_service(name) ⇒ Object



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

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