diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-06-27 05:15:51 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-06-27 05:15:51 +0000 |
| commit | bdd1761c561ed80003a62068157c4aaf32c83a73 (patch) | |
| tree | 420ef633d02ba63fd26631aa998ec5e10e8ea059 /lib/puppet/daemon.rb | |
| parent | 73a4bcc8357b13bb45ae0c5ccdda35b8563f1971 (diff) | |
| download | puppet-bdd1761c561ed80003a62068157c4aaf32c83a73.tar.gz puppet-bdd1761c561ed80003a62068157c4aaf32c83a73.tar.xz puppet-bdd1761c561ed80003a62068157c4aaf32c83a73.zip | |
Largely refactored how log destinations are handled, although it is not exposed externally. Most of this work is related to handling a large number of small problems related to threading.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1315 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/daemon.rb')
| -rwxr-xr-x | lib/puppet/daemon.rb | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/lib/puppet/daemon.rb b/lib/puppet/daemon.rb index edcd5f50d..13ae3f6a2 100755 --- a/lib/puppet/daemon.rb +++ b/lib/puppet/daemon.rb @@ -6,6 +6,8 @@ module Puppet # A module that handles operations common to all daemons. This is included # into the Server and Client base classes. module Daemon + include Puppet::Util + Puppet.config.setdefaults(:puppet, :setpidfile => [true, "Whether to store a PID file for the daemon."]) def daemonname @@ -204,12 +206,14 @@ module Puppet # Remove the pid file def rmpidfile - if defined? @pidfile and @pidfile and FileTest.exists?(@pidfile) - begin - File.unlink(@pidfile) - rescue => detail - Puppet.err "Could not remove PID file %s: %s" % - [@pidfile, detail] + threadlock(:pidfile) do + if defined? @pidfile and @pidfile and FileTest.exists?(@pidfile) + begin + File.unlink(@pidfile) + rescue => detail + Puppet.err "Could not remove PID file %s: %s" % + [@pidfile, detail] + end end end end @@ -217,25 +221,27 @@ module Puppet # Create the pid file. def setpidfile return unless Puppet[:setpidfile] - Puppet.config.use(:puppet) - @pidfile = self.pidfile - if FileTest.exists?(@pidfile) - if defined? $setpidfile - return - else - raise Puppet::Error, "A PID file already exists for #{Puppet.name} -at #{@pidfile}. Not starting." + threadlock(:pidfile) do + Puppet.config.use(:puppet) + @pidfile = self.pidfile + if FileTest.exists?(@pidfile) + if defined? $setpidfile + return + else + raise Puppet::Error, "A PID file already exists for #{Puppet.name} + at #{@pidfile}. Not starting." + end end - end - Puppet.info "Creating PID file to %s" % @pidfile - begin - File.open(@pidfile, "w") { |f| f.puts $$ } - rescue => detail - Puppet.err "Could not create PID file: %s" % detail - exit(74) + Puppet.info "Creating PID file to %s" % @pidfile + begin + File.open(@pidfile, "w") { |f| f.puts $$ } + rescue => detail + Puppet.err "Could not create PID file: %s" % detail + exit(74) + end + $setpidfile = true end - $setpidfile = true end # Shut down our server @@ -243,8 +249,10 @@ at #{@pidfile}. Not starting." # Remove our pid file rmpidfile() - # And close all logs - Puppet::Log.close + # And close all logs except the console. + Puppet::Log.destinations.reject { |d| d == :console }.each do |dest| + Puppet::Log.close(dest) + end super end |
