File Coverage

blib/lib/Rex/Apache/Deploy.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4             # vim: set ts=3 sw=3 tw=0:
5             # vim: set expandtab:
6              
7             =head1 NAME
8              
9             Rex::Apache::Deploy - Deploy module for Rex
10              
11             =head1 DESCRIPTION
12              
13             This is a (R)?ex module to ease the deployments of Tomcat, Perl, Rails, PHP or other languages.
14              
15             You can find examples and howtos on L
16              
17             =head1 GETTING HELP
18              
19             =over 4
20              
21             =item * Web Site: L
22              
23             =item * IRC: irc.freenode.net #rex
24              
25             =back
26              
27             =head1 DEPENDENCIES
28              
29             =over 4
30              
31             =item *
32              
33             L
34              
35             =item *
36              
37             L
38              
39             =item *
40              
41             L
42              
43             =item *
44              
45             zip
46              
47             =item *
48              
49             unzip
50              
51             =item *
52              
53             tar
54              
55             =item *
56              
57             bzip2
58              
59             =item *
60              
61             wget
62              
63             =back
64              
65             If you're using windows, you can install them from here: http://sourceforge.net/projects/gnuwin32/files/
66             Don't forget to add the bin directory of the installation to your %PATH% environment variable.
67              
68             =head1 SYNOPSIS
69              
70             use Rex::Apache::Deploy Symlink;
71            
72             deploy_to "/var/deploy";
73            
74             document_root "/var/www/myhost/htdocs";
75            
76             generate_deploy_directory sub {
77             my ($file) = @_;
78             $file =~ m/-(\d+\.\d+\.\d+)\.tar\.gz$/;
79             return $1;
80             };
81            
82             desc "Deploy to Apache";
83             task "deploy", group => "frontend", sub {
84             deploy "mypkg-1.0.1.tar.gz";
85             };
86              
87              
88             =head1 DEPLOY METHODS
89              
90             =over 4
91              
92             =item Symlink
93              
94             This method will upload your package (*.tar.gz, *.tar.bz2 or *.zip) all you servers and extract it in the directory you specified with I concatenated with the result of I. After that it will create a symlink from I to this new directory.
95              
96             deploy_to "/var/deploy";
97             document_root "/var/www";
98             generate_deploy_directory sub { return "1.0"; };
99              
100             This will upload the file to I and create a symlink from I to I.
101              
102             =item Tomcat
103              
104             This method is for Tomcat deployments. You need to have the Tomcat Manage application running on your Tomcat servers. It will upload your package to I, call the Tomcat Manager to undeploy the current context and deploy the new war archive. After that it will delete the uploaded temporary war file.
105              
106             context_path "/myapp";
107            
108             task "deploy", group => "middleware", sub {
109             deploy "myapp.war",
110             username => "manager-user",
111             password => "manager-password",
112             port => 8080,
113             manager_url => "/manager";
114             };
115              
116             This will deploy I to the tomcat listening on port I<8080> with the manager application found under I.
117              
118             =back
119              
120             =head2 SWITCHING INSTANCES
121              
122             If you have multiple Tomcat Instances you can manage them with the I command.
123              
124             jk disable => 'name';
125             jk enable => 'name';
126              
127              
128             =cut
129              
130              
131             package Rex::Apache::Deploy;
132              
133 1     1   2369 use strict;
  1         2  
  1         34  
134 1     1   6 use warnings;
  1         1  
  1         28  
135              
136 1     1   1119 use Data::Dumper;
  1         14331  
  1         369  
137 1     1   4856 use Rex::Commands::Run;
  0            
  0            
138             use Rex::Logger;
139              
140             use Cwd qw(getcwd);
141              
142             our $VERSION = '0.11.0';
143              
144             ###### commonly used
145             our @COMMONS = ();
146              
147              
148             sub import {
149              
150             my ($call_class) = caller;
151             return unless $call_class;
152              
153             return unless $_[1];
154              
155             die("Invalid input format") unless($_[1] =~ m/^[a-z0-9_]+$/i);
156              
157             no strict 'refs';
158             for my $exp (@COMMONS) {
159             *{"${call_class}::$exp"} = \&$exp;
160             }
161             use strict;
162              
163             eval "use $_[0]::$_[1] '$call_class';";
164              
165             }
166              
167             1;