[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:33:45 UTC 2010


The following commit has been merged in the upstream branch:
commit 6b26a7c0f1793a74ca778383125b7e4618fcc9e2
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Tue May 11 17:31:08 2010 -0700

    Feature #2935: Puppet::Mode
    
    Create a Mode class and Puppet.mode and application.mode methods
    Mode can be "agent", "master", or "user". Each application sets a mode.
    The Mode object has some smarts about the defaults for that mode.
    
    Signed-off-by: Jesse Wolfe <jes5199 at gmail.com>

diff --git a/lib/puppet.rb b/lib/puppet.rb
index 7b54ceb..3dcc053 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -91,6 +91,15 @@ module Puppet
         @@settings
     end
 
+    def self.mode
+        require 'puppet/util/mode'
+        $puppet_application_mode ||= Puppet::Util::Mode.new( :user )
+    end
+
+    def self.application_name
+        $puppet_application_name ||= "apply"
+    end
+
     # Load all of the configuration parameters.
     require 'puppet/defaults'
 
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 1ba9866..ca01572 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -219,6 +219,12 @@ class Puppet::Application
         def [](name)
             find(name).new
         end
+
+        def mode( mode_name = nil)
+            @mode ||= mode_name || @mode || :user
+            require 'puppet/util/mode'
+            Puppet::Util::Mode.new( @mode )
+        end
     end
 
     attr_reader :options, :command_line
@@ -258,8 +264,12 @@ class Puppet::Application
 
     def initialize(command_line = nil)
         @command_line = command_line || Puppet::Util::CommandLine.new
-
+        @mode = self.class.mode
         @options = {}
+
+        $puppet_application_mode = @mode
+        $puppet_application_name = name
+        require 'puppet'
     end
 
     # This is the main application entry point
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index dab1120..992b218 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -1,56 +1,19 @@
 # The majority of the system configuration parameters are set in this file.
 module Puppet
-    # If we're running the standalone puppet process as a non-root user,
-    # use basedirs that are in the user's home directory.
-    conf = nil
-    var = nil
-
-    require 'puppet/util/command_line'
-    name = Puppet::Util::CommandLine.new.legacy_executable_name
-
-    # Make File.expand_path happy
-    require 'etc'
-    ENV["HOME"] ||= Etc.getpwuid(Process.uid).dir
-
-    if name != "puppetmasterd" and Puppet::Util::SUIDManager.uid != 0
-        conf = File.expand_path("~/.puppet")
-        var = File.expand_path("~/.puppet/var")
-    else
-        # Else, use system-wide directories.
-        conf = "/etc/puppet"
-        var = "/var/lib/puppet"
-    end
-
-    self.setdefaults(:main,
-        :confdir => [conf, "The main Puppet configuration directory.  The default for this parameter is calculated based on the user.  If the process
-        is runnig as root or the user that ``puppetmasterd`` is supposed to run as, it defaults to a system directory, but if it's running as any other user,
+    setdefaults(:main,
+        :confdir => [Puppet.mode.conf_dir, "The main Puppet configuration directory.  The default for this parameter is calculated based on the user.  If the process
+        is running as root or the user that ``puppet master`` is supposed to run as, it defaults to a system directory, but if it's running as any other user,
         it defaults to being in ``~``."],
-        :vardir => [var, "Where Puppet stores dynamic and growing data.  The default for this parameter is calculated specially, like `confdir`_."],
-        :name => [name, "The name of the service, if we are running as one.  The
+        :vardir => [Puppet.mode.var_dir, "Where Puppet stores dynamic and growing data.  The default for this parameter is calculated specially, like `confdir`_."],
+        :name => [Puppet.application_name.to_s, "The name of the application, if we are running as one.  The
+            default is essentially $0 without the path or ``.rb``."],
+        :mode => [Puppet.mode.name.to_s, "The name of the application, if we are running as one.  The
             default is essentially $0 without the path or ``.rb``."]
     )
 
-    if name == "puppetmasterd"
-        logopts = {:default => "$vardir/log",
-            :mode => 0750,
-            :owner => "service",
-            :group => "service",
-            :desc => "The Puppet log directory."
-        }
-    else
-        logopts = ["$vardir/log", "The Puppet log directory."]
-    end
-    setdefaults(:main, :logdir => logopts)
+    setdefaults(:main, :logdir => Puppet.mode.logopts)
 
-    # This name hackery is necessary so that the rundir is set reasonably during
-    # unit tests.
-    if Process.uid == 0 and %w{puppetd puppetmasterd}.include?(self.name)
-        rundir = "/var/run/puppet"
-    else
-        rundir = "$vardir/run"
-    end
-
-    self.setdefaults(:main,
+    setdefaults(:main,
         :trace => [false, "Whether to print stack traces on some errors"],
         :autoflush => [false, "Whether log files should always flush to disk."],
         :syslogfacility => ["daemon", "What syslog facility to use when logging to
@@ -63,7 +26,7 @@ module Puppet
                 might result in spurious service restarts)."
         },
         :rundir => {
-            :default => rundir,
+            :default => Puppet.mode.run_dir,
             :mode => 01777,
             :desc => "Where Puppet PID files are kept."
         },
diff --git a/lib/puppet/util/mode.rb b/lib/puppet/util/mode.rb
new file mode 100644
index 0000000..6de8f56
--- /dev/null
+++ b/lib/puppet/util/mode.rb
@@ -0,0 +1,69 @@
+module Puppet
+    module Util
+        class Mode
+            def initialize(name)
+                @name = name.to_sym
+            end
+
+            attr :name
+
+            def master?
+                name == :master
+            end
+
+            def agent?
+                name == :agent
+            end
+
+            def user?
+                name == :user
+            end
+
+            def conf_dir
+                which_dir("/etc/puppet", "~/.puppet")
+            end
+
+            def var_dir
+                which_dir("/var/lib/puppet", "~/.puppet/var")
+            end
+
+            def run_dir
+                which_dir("/var/run/puppet", "~/.puppet/var")
+            end
+
+            def logopts
+                if name == :master
+                    {
+                        :default => "$vardir/log",
+                        :mode => 0750,
+                        :owner => "service",
+                        :group => "service",
+                        :desc => "The Puppet log directory."
+                    }
+                else
+                    ["$vardir/log", "The Puppet log directory."]
+                end
+            end
+
+            private
+
+            def which_dir( global, user )
+                #FIXME: we should test if we're user "puppet"
+                #       there's a comment that suggests that we do that
+                #       and we currently don't.
+                expand_path case
+                when name == :master; global
+                when Puppet.features.root?; global
+                else user
+                end
+            end
+
+            def expand_path( dir )
+                require 'etc'
+                ENV["HOME"] ||= Etc.getpwuid(Process.uid).dir
+                File.expand_path(dir)
+            end
+
+        end
+    end
+end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list