diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-10-13 22:08:34 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-10-13 22:08:34 +0000 |
commit | 66db3d89153bea5ba35ce421416773d7585ae88e (patch) | |
tree | 8bf294e7d0430f22d8d2dffc6036da38b2db6c38 /lib | |
parent | 194dab3c7af4d8e993ec8549a30773d68508a9b6 (diff) | |
download | puppet-66db3d89153bea5ba35ce421416773d7585ae88e.tar.gz puppet-66db3d89153bea5ba35ce421416773d7585ae88e.tar.xz puppet-66db3d89153bea5ba35ce421416773d7585ae88e.zip |
making service changes; it is still basically non-functional except in the degenerate case of using "init"
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@717 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/type/service.rb | 114 | ||||
-rwxr-xr-x | lib/puppet/type/service/debian.rb | 50 | ||||
-rwxr-xr-x | lib/puppet/type/service/init.rb | 6 | ||||
-rwxr-xr-x | lib/puppet/type/service/smf.rb | 78 | ||||
-rwxr-xr-x | lib/puppet/type/user.rb | 4 |
5 files changed, 140 insertions, 112 deletions
diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb index b98764f48..df3609af3 100644 --- a/lib/puppet/type/service.rb +++ b/lib/puppet/type/service.rb @@ -1,4 +1,4 @@ -# this is our main way of managing processes right now +# This is our main way of managing processes right now. # # a service is distinct from a process in that services # can only be managed through the interface of an init script @@ -13,13 +13,20 @@ module Puppet @name = :enabled def retrieve + unless @parent.respond_to?(:enabled?) + raise Puppet::Error, "Service %s does not support enabling" + end @is = @parent.enabled? end def shouldprocess(should) + @runlevel = nil case should when true: return :enabled when false: return :disabled + when /^\d+$/: + @runlevel = should + return :enabled else raise Puppet::Error, "Invalid 'enabled' value %s" % should end @@ -31,7 +38,7 @@ module Puppet unless @parent.respond_to?(:enable) raise Puppet::Error, "Service %s does not support enabling" end - @parent.enable + @parent.enable(@runlevel) return :service_enabled when :disabled unless @parent.respond_to?(:disable) @@ -102,7 +109,8 @@ module Puppet :restart, :start, :status, - :stop + :stop, + :type ] @paramdoc[:binary] = "The path to the daemon. This is only used for @@ -145,6 +153,37 @@ module Puppet attr_accessor :svctype end + # Retrieve the default type for the current platform. + def self.defaulttype + unless defined? @defsvctype + @defsvctype = nil + os = Facter["operatingsystem"].value + case os + when "Linux": + case Facter["distro"].value + when "Debian": + @defsvctype = Puppet::ServiceTypes::DebianSvc + end + when "SunOS": + release = Float(Facter["operatingsystemrelease"].value) + if release < 5.10 + @defsvctype = Puppet::ServiceTypes::InitSvc + else + @defsvctype = Puppet::ServiceTypes::SMFSvc + end + end + + unless @defsvctype + Puppet.notice "Defaulting to base service type" + @defsvctype = Puppet::ServiceTypes::BaseSvc + end + end + + Puppet.err @defsvctype + + return @defsvctype + end + # Execute a command. Basically just makes sure it exits with a 0 # code. def execute(type, cmd) @@ -163,6 +202,9 @@ module Puppet "Either a stop command or a pattern must be specified" end ps = Facter["ps"].value + unless ps and ps != "" + raise Puppet::Error, "You must upgrade Facter" + end regex = Regexp.new(self[:pattern]) IO.popen(ps) { |table| table.each { |line| @@ -176,14 +218,44 @@ module Puppet return nil end + # Initialize the service. This is basically responsible for merging + # in the right module. def initialize(hash) + # We have to extend the object before we call 'super', so that + # the parameter methods are called correctly. + type = hash[:type] || + hash["type"] || + self.class.defaulttype + + if type.is_a?(String) + type = type2module(type) + end + + # Extend the object with the service type + self.extend(type) + super + # and then see if it needs to be checked if self.respond_to?(:configchk) self.configchk end end + # Retrieve the service type. + def type2module(type) + case type + when "smf": + return Puppet::ServiceTypes::SMFSvc + when "init": + return Puppet::ServiceTypes::InitSvc + when "launchd": + #return Puppet::ServiceTypes::LaunchDSvc + else + raise Puppet::Error, "Invalid service type %s" % type + end + end + # Basically just a synonym for restarting. Used to respond # to events. def refresh @@ -257,37 +329,15 @@ module Puppet return true end end - - # Now load any overlay modules to provide additional functionality - os = Facter["operatingsystem"].value - case os - when "Linux": - case Facter["distro"].value - when "Debian": - require 'puppet/type/service/init' - @svctype = Puppet::ServiceTypes::InitSvc - - # and then require stupid debian-specific stuff - require 'puppet/type/service/debian' - include Puppet::ServiceTypes::DebianSvc - end - when "SunOS": - release = Float(Facter["operatingsystemrelease"].value) - if release < 5.10 - require 'puppet/type/service/init' - @svctype = Puppet::ServiceTypes::InitSvc - else - require 'puppet/type/service/smf' - @svctype = Puppet::ServiceTypes::SMFSvc - end - end - unless defined? @svctype - require 'puppet/type/service/base' - @svctype = Puppet::ServiceTypes::BaseSvc - end - include @svctype end end end +# Load all of the different service types. We could probably get away with +# loading less here, but it's not a big deal to do so. +require 'puppet/type/service/base' +require 'puppet/type/service/init' +require 'puppet/type/service/debian' +require 'puppet/type/service/smf' + # $Id$ diff --git a/lib/puppet/type/service/debian.rb b/lib/puppet/type/service/debian.rb new file mode 100755 index 000000000..aa7303d18 --- /dev/null +++ b/lib/puppet/type/service/debian.rb @@ -0,0 +1,50 @@ +require 'puppet/type/service/init' + +# Manage debian services. Start/stop is the same as InitSvc, but enable/disable +# is special. +module Puppet + module ServiceTypes + module DebianSvc + include Puppet::ServiceTypes::InitSvc + + # Remove the symlinks + def disable + output = %x{update-rc.d -f #{self.name} remove 2>/dev/null} + + unless $? == 0 + raise Puppet::Error, "Could not disable %s: %s" % + [self.name, output] + end + end + + def enabled? + output = %x{update-rc.d -n -f #{self.name} remove 2>/dev/null} + unless $? == 0 + raise Puppet::Error, "Could not check %s: %s" % + [self.name, output] + end + + # If it's enabled, then it will print output showing removal of + # links. + if output =~ /etc\/rc\d.d/ + return true + else + return false + end + end + + def enable(runlevel) + if runlevel + raise Puppet::Error, "Specification of runlevels is not supported" + else + output = %x{update-rc.d #{self.name} defaults 2>/dev/null} + end + + unless $? == 0 + raise Puppet::Error, "Could not check %s: %s" % + [self.name, output] + end + end + end + end +end diff --git a/lib/puppet/type/service/init.rb b/lib/puppet/type/service/init.rb index 42fdfd7f7..49702161c 100755 --- a/lib/puppet/type/service/init.rb +++ b/lib/puppet/type/service/init.rb @@ -9,6 +9,7 @@ module Puppet end unless @searchpaths.length > 0 if init = self.defaultinit + Puppet.notice "Adding default init" @searchpaths << init else Puppet.notice "No default init for %s" % @@ -88,11 +89,14 @@ module Puppet } end - # Enable a service, to it's started at boot time. This basically + # Enable a service, so it's started at boot time. This basically # just creates links in the RC directories, which means that, well, # we need to know where the rc directories are. # FIXME This should probably be a state or something, and # it should actually create use Symlink objects... + # At this point, people should just link objects for enabling, + # if they're running on a system that doesn't have a tool to + # manage init script links. #def enable #end diff --git a/lib/puppet/type/service/smf.rb b/lib/puppet/type/service/smf.rb index 4202708c8..9f59c9d53 100755 --- a/lib/puppet/type/service/smf.rb +++ b/lib/puppet/type/service/smf.rb @@ -1,83 +1,7 @@ module Puppet module ServiceTypes module SMFSvc - # Mark that our init script supports 'status' commands. - def hasstatus=(value) - case value - when true, "true": @parameters[:hasstatus] = true - when false, "false": @parameters[:hasstatus] = false - else - raise Puppet::Error, "Invalid 'hasstatus' value %s" % - value.inspect - 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 - - Puppet.debug "Executing '%s %s' as initcmd for '%s'" % - [script,cmd,self] - - rvalue = Kernel.system("%s %s" % - [script,cmd]) - - Puppet.debug "'%s' ran with exit status '%s'" % - [cmd,rvalue] - - - rvalue - end - - # Where is our init script? - def initscript - if defined? @initscript - return @initscript - else - @initscript = self.search(self.name) - end - end - - # Store the search path for init scripts. This will generally not - # be called. - def parampath=(ary) - unless ary.is_a?(Array) - ary = [ary] - end - @parameters[:path] = ary - @searchpaths = ary.find_all { |dir| - File.directory?(dir) - } - end - - # Enable a service, to it's started at boot time. This basically - # just creates links in the RC directories, which means that, well, - # we need to know where the rc directories are. - # FIXME This should probably be a state or something, and - # it should actually create use Symlink objects... - #def enable - #end - - #def disable - #end - - def search(name) - @searchpaths.each { |path| - fqname = File.join(path,name) - begin - stat = File.stat(fqname) - rescue - # should probably rescue specific errors... - Puppet.debug("Could not find %s in %s" % [name,path]) - next - end - - # if we've gotten this far, we found a valid script - return fqname - } - raise Puppet::Error, "Could not find init script for '%s'" % name + def restartcmd end # The start command is just the init scriptwith 'start'. diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb index 9db7173a7..10bd6b056 100755 --- a/lib/puppet/type/user.rb +++ b/lib/puppet/type/user.rb @@ -1,5 +1,3 @@ -# $Id$ - require 'etc' require 'facter' require 'puppet/type/state' @@ -284,3 +282,5 @@ module Puppet end end end + +# $Id$ |