Skip to content

Commit

Permalink
fix cpan/backpan mirrors to be up when app is down
Browse files Browse the repository at this point in the history
This also adds appropriate tasks to start/stop maintenance mode.

Refs cpan-testers/cpantesters-project#17
  • Loading branch information
preaction committed Oct 19, 2016
1 parent e5636a5 commit 4313225
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 88 deletions.
49 changes: 48 additions & 1 deletion Rexfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ L<Rex|http://rexify.org>
use Rex -feature => [ 1.4 ];
use Rex::Commands::Sync;
use Term::ReadKey;
use File::Basename qw( basename );

#######################################################################
# Groups
Expand Down Expand Up @@ -84,6 +85,13 @@ set www_dirs => {
reports => '/media/web/www/reports/html',
};

set www_app_config_files => [qw(
perl.org.conf
cpantesters.org.conf
)];

set www_maintenance_config_file => '000-maintenance.conf';

#######################################################################
# Environments
# The Vagrant VM for development purposes
Expand Down Expand Up @@ -176,8 +184,12 @@ task deploy_www_config =>
Rex::Logger::info( "Syncing apache configs" );
#sync_up 'etc/apache2/conf', '/etc/apache2/conf-available';
#run 'a2enconf ' . $_ for qw( log );
run 'a2dissite ' . $_ for split ' ', run 'ls -l /etc/apache2/sites-available';
sync_up 'etc/apache2/vhost', '/etc/apache2/sites-available';
run 'a2ensite ' . $_ for qw( 100-perl.org 300-cpantesters 443-cpantesters );
run 'a2ensite ' . $_
for grep { $_ ne get 'www_maintenance_config_file' }
map basename,
glob 'etc/apache2/vhost/*';
Rex::Logger::info( 'Enabling apache modules' );
run 'a2enmod ' . $_ for qw( remoteip );
Rex::Logger::info( "Restarting apache service" );
Expand Down Expand Up @@ -337,6 +349,41 @@ task deploy_monitor =>
};
};

desc 'Start maintenance mode';
task 'start_maintenance' =>
group => [qw( www )],
sub {
ensure_sudo_password();
sudo sub {
Rex::Logger::info( 'Syncing maintenance site' );
run 'mkdir -p /var/www/maintenance';
sync_up 'var/www/maintenance', '/var/www/maintenance';
Rex::Logger::info( 'Disabling app sites' );
run 'a2dissite ' . $_ for @{ get 'www_app_config_files' };
Rex::Logger::info( 'Enabling maintenance site' );
run 'a2ensite ' . get 'www_maintenance_config_file';
Rex::Logger::info( 'Restarting apache' );
service apache2 => 'reload';
# XXX: Purge the Fastly cache
}
};

desc 'Stop maintenance mode';
task 'stop_maintenance' =>
group => [qw( www )],
sub {
ensure_sudo_password();
sudo sub {
Rex::Logger::info( 'Enabling app sites' );
run 'a2ensite ' . $_ for @{ get 'www_app_config_files' };
Rex::Logger::info( 'Disabling maintenance site' );
run 'a2dissite ' . get 'www_maintenance_config_file';
Rex::Logger::info( 'Restarting apache' );
service apache2 => 'reload';
# XXX: Purge the Fastly cache
}
};

#######################################################################
# Subroutines

Expand Down
12 changes: 12 additions & 0 deletions etc/apache2/vhost/000-maintenance.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# This config file shows a maintenance site as a default virtual host.
# This file must come first in alphabetical order.

NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/maintenance

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
49 changes: 0 additions & 49 deletions etc/apache2/vhost/443-cpantesters.conf

This file was deleted.

20 changes: 20 additions & 0 deletions etc/apache2/vhost/backpan.cpantesters.org.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# This backpan site is used by neilb's CPAN reports
# (http://neilb.org/cpan-regulars/)

<VirtualHost 212.110.173.51:80>
ServerName backpan.cpantesters.org
ServerAdmin [email protected]
DocumentRoot /home/ftp/BACKPAN
<Directory /home/ftp/BACKPAN>
Options +Indexes
Require all granted
</Directory>

# Disable CGI scripts
RemoveHandler .cgi .pl

ErrorLog /var/www/logs/backpan-error.log
CustomLog /var/www/logs/backpan-access.log combined
</VirtualHost>

17 changes: 17 additions & 0 deletions etc/apache2/vhost/cpan.cpantesters.org.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

<VirtualHost 212.110.173.51:80>
ServerName cpan.cpantesters.org
ServerAdmin [email protected]
DocumentRoot /home/ftp/CPAN
<Directory /home/ftp/CPAN>
Options +Indexes
Require all granted
</Directory>

# Disable CGI scripts
RemoveHandler .cgi .pl

ErrorLog /var/www/logs/cpan-error.log
CustomLog /var/www/logs/cpan-access.log combined
</VirtualHost>

Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
#NameVirtualHost 212.110.173.51

<VirtualHost 212.110.173.51:80>
ServerName cpan.cpantesters.org
ServerAdmin [email protected]
DocumentRoot /home/ftp/CPAN
<Directory /home/ftp/CPAN>
Options +Indexes
Require all granted
</Directory>

# Disable CGI scripts
RemoveHandler .cgi .pl

