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
|
# File 'manifests/proxy_instance.pp', line 2
define helix::proxy_instance (
$p4proxyport,
$p4proxytarget,
$cachedir = "/opt/perforce/servers/${title}/cache",
$p4ssl = "/opt/perforce/servers/${title}/ssl",
$logfile = "/var/log/perforce/${title}_proxy.log",
$osuser = 'perforce',
$osgroup = 'perforce',
$ensure = 'running',
$enabled = true,
$p4dctl = undef,
) {
$instance_name = $title
if !defined(Class['helix::proxy']) {
fail('you must declare helix::proxy before declaring instances')
}
if !is_bool($enabled) {
fail('enabled parameter must be a boolean')
}
if !($ensure in ['running', 'stopped']) {
fail('ensure must be set to either running or stopped')
}
if $p4dctl {
$p4dctl_path = $p4dctl
} else {
$p4dctl_path = $helix::params::p4dctl
}
File {
ensure => file,
owner => $osuser,
group => $osgroup,
mode => '0644',
}
if $logfile == "/var/log/perforce/${title}_proxy.log" and !defined(File['/var/log/perforce']) {
file { '/var/log/perforce':
ensure => directory,
require => Package[$helix::proxy::pkgname],
}
}
# manage the p4dctl config file
file { "${title}_p4dctl_conf":
path => "/etc/perforce/p4dctl.conf.d/p4proxy_${instance_name}.conf",
owner => 'root',
group => 'root',
mode => '0600',
content => template('helix/p4proxy_p4dctl.erb'),
require => Package[$helix::proxy::pkgname],
}
# manage the cache directory if it is the default
if $cachedir == "/opt/perforce/servers/${title}/cache" {
if !defined(File["${title}_serverdir"]) {
file { "${title}_serverdir":
ensure => directory,
path => "/opt/perforce/servers/${title}",
require => File["${title}_p4dctl_conf"],
}
}
file { "${title}_cachedir":
ensure => directory,
path => $cachedir,
require => File["${title}_p4dctl_conf"],
before => Service["${title}_p4proxy_service"],
}
}
# manage the p4ssl parent directory if it is the default and not already managed
if $p4ssl == "/opt/perforce/servers/${title}/ssl" {
if !defined(File["${title}_serverdir"]) {
file { "${title}_serverdir":
ensure => directory,
path => "/opt/perforce/servers/${title}",
require => File["${title}_p4dctl_conf"],
}
}
}
# manage the p4ssl directory, if it isn't already
if !defined(File[$p4ssl]) {
file { $p4ssl:
ensure => directory,
mode => '0700',
require => File["${title}_p4dctl_conf"],
before => Service["${title}_p4proxy_service"],
}
}
# if proxy is going to listen on SSL port, ensure that certificate is generated
if $p4proxyport =~ /^ssl:/ {
exec { "${title}-Gc":
command => '/usr/sbin/p4p -Gc',
user => $osuser,
environment => "P4SSLDIR=${p4ssl}",
creates => "${p4ssl}/privatekey.txt",
require => File[$p4ssl],
notify => Exec["${title}-Gf"],
before => Service["${title}_p4proxy_service"],
}
exec { "${title}-Gf":
command => '/usr/sbin/p4p -Gf',
user => $osuser,
environment => "P4SSLDIR=${p4ssl}",
refreshonly => true,
}
}
# manage the service. The actual service is `perforce-p4dctl`, but the p4dctl command
# is used to manage the various service instances. it provides start/stop/restart/status
# subcommands to manage the instance
service { "${title}_p4proxy_service":
ensure => $ensure,
start => "${p4dctl_path} start ${instance_name}",
stop => "${p4dctl_path} stop ${instance_name}",
restart => "${p4dctl_path} restart ${instance_name}",
status => "${p4dctl_path} status ${instance_name}",
require => File["${title}_p4dctl_conf"],
}
}
|