summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorSeth Chisamore <schisamo@opscode.com>2012-11-13 14:05:57 -0500
committerSeth Chisamore <schisamo@opscode.com>2012-11-13 17:27:31 -0500
commit6317bf5f07f70b8ec70ad254a5b8b3aca9b6bbe7 (patch)
treec6c5f52d1a46e9dc0c0ea4846bb030db6a59c4eb /lib/chef
parentea28e343db64d9dbee57707e81e19342c2493365 (diff)
downloadchef-6317bf5f07f70b8ec70ad254a5b8b3aca9b6bbe7.tar.gz
[CHEF-3603] add init_command attribute to service resource
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/provider/service.rb10
-rw-r--r--lib/chef/provider/service/init.rb14
-rw-r--r--lib/chef/provider/service/simple.rb2
-rw-r--r--lib/chef/provider/service/solaris.rb6
-rw-r--r--lib/chef/resource/service.rb16
5 files changed, 37 insertions, 11 deletions
diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb
index decca7fd7c..27af1ac970 100644
--- a/lib/chef/provider/service.rb
+++ b/lib/chef/provider/service.rb
@@ -153,6 +153,16 @@ class Chef
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :restart"
end
+ protected
+
+ def default_init_command
+ if @new_resource.init_command
+ @new_resource.init_command
+ elsif self.instance_variable_defined?(:@init_command)
+ @init_command
+ end
+ end
+
end
end
end
diff --git a/lib/chef/provider/service/init.rb b/lib/chef/provider/service/init.rb
index ab843d764d..2dd03679c5 100644
--- a/lib/chef/provider/service/init.rb
+++ b/lib/chef/provider/service/init.rb
@@ -37,9 +37,9 @@ class Chef
# do not call super here, inherit only shared_requirements
shared_resource_requirements
requirements.assert(:start, :stop, :restart, :reload) do |a|
- a.assertion { ::File.exist?(@init_command) }
- a.failure_message(Chef::Exceptions::Service, "#{@init_command} does not exist!")
- a.whyrun("Init script '#{@init_command}' doesn't exist, assuming a prior action would have created it.") do
+ a.assertion { ::File.exist?(default_init_command) }
+ a.failure_message(Chef::Exceptions::Service, "#{default_init_command} does not exist!")
+ a.whyrun("Init script '#{default_init_command}' doesn't exist, assuming a prior action would have created it.") do
# blindly assume that the service exists but is stopped in why run mode:
@status_load_success = false
end
@@ -50,7 +50,7 @@ class Chef
if @new_resource.start_command
super
else
- shell_out!("#{@init_command} start")
+ shell_out!("#{default_init_command} start")
end
end
@@ -58,7 +58,7 @@ class Chef
if @new_resource.stop_command
super
else
- shell_out!("#{@init_command} stop")
+ shell_out!("#{default_init_command} stop")
end
end
@@ -66,7 +66,7 @@ class Chef
if @new_resource.restart_command
super
elsif @new_resource.supports[:restart]
- shell_out!("#{@init_command} restart")
+ shell_out!("#{default_init_command} restart")
else
stop_service
sleep 1
@@ -78,7 +78,7 @@ class Chef
if @new_resource.reload_command
super
elsif @new_resource.supports[:reload]
- shell_out!("#{@init_command} reload")
+ shell_out!("#{default_init_command} reload")
end
end
end
diff --git a/lib/chef/provider/service/simple.rb b/lib/chef/provider/service/simple.rb
index 670c62d480..bcb85230d0 100644
--- a/lib/chef/provider/service/simple.rb
+++ b/lib/chef/provider/service/simple.rb
@@ -128,7 +128,7 @@ class Chef
elsif @new_resource.supports[:status]
Chef::Log.debug("#{@new_resource} supports status, running")
begin
- if shell_out("#{@init_command} status").exitstatus == 0
+ if shell_out("#{default_init_command} status").exitstatus == 0
@current_resource.running true
Chef::Log.debug("#{@new_resource} is running")
end
diff --git a/lib/chef/provider/service/solaris.rb b/lib/chef/provider/service/solaris.rb
index 8e131590e8..364b6f6542 100644
--- a/lib/chef/provider/service/solaris.rb
+++ b/lib/chef/provider/service/solaris.rb
@@ -42,12 +42,12 @@ class Chef
end
def enable_service
- run_command(:command => "#{@init_command} enable #{@new_resource.service_name}")
+ run_command(:command => "#{default_init_command} enable #{@new_resource.service_name}")
return service_status.enabled
end
def disable_service
- run_command(:command => "#{@init_command} disable #{@new_resource.service_name}")
+ run_command(:command => "#{default_init_command} disable #{@new_resource.service_name}")
return service_status.enabled
end
@@ -55,7 +55,7 @@ class Chef
alias_method :start_service, :enable_service
def reload_service
- run_command(:command => "#{@init_command} refresh #{@new_resource.service_name}")
+ run_command(:command => "#{default_init_command} refresh #{@new_resource.service_name}")
end
def restart_service
diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb
index 3ace5cbec3..8ef1aeb475 100644
--- a/lib/chef/resource/service.rb
+++ b/lib/chef/resource/service.rb
@@ -40,6 +40,7 @@ class Chef
@status_command = nil
@restart_command = nil
@reload_command = nil
+ @init_command = nil
@priority = nil
@action = "nothing"
@startup_type = :automatic
@@ -108,6 +109,21 @@ class Chef
)
end
+ # The path to the init script associated with the service. On many
+ # distributions this is '/etc/init.d/SERVICE_NAME' by default. In
+ # non-standard configurations setting this value will save having to
+ # specify overrides for the start_command, stop_command and
+ # restart_command attributes.
+ It may be desirable to change
+ # this path and still leverage the other default
+ def init_command(arg=nil)
+ set_or_return(
+ :init_command,
+ arg,
+ :kind_of => [ String ]
+ )
+ end
+
# if the service is enabled or not
def enabled(arg=nil)
set_or_return(