ErrorLog /var/www/logs/cpan-error.log
CustomLog /var/www/logs/cpan-access.log combined
</VirtualHost>

<VirtualHost 212.110.173.51:80>
ServerName backpan.cpantesters.org
ServerAdmin [email protected]
DocumentRoot /home/ftp/BACKPAN
<Directory /home/ftp/BACKPAN>
Options +Indexes
Require all granted
</Directory>

# Disable CGI scripts
RemoveHandler .cgi .pl

ErrorLog /var/www/logs/backpan-error.log
CustomLog /var/www/logs/backpan-access.log combined
</VirtualHost>
# This config file contains all the sites for the CPAN Testers
# application. Disabling this config will disable CPAN Testers (like,
# for scheduled maintenance)

<VirtualHost 212.110.173.51:80>
ServerName pass.cpantesters.org
Expand Down Expand Up @@ -146,13 +117,50 @@
CustomLog /var/www/logs/reports-access.log combined
</VirtualHost>

<VirtualHost 212.110.173.51:80>
ServerName test.cpantesters.org
ServerAlias *.cpantesters.org
<VirtualHost 212.110.173.51:443>
ServerName prefs.cpantesters.org
ServerAdmin [email protected]
DocumentRoot /var/www/downtime
DocumentRoot /var/www/cpanprefs/html

ErrorLog /var/www/logs/downtime-error.log
CustomLog /var/www/logs/downtime-access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/prefs/prefs_cpantesters_org.crt
SSLCertificateKeyFile /etc/apache2/ssl/prefs/prefs.cpantesters.org.key
SSLCertificateChainFile /etc/apache2/ssl/prefs/prefs.cpantesters.org.ca-bundle

RewriteEngine on
RewriteRule ^.*(php)$ /cgi-bin/pages.cgi?act=error-badcmd [PT]
RewriteRule ^/?$ /cgi-bin/pages.cgi [PT]
ScriptAlias /cgi-bin/ /var/www/cpanprefs/cgi-bin/
Options +ExecCGI
ErrorLog /var/www/logs/cpanprefs-error.log
CustomLog /var/www/logs/cpanprefs-access.log combined
</VirtualHost>

<VirtualHost 212.110.173.51:443>
ServerName admin.cpantesters.org
ServerAdmin [email protected]
DocumentRoot /var/www/cpanadmin/html

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/admin/admin_cpantesters_org.crt
SSLCertificateKeyFile /etc/apache2/ssl/admin/admin.cpantesters.org.key
SSLCertificateChainFile /etc/apache2/ssl/admin/admin.cpantesters.org.ca-bundle

RewriteEngine on
RewriteRule ^.*(php)$ /cgi-bin/pages.cgi?act=error-badcmd [PT]
RewriteRule ^/?$ /cgi-bin/pages.cgi [PT]

RewriteRule ^/author/testers$ /cgi-bin/pages.cgi?act=author-testers [PT]
RewriteRule ^/author/testers/(.*)$ /cgi-bin/pages.cgi?act=author-testers&letter=$1 [PT]
RewriteRule ^/author/tester/(\d+)$ /cgi-bin/pages.cgi?act=author-tester&testerid=$1 [PT]
RewriteRule ^/author/tester/(\d+)/(prev|next)/(.*)$ /cgi-bin/pages.cgi?act=author-tester&testerid=$1&$2=$3 [PT]
RewriteRule ^/tester/edit$ /cgi-bin/pages.cgi?act=tester-edit&%{QUERY_STRING} [PT]
RewriteRule ^/(tester|user)(-confirm)/(.*)$ /cgi-bin/pages.cgi?act=$1$2&code=$3 [PT]
RewriteRule ^/([a-z]+)\-([a-z]+)/?$ /cgi-bin/pages.cgi?act=$1-$2 [PT]

ScriptAlias /cgi-bin/ /var/www/cpanadmin/cgi-bin/
Options +ExecCGI
ErrorLog /var/www/logs/cpanadmin-error.log
CustomLog /var/www/logs/cpanadmin-access.log combined
</VirtualHost>

24 changes: 24 additions & 0 deletions etc/apache2/vhost/perl.org.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#NameVirtualHost 212.110.173.51:80

<VirtualHost 212.110.173.51:80>
ServerName cpantesters.perl.org
ServerAdmin [email protected]
DocumentRoot /var/www/downtime

RedirectMatch permanent .* http://static.cpantesters.org

ErrorLog /var/www/logs/perlorg-error.log
CustomLog /var/www/logs/perlorg-access.log combined
</VirtualHost>

<VirtualHost 212.110.173.51:80>
ServerName testers.cpan.org
ServerAdmin [email protected]
DocumentRoot /var/www/downtime

RedirectMatch permanent .* http://static.cpantesters.org

ErrorLog /var/www/logs/cpanorg-error.log
CustomLog /var/www/logs/cpanorg-access.log combined
</VirtualHost>

6 changes: 6 additions & 0 deletions var/www/maintenance/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

<h1>Down for Maintenance</h1>

<p>CPAN Testers is temporarily down for maintenance: The database tables
are being repaired. We hope to be back up by Saturday, October 22
2016.</p>

0 comments on commit 4313225

Please sign in to comment.