diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-05 23:46:32 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-05 23:46:32 +0000 |
commit | 2113eed0137630836b3de3e2a8bc17b6cb7198e8 (patch) | |
tree | 7c7af351497339aa4640fc6fe2debe5a7d8f5023 | |
parent | fcc5bae22cb2a0286975cfc0bcab52a2a7f7973d (diff) | |
download | puppet-2113eed0137630836b3de3e2a8bc17b6cb7198e8.tar.gz puppet-2113eed0137630836b3de3e2a8bc17b6cb7198e8.tar.xz puppet-2113eed0137630836b3de3e2a8bc17b6cb7198e8.zip |
Adding hasrestart parameter to services
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1569 980ebf18-57e1-0310-9a29-db15c13687c0
-rwxr-xr-x | examples/root/etc/init.d/sleeper | 6 | ||||
-rwxr-xr-x | lib/puppet/provider/service/init.rb | 28 | ||||
-rw-r--r-- | lib/puppet/type/service.rb | 6 | ||||
-rw-r--r-- | test/types/service.rb | 4 |
4 files changed, 24 insertions, 20 deletions
diff --git a/examples/root/etc/init.d/sleeper b/examples/root/etc/init.d/sleeper index a4e28a2fb..6da5eae32 100755 --- a/examples/root/etc/init.d/sleeper +++ b/examples/root/etc/init.d/sleeper @@ -31,6 +31,12 @@ function stop fi } +function restart +{ + stop + start +} + function status { #if [ -n `which pgrep` ]; then diff --git a/lib/puppet/provider/service/init.rb b/lib/puppet/provider/service/init.rb index 76cac2763..90f7c26a7 100755 --- a/lib/puppet/provider/service/init.rb +++ b/lib/puppet/provider/service/init.rb @@ -81,25 +81,6 @@ Puppet::Type.type(:service).provide :init, :parent => :base do end end - # it'd be nice if i didn't throw the output away... - # this command returns true if the exit code is 0, and returns - # false otherwise - def initcmd(cmd) - script = self.initscript - - self.debug "Executing '%s %s' as initcmd for '%s'" % - [script,cmd,self] - - rvalue = Kernel.system("%s %s" % - [script,cmd]) - - self.debug "'%s' ran with exit status '%s'" % - [cmd,rvalue] - - - rvalue - end - # Where is our init script? def initscript if defined? @initscript @@ -109,6 +90,15 @@ Puppet::Type.type(:service).provide :init, :parent => :base do end end + def restart + if @model[:hasrestart] == :true + command = self.initscript + " restart" + self.execute("restart", command) + else + super + end + end + def search(name) @model[:path].each { |path| fqname = File.join(path,name) diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb index e52de1f05..734bff50f 100644 --- a/lib/puppet/type/service.rb +++ b/lib/puppet/type/service.rb @@ -251,6 +251,12 @@ module Puppet desc "Specify a *stop* command manually." end + newparam :hasrestart do + desc "Specify that an init script has a ``restart`` option. Otherwise, + the init script's ``stop`` and ``start`` methods are used." + newvalues(:true, :false) + end + # Retrieve the default type for the current platform. def self.disableddefaulttype unless defined? @defsvctype diff --git a/test/types/service.rb b/test/types/service.rb index e1d2629a2..c6f530dc7 100644 --- a/test/types/service.rb +++ b/test/types/service.rb @@ -16,6 +16,7 @@ end if $skipsvcs puts "Skipping service testing on %s" % Facter["operatingsystem"].value else + puts "wtf?" #class TestInitService < Test::Unit::TestCase class TestInitService include TestPuppet @@ -47,6 +48,7 @@ class TestInitService hash[:path] = File.join($puppetbase,"examples/root/etc/init.d") hash[:ensure] = true hash[:hasstatus] = true + hash[:hasrestart] = true #hash[:type] = "init" assert_nothing_raised() { return Puppet.type(:service).create(hash) @@ -133,7 +135,7 @@ class TestLocalService < Test::Unit::TestCase return {"smtp" => {}, "xfs" => {}} end when "debian": - return {"hddtemp" => {}} + return {"hddtemp" => {:hasrestart => true}} when "centos": return {"cups" => {:hasstatus => true}} when "redhat": |