diff options
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/type/service.rb | 4 | ||||
-rwxr-xr-x | lib/puppet/type/service/smf.rb | 52 |
2 files changed, 43 insertions, 13 deletions
diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb index 76bc8adb1..21f258f0b 100644 --- a/lib/puppet/type/service.rb +++ b/lib/puppet/type/service.rb @@ -70,7 +70,7 @@ module Puppet should = :running else self.warning "%s: interpreting '%s' as false" % - [self.class,should] + [self.class,should.inspect] should = 0 end self.debug "Service should is %s" % should @@ -87,8 +87,10 @@ module Puppet case self.should when :running @parent.start + self.info "started" return :service_started when :stopped + self.info "stopped" @parent.stop return :service_stopped else diff --git a/lib/puppet/type/service/smf.rb b/lib/puppet/type/service/smf.rb index f16eb422a..b98e47eb4 100755 --- a/lib/puppet/type/service/smf.rb +++ b/lib/puppet/type/service/smf.rb @@ -2,27 +2,55 @@ # somewhat obvious. Puppet.type(:service).newsvctype(:smf) do def restartcmd + "svcadm restart %s" % self.name end - # The start command is just the init scriptwith 'start'. def startcmd - self.initscript + " start" + "svcadm enable %s" % self.name end - # If it was specified that the init script has a 'status' command, then - # we just return that; otherwise, we return false, which causes it to - # fallback to other mechanisms. - def statuscmd - if self[:hasstatus] - return self.initscript + " status" - else - return false + def status + if self[:status] + super + return + end + %x{/usr/bin/svcs -l #{self.name} 2>/dev/null}.split("\n").each { |line| + var = nil + value = nil + if line =~ /^(\w+)\s+(.+)/ + var = $1 + value = $2 + else + Puppet.err "Could not match %s" % line.inspect + end + case var + when "state": + case value + when "online": + #self.warning "matched running %s" % line.inspect + return :running + when "offline", "disabled": + #self.warning "matched stopped %s" % line.inspect + return :stopped + when "legacy_run": + raise Puppet::Error, + "Cannot manage legacy services through SMF" + else + raise Puppet::Error, + "Unmanageable state %s on service %s" % + [value, self.name] + end + end + } + + if $? != 0 + raise Puppet::Error, + "Could not get status on service %s" % self.name end end - # The stop command is just the init script with 'stop'. def stopcmd - self.initscript + " stop" + "svcadm disable %s" % self.name end end |