This repository has been archived by the owner on Feb 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrebuild.pl
executable file
·196 lines (171 loc) · 5.05 KB
/
rebuild.pl
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
192
193
194
195
196
#!/usr/bin/perl
use strict;
use Cwd;
our $gatodir = cwd();
our $tomcatdir = $gatodir."/tomcat";
our $urlbase = "http://localhost:8080";
our $backupdir = "$gatodir/../gatobackup";
our $edgewarpath = "$gatodir/gato-webapp/target/gato-webapp*war";
our $magrepopath = "/var/mag_repositories";
our $magnoliapropertiespath = "/etc/magnolia/config";
our @heavymodules = ('gato-lib', 'gato-internal', 'gato-component-cssjs', 'gato-component-dept-directory',
'gato-component-faq', 'gato-component-gallery', 'gato-component-documents', 'gato-area-mail', 'gato-component-button',
'gato-component-twitter', 'gato-component-rss', 'gato-component-events', 'gato-component-sitemap',
'gato-component-hours', 'gato-area-filterable-search');
our $module = "";
# place your local overrides in the root gato directory in a file named "rebuild_vars.pl"
# git will ignore the file
if (-e "$gatodir/rebuild_vars.pl") { require("$gatodir/rebuild_vars.pl"); }
if ($ARGV[0] eq '--module') {
$module = $ARGV[1];
buildmodule($module);
tomcat_restart(sub {
replacemodule($module);
});
} elsif ($ARGV[0] eq '--restart') {
tomcat_restart();
} elsif ($ARGV[0] eq '--stop') {
tomcat_stop();
} elsif ($ARGV[0] eq '--start') {
tomcat_start();
} elsif ($ARGV[0] eq '--resources') {
if (setmagnoliaresourcespath()) {
symlinkheavyresources();
}
} elsif ($ARGV[0] eq '--reset') {
resetdata();
} elsif ($ARGV[0] eq '--backup') {
backupmagrepositories();
backupmysql();
} elsif ($ARGV[0] eq '--restore') {
restoredata();
} elsif ($ARGV[0] eq '--dry') {
buildedge();
tomcat_restart(sub {
restoredata();
cleanwebapp();
installwar($edgewarpath);
});
triggerbootstrap();
} else {
buildedge();
tomcat_restart(sub {
cleanwebapp();
installwar($edgewarpath);
});
triggerbootstrap();
}
print "Done.\n";
sub tomcat_stop {
print "stopping tomcat...\n";
my $pid = `pgrep -f /java.*$tomcatdir`;
`kill $pid` if $pid > 0;
my $matchstr = quotemeta($tomcatdir);
while (`ps ax` =~ m/\/java.*$matchstr/) {
print "waiting for tomcat to go away...\n";
sleep(1);
}
print "wiping out the cache directory so our CSS/JS gets reloaded...\n";
`rm -rf $tomcatdir/webapps/ROOT/cache`;
}
sub tomcat_start {
print "starting tomcat...\n";
`$tomcatdir/bin/startup.sh`;
}
sub tomcat_restart {
my $nested = shift;
tomcat_stop();
$nested->() if $nested;
tomcat_start();
}
sub setmagnoliaresourcespath() {
my $success = 0;
print "creating magnolia properties file to point resources at git repo...\n";
`mkdir -p $magnoliapropertiespath`;
open(my $fh, '>', "$magnoliapropertiespath/magnolia.properties") or warn $!;
if (-w $fh) {
print $fh "magnolia.resources.dir=$gatodir/resources\n";
print $fh "magnolia.develop=true\n";
$success = 1;
} else {
print "Need write permission, try sudo.\n";
}
close($fh);
return $success;
}
sub symlinkheavyresources {
print "symlinking heavy modules into $gatodir/resources...\n";
foreach my $hm (@heavymodules) {
`ln -s $gatodir/$hm/src/main/resources/$hm $gatodir/resources/$hm` unless -e "$gatodir/resources/$hm";
}
}
sub resetdata {
print "resetting all data...\n";
`mysql -u root -e "DROP DATABASE IF EXISTS magnolia; CREATE DATABASE magnolia"`;
`rm -rf $magrepopath/magnolia`;
}
sub restoredata {
resetdata();
restoremagrepositories();
restoremysql();
}
sub cleanwebapp {
print "removing old webapp...\n";
`rm -rf $tomcatdir/webapps/ROOT*`;
}
sub buildedge {
symlinkheavyresources();
print "building full war...\n";
chdir($gatodir);
buildany();
}
sub buildmodule {
my $module = shift;
print "building individual module $module...\n";
chdir($gatodir.'/'.$module);
buildany();
}
sub buildany {
my $output = `mvn clean install 2>&1`;
if ($output =~ m/FAILURE/) { print $output."\n"; exit; }
}
sub installwar {
my $warpath = shift;
print "copying war...\n";
`cp $warpath $tomcatdir/webapps/ROOT.war`;
`mvn clean`;
}
sub replacemodule {
my $module = shift;
print "removing old $module jar...\n";
`rm $tomcatdir/webapps/ROOT/WEB-INF/lib/$module*.jar`;
print "copying new $module jar to webapp...\n";
`cp $gatodir/$module/target/$module*.jar $tomcatdir/webapps/ROOT/WEB-INF/lib/`;
}
sub triggerbootstrap() {
print "initiating upgrade tasks...\n";
sleep(10);
`curl $urlbase/.magnolia/installer > /dev/null`;
`curl $urlbase/.magnolia/installer/start > /dev/null`;
}
sub waitforbootstrap() {
print "waiting for bootstrap process to finish...\n";
sleep(80);
}
sub backupmagrepositories {
print "copying current mag_repositories folder to $backupdir...\n";
`rm -rf $backupdir/magnolia`;
`cp -R $magrepopath/magnolia $backupdir/magnolia`;
}
sub backupmysql {
print "archiving mysql database 'magnolia'...\n";
`mysqldump -u root --add-drop-table --extended-insert magnolia > $backupdir/magnolia.sql`
}
sub restoremagrepositories {
print "copying backed up mag_repositories folder into place...\n";
`cp -R $backupdir/magnolia $magrepopath/magnolia`;
}
sub restoremysql {
print "restoring mysql data...\n";
`mysql -u root magnolia < $backupdir/magnolia.sql`;
}