summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-03-14 20:00:20 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-03-14 20:00:20 +0000
commit73d051fa150534f32d1f8d32bea466b1aa24fab8 (patch)
treecfc24f4d782a6f6d19b5de290e142a0532e8cb53
parent5e86634910a3a4636d3d9445bd340d2469848585 (diff)
downloadpuppet-73d051fa150534f32d1f8d32bea466b1aa24fab8.tar.gz
Fixing service enable/disable on solaris 10, and fixing some problems with the tests
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1033 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/type/service.rb31
-rwxr-xr-xlib/puppet/type/service/debian.rb12
-rwxr-xr-xlib/puppet/type/service/smf.rb15
-rw-r--r--test/types/service.rb6
4 files changed, 35 insertions, 29 deletions
diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb
index 1db138c0a..af2f0a376 100644
--- a/lib/puppet/type/service.rb
+++ b/lib/puppet/type/service.rb
@@ -28,21 +28,24 @@ module Puppet
newvalue(:true) do
unless @parent.respond_to?(:enable)
- raise Puppet::Error, "Service %s does not support enabling"
+ raise Puppet::Error, "Service %s does not support enabling" %
+ self.name
end
@parent.enable
end
newvalue(:false) do
unless @parent.respond_to?(:disable)
- raise Puppet::Error, "Service %s does not support enabling"
+ raise Puppet::Error, "Service %s does not support enabling" %
+ self.name
end
@parent.disable
end
def retrieve
unless @parent.respond_to?(:enabled?)
- raise Puppet::Error, "Service %s does not support enabling"
+ raise Puppet::Error, "Service %s does not support enabling" %
+ self.name
end
@is = @parent.enabled?
end
@@ -104,20 +107,6 @@ module Puppet
aliasvalue(:false, :stopped)
aliasvalue(:true, :running)
-# munge do |should|
-# case should
-# when false,0,"0", "stopped", :stopped:
-# should = :stopped
-# when true,1,"1", :running, "running":
-# should = :running
-# else
-# self.warning "%s: interpreting '%s' as false" %
-# [self.class,should.inspect]
-# should = 0
-# end
-# return should
-# end
-
def retrieve
self.is = @parent.status
self.debug "Current status is '%s'" % self.is
@@ -128,12 +117,10 @@ module Puppet
case self.should
when :running
@parent.start
- self.info "started"
- return :service_started
+ event = :service_started
when :stopped
- self.info "stopped"
@parent.stop
- return :service_stopped
+ event = :service_stopped
else
self.debug "Not running '%s' and shouldn't be running" %
self
@@ -145,6 +132,8 @@ module Puppet
state.sync
end
end
+
+ return event
end
end
diff --git a/lib/puppet/type/service/debian.rb b/lib/puppet/type/service/debian.rb
index 3b063e814..c7996c423 100755
--- a/lib/puppet/type/service/debian.rb
+++ b/lib/puppet/type/service/debian.rb
@@ -5,7 +5,9 @@ require 'puppet/type/service/init'
Puppet.type(:service).newsvctype(:debian, :init) do
# Remove the symlinks
def disable
- output = %x{update-rc.d -f #{self[:name]} remove 2>&1}
+ cmd = %{update-rc.d -f #{self[:name]} remove 2>&1}
+ self.debug "Executing '%s'" % cmd
+ output = %x{#{cmd}}
unless $? == 0
raise Puppet::Error, "Could not disable %s: %s" %
@@ -14,7 +16,9 @@ Puppet.type(:service).newsvctype(:debian, :init) do
end
def enabled?
- output = %x{update-rc.d -n -f #{self[:name]} remove 2>&1}
+ cmd = %{update-rc.d -n -f #{self[:name]} remove 2>&1}
+ self.debug "Executing '%s'" % cmd
+ output = %x{#{cmd}}
unless $? == 0
raise Puppet::Error, "Could not check %s: %s" %
[self.name, output]
@@ -30,7 +34,9 @@ Puppet.type(:service).newsvctype(:debian, :init) do
end
def enable
- output = %x{update-rc.d #{self[:name]} defaults 2>&1}
+ cmd = %{update-rc.d #{self[:name]} defaults 2>&1}
+ self.debug "Executing '%s'" % cmd
+ output = %x{#{cmd}}
unless $? == 0
raise Puppet::Error, "Could not enable %s: %s" %
diff --git a/lib/puppet/type/service/smf.rb b/lib/puppet/type/service/smf.rb
index 71d7d3a46..3304b0bbc 100755
--- a/lib/puppet/type/service/smf.rb
+++ b/lib/puppet/type/service/smf.rb
@@ -1,11 +1,20 @@
# Solaris 10 SMF-style services.
Puppet.type(:service).newsvctype(:smf) do
def enable
- "svcadm enable %s" % self[:name]
+ self.start
end
- def dsiable
- "svcadm disable %s" % self[:name]
+ def enabled?
+ case self.status
+ when :running:
+ return :true
+ else
+ return :false
+ end
+ end
+
+ def disable
+ self.stop
end
def restartcmd
diff --git a/test/types/service.rb b/test/types/service.rb
index c53a4022a..720f38350 100644
--- a/test/types/service.rb
+++ b/test/types/service.rb
@@ -236,7 +236,6 @@ class TestLocalService < Test::Unit::TestCase
else
def test_servicestartstop
mktestsvcs.each { |svc|
- svc[:check] = :enable
startstate = nil
assert_nothing_raised("Could not get status") {
startstate = svc.status
@@ -253,6 +252,7 @@ class TestLocalService < Test::Unit::TestCase
def test_serviceenabledisable
mktestsvcs.each { |svc|
startstate = nil
+ svc[:check] = :enable
assert_nothing_raised("Could not get status") {
startstate = svc.enabled?
}
@@ -277,9 +277,10 @@ class TestLocalService < Test::Unit::TestCase
}
svc[:enable] = false
- svc[:ensure] = :running
+ svc[:ensure] = :stopped
assert_apply(svc)
+ sleep 1
svc.retrieve
assert(svc.insync?, "Service did not sync both states")
@@ -287,6 +288,7 @@ class TestLocalService < Test::Unit::TestCase
svc[:ensure] = :running
assert_apply(svc)
+ sleep 1
svc.retrieve
assert(svc.insync?, "Service did not sync both states")