Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Perl>
- use DBI;
- use strict;
- </Perl>
- <Perl>
- # The domain these virtual hosts will be running on
- my $service_domain = '.squadlist.co.uk';
- # Connect to the database and retrieve a list of instances which need to be configured as virtualhosts
- my $dbh = DBI->connect('DBI:mysql:squadlist_instances;host=localhost', 'apache_read_only', 'ro_password') or die "could not connect to the database:$dbh->errstr\n";
- my $querystring = qq{
- select instance, user, password from instances
- order by instance
- };
- my $sth = $dbh->prepare($querystring);
- $sth->execute();
- # Loop through each instance, creating it's apache config
- while (my $row = $sth->fetchrow_hashref()) {
- my $instance = $row->{'instance'};
- my $user = $row->{'user'};
- my $password = $row{'password'};
- my $hostname = $instance.$service_domain;
- # Write configuration for the virtualhost directly into apache
- $PerlConfig .= qq {
- <VirtualHost $hostname:80>
- ServerAdmin support@squadlist.co.uk
- DocumentRoot /home/www/Sites/squadlist.co.uk/src
- ServerName $hostname
- CustomLog /var/log/apache2/$hostname-access_log combined
- ErrorLog /var/log/apache2/$hostname-error.log
- SetEnv DATABASE_NAME $instance\_squadlist
- SetEnv DATABASE_USER $user
- SetEnv DATABASE_PASSWORD $password
- </VirtualHost>
- };
- }
- $sth->finish();
- $dbh->disconnect();
- </Perl>
Add Comment
Please, Sign In to add comment