Guest User

Untitled

a guest
Mar 15th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <Perl>
  2. use DBI;
  3. use strict;
  4. </Perl>
  5.  
  6. <Perl>
  7.  
  8. # The domain these virtual hosts will be running on
  9. my $service_domain = '.squadlist.co.uk';
  10.  
  11. # Connect to the database and retrieve a list of instances which need to be configured as virtualhosts
  12. 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";
  13. my $querystring = qq{
  14. select instance, user, password from instances
  15. order by instance
  16. };
  17. my $sth = $dbh->prepare($querystring);
  18. $sth->execute();
  19.  
  20. # Loop through each instance, creating it's apache config
  21. while (my $row = $sth->fetchrow_hashref()) {
  22.  
  23. my $instance = $row->{'instance'};
  24. my $user = $row->{'user'};
  25. my $password = $row{'password'};
  26. my $hostname = $instance.$service_domain;
  27.  
  28. # Write configuration for the virtualhost directly into apache
  29. $PerlConfig .= qq {
  30.  
  31. <VirtualHost $hostname:80>
  32.  
  33. ServerAdmin support@squadlist.co.uk
  34. DocumentRoot /home/www/Sites/squadlist.co.uk/src
  35. ServerName $hostname
  36.  
  37. CustomLog /var/log/apache2/$hostname-access_log combined
  38. ErrorLog /var/log/apache2/$hostname-error.log
  39.  
  40. SetEnv DATABASE_NAME $instance\_squadlist
  41. SetEnv DATABASE_USER $user
  42. SetEnv DATABASE_PASSWORD $password
  43. </VirtualHost>
  44. };
  45.  
  46. }
  47.  
  48. $sth->finish();
  49. $dbh->disconnect();
  50. </Perl>
Add Comment
Please, Sign In to add comment