1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
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::Util::Platform.windows?
@run_modes[name] ||= WindowsRunMode.new(name)
else
@run_modes[name] ||= UnixRunMode.new(name)
end
end
def server?
name == :master || name == :server
end
def master?
name == :master || name == :server
end
def agent?
name == :agent
end
def user?
name == :user
end
def run_dir
RunMode[name].run_dir
end
def log_dir
RunMode[name].log_dir
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:
# {https://projects.puppetlabs.com/issues/16637 #16637} for Puppet 3.x
#
# @todo this code duplicates {Puppet::Settings#which\_configuration\_file}
# as described in {https://projects.puppetlabs.com/issues/16637 #16637}
def which_dir( system, user )
if Puppet.features.root?
File.expand_path(system)
else
File.expand_path(user)
end
end
end
class UnixRunMode < RunMode
def conf_dir
which_dir("/etc/puppet", "~/.puppet/etc")
end
def code_dir
which_dir("/etc/puppet/code", "~/.puppet/code")
end
def var_dir
which_dir("/var/cache/puppet", "~/.puppet/cache")
end
def public_dir
which_dir("/var/cache/puppet/public", "~/.puppet/cache/public")
end
def run_dir
which_dir("/run/puppet", "~/.puppet/var/run")
end
def log_dir
which_dir("/var/log/puppet", "~/.puppet/var/log")
end
def ssl_dir
system_ssl = "/var/lib/puppet/ssl"
user_ssl = "$confdir/ssl"
if Puppet.features.root? or File.owned?(system_ssl)
system_ssl
else
user_ssl
end
end
end
class WindowsRunMode < RunMode
def conf_dir
which_dir(File.join(windows_common_base("puppet/etc")), "~/.puppetlabs/etc/puppet")
end
def code_dir
which_dir(File.join(windows_common_base("code")), "~/.puppetlabs/etc/code")
end
def var_dir
which_dir(File.join(windows_common_base("puppet/cache")), "~/.puppetlabs/opt/puppet/cache")
end
def public_dir
which_dir(File.join(windows_common_base("puppet/public")), "~/.puppetlabs/opt/puppet/public")
end
def run_dir
which_dir(File.join(windows_common_base("puppet/var/run")), "~/.puppetlabs/var/run")
end
def log_dir
which_dir(File.join(windows_common_base("puppet/var/log")), "~/.puppetlabs/var/log")
end
private
def windows_common_base(*extra)
[ENV['ALLUSERSPROFILE'], "PuppetLabs"] + extra
end
end
end
end
|