| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 tw=0: |
|
5
|
|
|
|
|
|
|
# vim: set expandtab: |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Rex::Apache::Deploy::Tomcat7 - Deploy application to Tomcat 7. |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
With this module you can deploy WAR archives to Tomcat7. |
|
14
|
|
|
|
|
|
|
This module needs the manager application and I permissions. |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Rex::Apache::Deploy qw/Tomcat7/; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
context_path "/myapp"; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
task "dodeploy", "tc01", "tc02", sub { |
|
23
|
|
|
|
|
|
|
deploy "myapp.war", |
|
24
|
|
|
|
|
|
|
username => "manager", |
|
25
|
|
|
|
|
|
|
password => "manager", |
|
26
|
|
|
|
|
|
|
port => 8080; |
|
27
|
|
|
|
|
|
|
}; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over 4 |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
package Rex::Apache::Deploy::Tomcat7; |
|
36
|
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
1569
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
25
|
|
|
38
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
1
|
|
|
1
|
|
5
|
use Rex::Commands::Run; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
41
|
1
|
|
|
1
|
|
81
|
use Rex::Commands::Fs; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
6
|
|
|
42
|
1
|
|
|
1
|
|
431
|
use Rex::Commands::Upload; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
43
|
1
|
|
|
1
|
|
44
|
use Rex::Commands; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
44
|
1
|
|
|
1
|
|
818
|
use File::Basename qw(dirname basename); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
61
|
|
|
45
|
1
|
|
|
1
|
|
5
|
use LWP::UserAgent; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
9
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#require Exporter; |
|
48
|
|
|
|
|
|
|
#use base qw(Exporter); |
|
49
|
|
|
|
|
|
|
|
|
50
|
1
|
|
|
1
|
|
29
|
use vars qw(@EXPORT $context_path); |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
127
|
|
|
51
|
|
|
|
|
|
|
@EXPORT = qw(deploy context_path jk); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
############ deploy functions ################ |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item deploy($file, %option) |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This function deploys the given WAR archive. For that it will connect to the Tomcat manager. You have to define username and password for the Tomcat manager in the %option hash. If the Tomcat manager isn't available under its default location /manager you can also define the location with the I option. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
task "dodeploy", "tc01", "tc02", sub { |
|
60
|
|
|
|
|
|
|
deploy "myapp.war", |
|
61
|
|
|
|
|
|
|
username => "manager", |
|
62
|
|
|
|
|
|
|
password => "manager", |
|
63
|
|
|
|
|
|
|
manager_url => "_manager", |
|
64
|
|
|
|
|
|
|
port => 8080, |
|
65
|
|
|
|
|
|
|
context_path => "/foo"; |
|
66
|
|
|
|
|
|
|
}; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub deploy { |
|
72
|
0
|
|
|
0
|
1
|
|
my ( $file, %option ) = @_; |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if ( !%option ) { |
|
75
|
0
|
0
|
|
|
|
|
if ( Rex::Config->get("package_option") ) { |
|
76
|
0
|
|
|
|
|
|
%option = %{ Rex::Config->get("package_option") }; |
|
|
0
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $options = \%option; |
|
81
|
|
|
|
|
|
|
|
|
82
|
1
|
|
|
1
|
|
9
|
no strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
21
|
|
|
83
|
1
|
|
|
1
|
|
5
|
no warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
114
|
|
|
84
|
0
|
|
|
|
|
|
my $rnd_file = get_random( 8, a .. z, 0 .. 9 ); |
|
85
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
23
|
|
|
86
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1083
|
|
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if ( !exists $options->{"context_path"} ) { |
|
89
|
0
|
|
|
|
|
|
$options->{"context_path"} = $context_path; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
if ( exists $options->{"manager_url"} ) { |
|
93
|
0
|
|
|
|
|
|
my $mgr_url = $options->{"manager_url"}; |
|
94
|
0
|
|
|
|
|
|
$mgr_url =~ s{^/}{}; |
|
95
|
0
|
|
|
|
|
|
$options->{"manager_url"} = $mgr_url; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
else { |
|
98
|
0
|
|
|
|
|
|
$options->{"manager_url"} = "manager"; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
upload( $file, "/tmp/$rnd_file.war" ); |
|
102
|
0
|
|
|
|
|
|
chmod 644, "/tmp/$rnd_file.war"; |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$options->{"file"} = "/tmp/$rnd_file.war"; |
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
_deploy($options); |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
unlink "/tmp/$rnd_file.war"; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub jk { |
|
112
|
0
|
|
|
0
|
0
|
|
my ( $action, $iname, @opts ) = @_; |
|
113
|
0
|
|
|
|
|
|
my $option = {@opts}; |
|
114
|
0
|
|
0
|
|
|
|
my $path = $option->{"path"} || "/jkmanager"; |
|
115
|
0
|
|
0
|
|
|
|
my $worker = $option->{"worker"} || ""; |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $url = "http://%s%s/?cmd=update&w=$worker&att=vwa&sw=%s&vwa=%i"; |
|
118
|
0
|
|
|
|
|
|
my $server = Rex->get_current_connection()->{"server"}; |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
if ( $action eq "disable" ) { |
|
121
|
0
|
|
|
|
|
|
$url = sprintf( $url, $server, $path, $iname, 1 ); |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
else { |
|
124
|
0
|
|
|
|
|
|
$url = sprintf( $url, $server, $path, $iname, 0 ); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
|
128
|
0
|
|
|
|
|
|
my $response = $ua->get($url); |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
if ( !$response->is_success ) { |
|
131
|
0
|
|
|
|
|
|
die("Failed $action instance"); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
############ helper function ############## |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _deploy { |
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
|
|
0
|
|
|
my $p = shift; |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $server = connection->server; |
|
142
|
0
|
0
|
|
|
|
|
if ( $server eq "" ) { |
|
143
|
0
|
|
|
|
|
|
$server = "localhost"; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
|
147
|
|
|
|
|
|
|
my $url = |
|
148
|
|
|
|
|
|
|
_get_url( "$server:$p->{port}", |
|
149
|
|
|
|
|
|
|
"deploy?path=$p->{context_path}&war=file:$p->{file}&update=true", |
|
150
|
0
|
|
|
|
|
|
$p->{"username"}, $p->{"password"}, $p->{"manager_url"} ); |
|
151
|
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
Rex::Logger::debug("Connection to: $url"); |
|
153
|
0
|
|
|
|
|
|
my $resp = $ua->get($url); |
|
154
|
0
|
0
|
|
|
|
|
if ( $resp->is_success ) { |
|
155
|
0
|
|
|
|
|
|
my $c = $resp->decoded_content; |
|
156
|
0
|
0
|
|
|
|
|
if ( $c =~ m/FAIL/gmi ) { |
|
157
|
0
|
|
|
|
|
|
Rex::Logger::info( $resp->decoded_content ); |
|
158
|
0
|
|
|
|
|
|
die( $resp->decoded_content ); |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
else { |
|
161
|
0
|
|
|
|
|
|
Rex::Logger::info( $resp->decoded_content ); |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
else { |
|
165
|
0
|
|
|
|
|
|
Rex::Logger::info( "FAILURE: $url: " . $resp->status_line ); |
|
166
|
0
|
|
|
|
|
|
die( "FAILURE: $url: " . $resp->status_line ); |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub _undeploy { |
|
172
|
|
|
|
|
|
|
|
|
173
|
0
|
|
|
0
|
|
|
my $p = shift; |
|
174
|
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
my $server = connection->server; |
|
176
|
0
|
0
|
|
|
|
|
if ( $server eq "" ) { |
|
177
|
0
|
|
|
|
|
|
$server = "localhost"; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
|
181
|
|
|
|
|
|
|
my $url = _get_url( "$server:$p->{port}", "undeploy?path=$p->{context_path}", |
|
182
|
0
|
|
|
|
|
|
$p->{username}, $p->{password}, $p->{manager_url} ); |
|
183
|
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
Rex::Logger::debug("Connection to: $url"); |
|
185
|
0
|
|
|
|
|
|
my $resp = $ua->get($url); |
|
186
|
0
|
0
|
|
|
|
|
if ( $resp->is_success ) { |
|
187
|
0
|
|
|
|
|
|
Rex::Logger::info( $resp->decoded_content ); |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
else { |
|
190
|
0
|
|
|
|
|
|
Rex::Logger::info( "FAILURE: $url: " . $resp->status_line ); |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub _get_url { |
|
196
|
0
|
|
|
0
|
|
|
my $server = shift; |
|
197
|
0
|
|
|
|
|
|
my $command = shift; |
|
198
|
0
|
|
|
|
|
|
my $user = shift; |
|
199
|
0
|
|
|
|
|
|
my $pw = shift; |
|
200
|
0
|
|
|
|
|
|
my $mgr_path = shift; |
|
201
|
|
|
|
|
|
|
|
|
202
|
0
|
|
0
|
|
|
|
$mgr_path ||= "manager"; |
|
203
|
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
return "http://$user:$pw\@" . "$server/$mgr_path/text/$command"; |
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub _do_action { |
|
208
|
|
|
|
|
|
|
|
|
209
|
0
|
|
|
0
|
|
|
my $action = shift; |
|
210
|
0
|
|
|
|
|
|
my $path = shift; |
|
211
|
0
|
|
|
|
|
|
my $port = shift; |
|
212
|
0
|
|
|
|
|
|
my $user = shift; |
|
213
|
0
|
|
|
|
|
|
my $pw = shift; |
|
214
|
0
|
|
|
|
|
|
my $mgr_path = shift; |
|
215
|
|
|
|
|
|
|
|
|
216
|
0
|
|
0
|
|
|
|
$mgr_path ||= "manager"; |
|
217
|
|
|
|
|
|
|
|
|
218
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
|
219
|
0
|
|
|
|
|
|
my $current_connection = Rex::get_current_connection(); |
|
220
|
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
my $server = connection->server; |
|
222
|
0
|
0
|
|
|
|
|
if ( $server eq "" ) { |
|
223
|
0
|
|
|
|
|
|
$server = "localhost"; |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
0
|
|
|
|
|
|
my $_url = |
|
227
|
|
|
|
|
|
|
_get_url( "$server:$port", "$action?path=$path", $user, $pw, $mgr_path ); |
|
228
|
0
|
|
|
|
|
|
Rex::Logger::debug("Connecting to: $_url"); |
|
229
|
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
|
my $resp = $ua->get($_url); |
|
231
|
0
|
0
|
|
|
|
|
if ( $resp->is_success ) { |
|
232
|
0
|
|
|
|
|
|
Rex::Logger::info( $resp->decoded_content ); |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
else { |
|
235
|
0
|
|
|
|
|
|
Rex::Logger::info( "FAILURE: $_url: " . $resp->status_line ); |
|
236
|
|
|
|
|
|
|
} |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
} |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
############ configuration functions ############# |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item context_path($path) |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This function sets the context path for the application that gets deployed. This is a global setting. If you want to specify a custom context path for your application you can also do this as an option for the I function. |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
context_path "/myapp"; |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub context_path { |
|
251
|
0
|
|
|
0
|
1
|
|
$context_path = shift; |
|
252
|
|
|
|
|
|
|
} |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
####### import function ####### |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub import { |
|
257
|
|
|
|
|
|
|
|
|
258
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
105
|
|
|
259
|
0
|
|
|
0
|
|
|
for my $func (@EXPORT) { |
|
260
|
0
|
|
|
|
|
|
Rex::Logger::debug("Registering main::$func"); |
|
261
|
0
|
|
|
|
|
|
*{"$_[1]::$func"} = \&$func; |
|
|
0
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
} |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
} |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=back |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=cut |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
1; |