diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-01-10 17:46:07 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-01-10 17:46:07 +0000 |
| commit | 45ac512054af7cb8104cfa785102b67164d2cca4 (patch) | |
| tree | 096a7f4a1e3e5719e10a02032a55f9fbdede4b52 /lib | |
| parent | 45c91e30c848011ff729505441fbf47a7f8df8fc (diff) | |
| download | puppet-45ac512054af7cb8104cfa785102b67164d2cca4.tar.gz puppet-45ac512054af7cb8104cfa785102b67164d2cca4.tar.xz puppet-45ac512054af7cb8104cfa785102b67164d2cca4.zip | |
Supporting puppetmasterd running as a non-root user, and doing some basic message cleanup
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@798 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet.rb | 15 | ||||
| -rw-r--r-- | lib/puppet/client.rb | 3 | ||||
| -rwxr-xr-x | lib/puppet/daemon.rb | 41 | ||||
| -rw-r--r-- | lib/puppet/parser/interpreter.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/server.rb | 1 | ||||
| -rw-r--r-- | lib/puppet/server/ca.rb | 5 | ||||
| -rw-r--r-- | lib/puppet/storage.rb | 33 | ||||
| -rw-r--r-- | lib/puppet/type.rb | 17 | ||||
| -rw-r--r-- | lib/puppet/type/component.rb | 2 | ||||
| -rwxr-xr-x | lib/puppet/type/pfile/checksum.rb | 4 |
10 files changed, 66 insertions, 59 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb index 1b7a8f761..932ee9e1c 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -70,6 +70,7 @@ PUPPETVERSION = '0.10.0' alias :error :err @defaults = { + :name => $0.gsub(/.+#{File::SEPARATOR}/,''), :rrddir => [:puppetvar, "rrd"], :logdir => [:puppetvar, "log"], :bucketdir => [:puppetvar, "bucket"], @@ -88,18 +89,24 @@ PUPPETVERSION = '0.10.0' # and finally the simple answers, :server => "puppet", + :user => "puppet", + :group => "puppet", :rrdgraph => false, :noop => false, :parseonly => false, :puppetport => 8139, :masterport => 8140, } - if Process.uid == 0 - @defaults[:puppetconf] = "/etc/puppet" - @defaults[:puppetvar] = "/var/puppet" - else + + # If we're running the standalone puppet process as a non-root user, + # use basedirs that are in the user's home directory. + if @defaults[:name] == "puppet" and Process.uid != 0 @defaults[:puppetconf] = File.expand_path("~/.puppet") @defaults[:puppetvar] = File.expand_path("~/.puppet/var") + else + # Else, use system-wide directories. + @defaults[:puppetconf] = "/etc/puppet" + @defaults[:puppetvar] = "/var/puppet" end def self.clear diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb index 80b9fe30f..c58f33ec3 100644 --- a/lib/puppet/client.rb +++ b/lib/puppet/client.rb @@ -100,7 +100,8 @@ module Puppet hash[:Path] ||= "/RPC2" hash[:Server] ||= "localhost" hash[:Port] ||= Puppet[:masterport] - Puppet.debug "Creating client for %s" % hash[:Server] + Puppet.info "Starting Puppet client version %s for %s" % + [Puppet.version, hash[:Server]] @puppetserver = hash[:Server] diff --git a/lib/puppet/daemon.rb b/lib/puppet/daemon.rb index c69e635b4..68b6ff3d9 100755 --- a/lib/puppet/daemon.rb +++ b/lib/puppet/daemon.rb @@ -30,24 +30,7 @@ module Puppet # :nodoc: exit(12) end - name = $0.gsub(/.+#{File::SEPARATOR}/,'') - @pidfile = File.join(Puppet[:puppetvar], name + ".pid") - if FileTest.exists?(@pidfile) - Puppet.info "Deleting old pid file" - begin - File.unlink(@pidfile) - rescue Errno::EACCES - Puppet.err "Could not delete old PID file; cannot create new one" - return - end - end - - begin - File.open(@pidfile, "w") { |f| f.puts $$ } - rescue => detail - Puppet.err "Could not create PID file: %s" % detail - end - Puppet.info "pid file is %s" % @pidfile + setpidfile() end def fqdn @@ -186,6 +169,28 @@ module Puppet # :nodoc: return retrieved end + # Create the pid file. + def setpidfile + name = $0.gsub(/.+#{File::SEPARATOR}/,'') + @pidfile = File.join(Puppet[:puppetvar], "run", name + ".pid") + if FileTest.exists?(@pidfile) + Puppet.info "Deleting old pid file" + begin + File.unlink(@pidfile) + rescue Errno::EACCES + Puppet.err "Could not delete old PID file; cannot create new one" + return + end + end + + begin + File.open(@pidfile, "w") { |f| f.puts $$ } + rescue => detail + Puppet.err "Could not create PID file: %s" % detail + end + Puppet.info "pid file is %s" % @pidfile + end + # Shut down our server def shutdown # Remove our pid file diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 6a8a333e8..344863ec0 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -133,7 +133,9 @@ module Puppet end end - Puppet.info "Reloading files" + if defined? @parser + Puppet.info "Reloading files" + end # should i be creating a new parser each time...? @parser = Puppet::Parser::Parser.new() @parser.file = @file diff --git a/lib/puppet/server.rb b/lib/puppet/server.rb index 35a16a7f3..cd73ce885 100644 --- a/lib/puppet/server.rb +++ b/lib/puppet/server.rb @@ -28,6 +28,7 @@ module Puppet include Puppet::Daemon def initialize(hash = {}) + Puppet.info "Starting server for Puppet version %s" % Puppet.version daemonize = nil if hash.include?(:Daemonize) daemonize = hash[:Daemonize] diff --git a/lib/puppet/server/ca.rb b/lib/puppet/server/ca.rb index df2614e7c..7afd0c82c 100644 --- a/lib/puppet/server/ca.rb +++ b/lib/puppet/server/ca.rb @@ -30,7 +30,10 @@ class Server end unless FileTest.exists?(@autosign) - Puppet.info "Autosign is enabled but %s is missing" % @autosign + unless defined? @@warnedonautosign + @@warnedonautosign = true + Puppet.info "Autosign is enabled but %s is missing" % @autosign + end return false end auth = Puppet::Server::AuthStore.new diff --git a/lib/puppet/storage.rb b/lib/puppet/storage.rb index a1ca9e1cc..af59efa19 100644 --- a/lib/puppet/storage.rb +++ b/lib/puppet/storage.rb @@ -31,27 +31,28 @@ module Puppet unless File.exists?(Puppet[:checksumfile]) Puppet.info "Statefile %s does not exist" % Puppet[:checksumfile] + unless defined? @@state and ! @@state.nil? + self.init + end return end #Puppet.debug "Loading statefile %s" % Puppet[:checksumfile] Puppet::Util.lock(Puppet[:checksumfile]) { |file| #@@state = Marshal.load(file) - @@state = YAML.load(file) - #File.open(Puppet[:checksumfile]) { |file| - # file.each { |line| - # line.chomp! - # myclass, key, value = line.split(@@splitchar) -# -# begin -# @@state[eval(myclass)][key] = Marshal::load(value) -# rescue => detail -# raise Puppet::Error, -# "Failed to load value for %s::%s => %s" % [ -# myclass,key,detail -# ], caller -# end -# } - #} + begin + @@state = YAML.load(file) + rescue => detail + Puppet.err "Checksumfile %s is corrupt; replacing" % + Puppet[:checksumfile] + begin + File.rename(Puppet[:checksumfile], + Puppet[:checksumfile] + ".bad") + rescue + raise Puppet::Error, + "Could not rename corrupt %s; remove manually" % + Puppet[:checksumfile] + end + end } #Puppet.debug "Loaded state is %s" % @@state.inspect diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index b56312d07..dc7f0dab9 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1156,23 +1156,6 @@ class Type < Puppet::Element } end - # sync the changes to disk, and return the events generated by the changes - # FIXME this method is essentially obviated, but it's still used by tests - # and i don't feel like fixing it yet - def sync - raise Puppet::DevError, "Type#sync called" - events = self.collect { |child| - child.sync - }.reject { |event| - ! (event.is_a?(Symbol) or event.is_a?(String)) - }.flatten - - #Puppet.notice "got events %s" % events.inspect - - Puppet::Metric.addevents(self.class,self,events) - return events - end - # convert to a string def to_s self.name diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb index 78ccb36da..237c17724 100644 --- a/lib/puppet/type/component.rb +++ b/lib/puppet/type/component.rb @@ -93,7 +93,7 @@ module Puppet def name #return self[:name] unless defined? @name - if self[:type] == self[:name] + if self[:type] == self[:name] or self[:name] =~ /--\d+$/ @name = self[:type] else @name = "%s[%s]" % [self[:type],self[:name]] diff --git a/lib/puppet/type/pfile/checksum.rb b/lib/puppet/type/pfile/checksum.rb index 179c1f613..813157d51 100755 --- a/lib/puppet/type/pfile/checksum.rb +++ b/lib/puppet/type/pfile/checksum.rb @@ -81,6 +81,10 @@ module Puppet @checktypes << value state = Puppet::Storage.state(self) + + unless state + raise Puppet::DevError, "Did not get state back from Storage" + end if hash = state[@parent[:path]] if hash.include?(value) return hash[value] |
