Sha256: 367743d3d2a9d18dcdb36eb2df83731d07825afc9e4df3886d7f04c21e30ba36

Contents?: true

Size: 1.79 KB

Versions: 99

Compression:

Stored size: 1.79 KB

Contents

require 'etc'

module Puppet
  module Util
    class RunMode
      def initialize(name)
        @name = name.to_sym
      end

      attr :name

      def self.[](name)
        @run_modes ||= {}
        if Puppet.features.microsoft_windows?
          @run_modes[name] ||= WindowsRunMode.new(name)
        else
          @run_modes[name] ||= UnixRunMode.new(name)
        end
      end

      def master?
        name == :master
      end

      def agent?
        name == :agent
      end

      def user?
        name == :user
      end

      def run_dir
        "$vardir/run"
      end

      def log_dir
        "$vardir/log"
      end

      private

      ##
      # select the system or the user directory depending on the context of
      # this process.  The most common use is determining filesystem path
      # values for confdir and vardir.  The intended semantics are:
      # {http://projects.puppetlabs.com/issues/16637 #16637} for Puppet 3.x
      #
      # @todo this code duplicates {Puppet::Settings#which\_configuration\_file}
      #   as described in {http://projects.puppetlabs.com/issues/16637 #16637}
      def which_dir( system, user )
        File.expand_path(if Puppet.features.root? then system else user end)
      end
    end

    class UnixRunMode < RunMode
      def conf_dir
        which_dir("/etc/puppet", "~/.puppet")
      end

      def var_dir
        which_dir("/var/lib/puppet", "~/.puppet/var")
      end
    end

    class WindowsRunMode < RunMode
      def conf_dir
        which_dir(File.join(windows_common_base("etc")), "~/.puppet")
      end

      def var_dir
        which_dir(File.join(windows_common_base("var")), "~/.puppet/var")
      end

    private

      def windows_common_base(*extra)
        [Dir::COMMON_APPDATA, "PuppetLabs", "puppet"] + extra
      end
    end
  end
end

Version data entries

99 entries across 99 versions & 3 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/util/run_mode.rb
puppet-3.8.7 lib/puppet/util/run_mode.rb
puppet-3.8.7-x86-mingw32 lib/puppet/util/run_mode.rb
puppet-3.8.7-x64-mingw32 lib/puppet/util/run_mode.rb
puppet-3.8.6 lib/puppet/util/run_mode.rb
puppet-3.8.6-x86-mingw32 lib/puppet/util/run_mode.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/util/run_mode.rb
puppet-3.8.6-x64-mingw32 lib/puppet/util/run_mode.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/util/run_mode.rb
puppet-3.8.5 lib/puppet/util/run_mode.rb
puppet-3.8.5-x86-mingw32 lib/puppet/util/run_mode.rb
puppet-3.8.5-x64-mingw32 lib/puppet/util/run_mode.rb
puppet-3.8.4 lib/puppet/util/run_mode.rb
puppet-3.8.4-x86-mingw32 lib/puppet/util/run_mode.rb
puppet-3.8.4-x64-mingw32 lib/puppet/util/run_mode.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/util/run_mode.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/util/run_mode.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/util/run_mode.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/util/run_mode.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/util/run_mode.rb