forked from puppetlabs/puppet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_mode.rb
More file actions
163 lines (129 loc) · 3.8 KB
/
run_mode.rb
File metadata and controls
163 lines (129 loc) · 3.8 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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/puppetlabs/puppet", "~/.puppetlabs/etc/puppet")
end
def code_dir
which_dir("/etc/puppetlabs/code", "~/.puppetlabs/etc/code")
end
def var_dir
which_dir("/opt/puppetlabs/puppet/cache", "~/.puppetlabs/opt/puppet/cache")
end
def public_dir
which_dir("/opt/puppetlabs/puppet/public", "~/.puppetlabs/opt/puppet/public")
end
def run_dir
which_dir("/var/run/puppetlabs", "~/.puppetlabs/var/run")
end
def log_dir
which_dir("/var/log/puppetlabs/puppet", "~/.puppetlabs/var/log")
end
def pkg_config_path
'/opt/puppetlabs/puppet/lib/pkgconfig'
end
def gem_cmd
'/opt/puppetlabs/puppet/bin/gem'
end
def common_module_dir
'/opt/puppetlabs/puppet/modules'
end
def vendor_module_dir
'/opt/puppetlabs/puppet/vendor_modules'
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
def pkg_config_path
nil
end
def gem_cmd
if (puppet_dir = Puppet::Util.get_env('PUPPET_DIR'))
File.join(puppet_dir.to_s, 'bin', 'gem.bat')
else
File.join(Gem.default_bindir, 'gem.bat')
end
end
def common_module_dir
# TODO: use File.join?
"#{installdir}/puppet/modules" if installdir
end
def vendor_module_dir
File.join(installdir, 'puppet', 'vendor_modules') if installdir
end
private
def installdir
ENV['FACTER_env_windows_installdir']
end
def windows_common_base(*extra)
[ENV['ALLUSERSPROFILE'], "PuppetLabs"] + extra
end
end
end
end