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
192
193
194
195
196
197
|
# File 'manifests/service.pp', line 34
define tomcat::service (
Optional[String[1]] $catalina_home = undef,
Optional[Stdlib::Absolutepath] $catalina_base = undef,
Boolean $use_jsvc = false,
Boolean $use_init = false,
Optional[String[1]] $java_home = undef,
Enum['running', 'stopped', 'true', 'false'] $service_ensure = running,
Optional[Boolean] $service_enable = undef,
Optional[String[1]] $service_name = undef,
Optional[String[1]] $start_command = undef,
Optional[String[1]] $stop_command = undef,
Optional[String[1]] $status_command = undef,
Optional[String[1]] $user = undef,
Integer $wait_timeout = 10,
) {
include tomcat
$_user = pick($user, $tomcat::user)
# XXX Backwards compatibility: If the user declares a base but not a home, we
# assume they are in compatibility mode
if $catalina_base {
$_catalina_home = pick($catalina_home, $catalina_base)
} else {
$_catalina_home = pick($catalina_home, $tomcat::catalina_home)
}
$_catalina_base = pick($catalina_base, $_catalina_home) #default to home
tag(sha1($_catalina_home))
tag(sha1($_catalina_base))
if $use_init and ! $use_jsvc and ! $service_name {
fail('service_name must be specified when using the package init script')
}
if $use_init and ! $use_jsvc and $catalina_home {
warning('catalina_home has no effect when using the package init script; ignoring')
}
if $use_jsvc and $service_name {
warning('service_name has no effect when using jsvc; ignoring')
}
if ! $use_init and $service_enable != undef {
warning('service_enable has no effect without an init script; ignoring')
}
if ! $use_jsvc and $java_home {
warning('java_home has no effect when not using jsvc; ignoring')
}
if $use_jsvc and $use_init {
$_service_name = "tomcat-${name}"
$_hasstatus = true
$_hasrestart = true
$_start = "service tomcat-${name} start"
$_stop = "service tomcat-${name} stop"
$_status = "service tomcat-${name} status"
$_provider = undef
# Template uses:
# - $_catalina_home
# - $_catalina_base
# - $java_home
# - $_user
$parameters = {
'_catalina_base' => $_catalina_base,
'_catalina_home' => $_catalina_home,
'java_home' => $java_home,
'_user' => $_user,
'wait_timeout' => $wait_timeout,
}
file { "/etc/init.d/tomcat-${name}":
mode => '0755',
content => epp('tomcat/jsvc-init.epp', $parameters),
}
} elsif $use_jsvc {
if $java_home {
$_jsvc_home = "-home ${java_home} "
} else {
$_jsvc_home = undef
}
$_service_name = "tomcat-${name}"
$_hasstatus = false
$_hasrestart = false
if $start_command {
$_start = $start_command
} else {
$_start = "export CATALINA_HOME=${_catalina_home}; export CATALINA_BASE=${_catalina_base}; \
\$CATALINA_HOME/bin/jsvc \
${_jsvc_home}-user ${_user} \
-classpath \$CATALINA_HOME/bin/bootstrap.jar:\$CATALINA_HOME/bin/tomcat-juli.jar \
-outfile \$CATALINA_BASE/logs/catalina.out \
-errfile \$CATALINA_BASE/logs/catalina.err \
-pidfile \$CATALINA_BASE/logs/jsvc.pid \
-Dcatalina.home=\$CATALINA_HOME \
-Dcatalina.base=\$CATALINA_BASE \
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
-Djava.util.logging.config.file=\$CATALINA_BASE/conf/logging.properties \
org.apache.catalina.startup.Bootstrap"
}
if $stop_command {
$_stop = $stop_command
} else {
$_stop = "export CATALINA_HOME=${_catalina_home}; export CATALINA_BASE=${_catalina_base};
\$CATALINA_HOME/bin/jsvc \
-pidfile \$CATALINA_BASE/logs/jsvc.pid \
-stop org.apache.catalina.startup.Bootstrap"
}
if $status_command {
$_status = $status_command
} else {
$_status = "ps p `cat ${_catalina_base}/logs/jsvc.pid` > /dev/null"
}
$_provider = 'base'
} elsif $use_init {
$_service_name = $service_name
$_hasstatus = true
$_hasrestart = true
$_start = $start_command
$_stop = $stop_command
$_status = $status_command
$_provider = undef
} else {
$_service_name = "tomcat-${name}"
$_hasstatus = false
$_hasrestart = false
$_start = $start_command ? {
undef => "su -s /bin/bash -c 'CATALINA_HOME=${_catalina_home} CATALINA_BASE=${_catalina_base} ${_catalina_home}/bin/catalina.sh start' ${_user}", # lint:ignore:140chars
default => $start_command
}
$_stop = $stop_command ? {
undef => "su -s /bin/bash -c 'CATALINA_HOME=${_catalina_home} CATALINA_BASE=${_catalina_base} ${_catalina_home}/bin/catalina.sh stop' ${_user}", # lint:ignore:140chars
default => $stop_command
}
$_status = $status_command ? {
undef => "ps aux | grep 'catalina.base=${_catalina_base} ' | grep -v grep",
default => $status_command
}
$_provider = 'base'
}
if $use_init {
if $service_enable != undef {
$_service_enable = $service_enable
} else {
$_service_enable = $service_ensure ? {
'running' => true,
true => true,
default => undef,
}
}
} else {
$_service_enable = undef
}
service { $_service_name:
ensure => $service_ensure,
enable => $_service_enable,
hasstatus => $_hasstatus,
hasrestart => $_hasrestart,
start => $_start,
stop => $_stop,
status => $_status,
provider => $_provider,
}
}
|