-
Notifications
You must be signed in to change notification settings - Fork 1
/
instance.pp
191 lines (179 loc) · 5.75 KB
/
instance.pp
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# Create a new user and tomcat-home and add tomcat-user-instance
# uses debian package tomcat7-user
#
# @param gid
# the group id of new user
#
# @param uid
# the user id of new user
#
# @param http_port
# which port should tomcat listen on
#
# @param control_port
# the tomcat control port
#
# @param jmx_port
# port for java jmx management, defaults to undef, in which case no jmx port will be openend
#
# @param xmx
# java max memory allocation (Xmx), default: 128m
#
# @param xms
# java inital memory allocation (Xms), default: 32m
#
# @param user
# user which the service belongs to (will be created), defaults to $name if not set
#
# @param group
# usergroup which the service belongs to (will be created), defaults to $name if not set
#
# @param additional_java_opts
# additional opts to be passed to tomcat as JAVA_OPTS
#
# @param additional_default_lines
# additional lines to add to /etc/default/tomcat-$name
#
# @param init_dependencies
# services which should be started before this tomcat, added as dependency to init.d script, separate with whitespace if more than one
#
# @param telegraph_enabled
# collect stats with telegraf, installs jolokia.war in webapp dir
#
# @param additional_java_opts
# additional opts to be passed to tomcat as JAVA_OPTS
#
# @param keep_logs
# the amount of days catalina logs are kept by logrotate
#
define usertomcat::instance (
$http_port,
$control_port,
$gid = undef,
$uid = undef,
$jmx_port = undef,
$xmx = '128m',
$xms = '32m',
$group = $name,
$user = $name,
$tomcat_version = '7',
$additional_java_opts = undef,
$additional_default_lines = [],
$init_dependencies = undef,
$telegraf_enabled = false,
$logdir = "/home/${user}/${name}/logs",
$keep_logs = 30,
$initd_template_loc = "usertomcat/etc/init.d/tomcat${tomcat_version}.Debian.erb",
) {
require 'usertomcat::dependencies'
ensure_packages(["tomcat${tomcat_version}", "tomcat${tomcat_version}-user", 'libtcnative-1'])
# Check if group and user are already existing.
# Just in case we have two tomcats using the same user and group
# (e.g. tgcrud and tgcrud-public or group ULSB is already existing :-)
if ! defined(Group[$group]) {
group { $group:
ensure => present,
gid => $gid,
}
}
if ! defined(User[$user]) {
user { $user:
ensure => present,
uid => $uid,
gid => $gid,
shell => '/bin/bash',
home => "/home/${user}",
managehome => true,
}
}
exec { "create_${name}":
path => ['/usr/bin','/bin','/usr/sbin'],
command => "tomcat${tomcat_version}-instance-create -p ${http_port} -c ${control_port} /home/${user}/${name}",
creates => "/home/${user}/${name}",
user => $user,
require => Package["tomcat${tomcat_version}-user"],
}
# ~> exec { "patching_${name}_for_apr":
# path => ['/usr/bin','/bin','/usr/sbin'],
# command => "patch /home/${user}/${name}/conf/server.xml < /usr/local/src/t#omcat${tomcat_version}-apr.patch",
# refreshonly => true,
# require => File["/usr/local/src/tomcat${tomcat_version}-apr.patch"],
# }
file { "/etc/init.d/${name}":
ensure => file,
content => template($initd_template_loc),
owner => 'root',
group => 'root',
mode => '0755',
before => Service[$name],
notify => Service[$name],
}
file { "/etc/default/${name}":
ensure => file,
content => template("usertomcat/etc/default/tomcat${tomcat_version}.erb"),
owner => 'root',
group => 'root',
mode => '0644',
before => Service[$name],
notify => Service[$name],
}
service { $name:
ensure => running,
enable => true,
require => Exec["create_${name}"],
}
# add symlink to var/log/$name
file {"/var/log/${name}":
ensure => link,
target => $logdir,
}
# add logdir to logging.properties
# ++TODO++
# logrotate
logrotate::rule { $name:
path => "${logdir}/catalina.out",
require => Exec["create_${name}"],
rotate => $keep_logs,
rotate_every => 'day',
compress => true,
copytruncate => true,
missingok => true,
ifempty => true,
dateext => true,
dateformat => '.%Y-%m-%d',
}
if $telegraf_enabled {
require 'usertomcat::jolokia'
file { "/home/${user}/${name}/webapps/jolokia.war":
source => '/var/cache/jolokia.war',
}
telegraf::input { "jolokia2_${name}_tomcat":
plugin_type => 'jolokia2_agent',
options => [{
'urls' => ["http://127.0.0.1:${http_port}/jolokia/"],
'name_prefix' => "${name}.",
'metric' => [{
'name' => 'tomcat_requests',
'mbean' => 'Catalina:name=*,type=GlobalRequestProcessor',
'paths' => [ 'requestCount','bytesReceived','bytesSent','processingTime','errorCount' ],
'tag_keys' => ['name'],
},{
'name' => 'tomcat_threads',
'mbean' => 'Catalina:name=*,type=ThreadPool',
'paths' => [ 'maxThreads','currentThreadCount','currentThreadsBusy' ],
'tag_keys' => ['name'],
},{
'name' => 'process_cpu_load',
'mbean' => 'java.lang:type=OperatingSystem',
'paths' => [ 'ProcessCpuLoad' ],
'tag_keys' => ['name'],
},{
'name' => 'heap_memory_usage',
'mbean' => 'java.lang:type=Memory',
'paths' => [ 'HeapMemoryUsage' ],
'tag_keys' => ['name'],
}],
}],
}
}
}