summaryrefslogtreecommitdiffstats
path: root/lib/puppet.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-02-02 17:19:07 -0600
committerLuke Kanies <luke@madstop.com>2009-02-06 18:08:43 -0600
commitc0fcb2137e66af8ba60a959faa221034c6832b69 (patch)
tree10f62605333979ea64445dca5d4d66d58237de97 /lib/puppet.rb
parent700e823f7c33eb3c5b4d9e467742fd24f63bbeef (diff)
downloadpuppet-c0fcb2137e66af8ba60a959faa221034c6832b69.tar.gz
puppet-c0fcb2137e66af8ba60a959faa221034c6832b69.tar.xz
puppet-c0fcb2137e66af8ba60a959faa221034c6832b69.zip
Creating and using a new Puppet::Daemon class
This replaces the short-lived EventManager class, all of the service- and timer-related code in puppet.rb, and moves code from agent.rb, server.rb, and other places into one class responsible for starting, stopping, pids, and more. The Daemon module is no longer in existence, so it's been removed from the classes that were using it. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet.rb')
-rw-r--r--lib/puppet.rb204
1 files changed, 0 insertions, 204 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb
index dad8936d2..c2d108d7f 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -8,7 +8,6 @@ end
require 'singleton'
require 'facter'
require 'puppet/error'
-require 'puppet/external/event-loop'
require 'puppet/util'
require 'puppet/util/log'
require 'puppet/util/autoload'
@@ -32,14 +31,7 @@ module Puppet
end
class << self
- # So we can monitor signals and such.
- include SignalObserver
-
include Puppet::Util
-
- # To keep a copy of arguments. Set within Config#addargs, because I'm
- # lazy.
- attr_accessor :args
attr_reader :features
attr_writer :name
end
@@ -117,7 +109,6 @@ module Puppet
# Load all of the configuration parameters.
require 'puppet/defaults'
-
def self.genmanifest
if Puppet[:genmanifest]
puts Puppet.settings.to_manifest
@@ -125,42 +116,6 @@ module Puppet
end
end
- # Run all threads to their ends
- def self.join
- defined? @threads and @threads.each do |t| t.join end
- end
-
- # Create a new service that we're supposed to run
- def self.newservice(service)
- @services ||= []
-
- @services << service
- end
-
- def self.newthread(&block)
- @threads ||= []
-
- @threads << Thread.new do
- yield
- end
- end
-
- def self.newtimer(hash, &block)
- timer = nil
- threadlock(:timers) do
- @timers ||= []
- timer = EventLoop::Timer.new(hash)
- @timers << timer
-
- if block_given?
- observe_signal(timer, :alarm, &block)
- end
- end
-
- # In case they need it for something else.
- timer
- end
-
# Parse the config file for this process.
def self.parse_config
if Puppet[:config] and File.exists? Puppet[:config]
@@ -169,165 +124,6 @@ module Puppet
end
end
- # Relaunch the executable.
- def self.restart
- command = $0 + " " + self.args.join(" ")
- Puppet.notice "Restarting with '%s'" % command
- Puppet.shutdown(false)
- Puppet::Util::Log.reopen
- exec(command)
- end
-
- # Trap a couple of the main signals. This should probably be handled
- # in a way that anyone else can register callbacks for traps, but, eh.
- def self.settraps
- [:INT, :TERM].each do |signal|
- trap(signal) do
- Puppet.notice "Caught #{signal}; shutting down"
- Puppet.debug "Signal caught here:"
- caller.each { |l| Puppet.debug l }
- Puppet.shutdown
- end
- end
-
- # Handle restarting.
- trap(:HUP) do
- if client = @services.find { |s| s.is_a? Puppet::Network::Client.master } and client.running?
- client.restart
- else
- Puppet.restart
- end
- end
-
- # Provide a hook for running clients where appropriate
- trap(:USR1) do
- done = 0
- Puppet.notice "Caught USR1; triggering client run"
- @services.find_all { |s| s.is_a? Puppet::Network::Client }.each do |client|
- if client.respond_to? :running?
- if client.running?
- Puppet.info "Ignoring running %s" % client.class
- else
- done += 1
- begin
- client.runnow
- rescue => detail
- Puppet.err "Could not run client: %s" % detail
- end
- end
- else
- Puppet.info "Ignoring %s; cannot test whether it is running" %
- client.class
- end
- end
-
- unless done > 0
- Puppet.notice "No clients were run"
- end
- end
-
- trap(:USR2) do
- Puppet::Util::Log.reopen
- end
- end
-
- # Shutdown our server process, meaning stop all services and all threads.
- # Optionally, exit.
- def self.shutdown(leave = true)
- Puppet.notice "Shutting down"
- # Unmonitor our timers
- defined? @timers and @timers.each do |timer|
- EventLoop.current.ignore_timer timer
- end
-
- # This seems to exit the process, although I can't find where it does
- # so. Leaving it out doesn't seem to hurt anything.
- #if EventLoop.current.running?
- # EventLoop.current.quit
- #end
-
- # Stop our services
- defined? @services and @services.each do |svc|
- next unless svc.respond_to?(:shutdown)
- begin
- timeout(20) do
- svc.shutdown
- end
- rescue TimeoutError
- Puppet.err "%s could not shut down within 20 seconds" % svc.class
- end
- end
-
- # And wait for them all to die, giving a decent amount of time
- defined? @threads and @threads.each do |thr|
- begin
- timeout(20) do
- thr.join
- end
- rescue TimeoutError
- # Just ignore this, since we can't intelligently provide a warning
- end
- end
-
- if leave
- exit(0)
- end
- end
-
- # Start all of our services and optionally our event loop, which blocks,
- # waiting for someone, somewhere, to generate events of some kind.
- def self.start(block = true)
- # Starting everything in its own thread, fwiw
- defined? @services and @services.dup.each do |svc|
- newthread do
- begin
- svc.start
- rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
- @services.delete svc
- Puppet.err "Could not start %s: %s" % [svc.class, detail]
- end
- end
- end
-
- # We need to give the services a chance to register their timers before
- # we try to start monitoring them.
- sleep 0.5
-
- unless @services.length > 0
- Puppet.notice "No remaining services; exiting"
- exit(1)
- end
-
- if defined? @timers and ! @timers.empty?
- @timers.each do |timer|
- EventLoop.current.monitor_timer timer
- end
- end
-
- if block
- EventLoop.current.run
- end
- end
-
- # Create the timer that our different objects (uh, mostly the client)
- # check.
- def self.timer
- unless defined? @timer
- #Puppet.info "Interval is %s" % Puppet[:runinterval]
- #@timer = EventLoop::Timer.new(:interval => Puppet[:runinterval])
- @timer = EventLoop::Timer.new(
- :interval => Puppet[:runinterval],
- :tolerance => 1,
- :start? => true
- )
- EventLoop.current.monitor_timer @timer
- end
- @timer
- end
-
# XXX this should all be done using puppet objects, not using
# normal mkdir
def self.recmkdir(dir,mode = 0755)