| Line 2... |
Line 2... |
| 2 |
use strict;
|
2 |
use strict;
|
| 3 |
use DBI;
|
3 |
use DBI;
|
| 4 |
use List::Util 'shuffle';
|
4 |
use List::Util 'shuffle';
|
| Line 5... |
Line 5... |
| 5 |
|
5 |
|
| 6 |
my $host_name = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "localhost" : "192.168.1.5";
|
- |
|
| 7 |
my $db_name = "rollerco_vorc";
|
- |
|
| 8 |
my $dsn = "DBI:mysql:host=$host_name;database=$db_name";
|
6 |
my $host_name = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "localhost" : "192.168.1.5";
|
| 9 |
$ENV{HOME} = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco" : "/tmp";
|
7 |
$ENV{HOME} = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco" : "/tmp";
|
| Line 10... |
Line 8... |
| 10 |
# $ENV{HOME} = "/tmp" unless $ENV{HOME};
|
8 |
# $ENV{HOME} = "/tmp" unless $ENV{HOME};
|
| 11 |
|
9 |
|
| - |
|
10 |
# Connect to MySQL server, using hardwired name and password
|
| - |
|
11 |
sub connect {
|
| - |
|
12 |
my $DB = shift // "vorc";
|
| - |
|
13 |
|
| - |
|
14 |
my $db_name = "rollerco_".$DB;
|
| 12 |
# Connect to MySQL server, using hardwired name and password
|
15 |
my $dsn = "DBI:mysql:host=$host_name;database=$db_name";
|
| Line 13... |
Line 16... |
| 13 |
sub connect {
|
16 |
|
| 14 |
return connect_with_option_file() unless !(-f $ENV{HOME}.'/.my.cnf');
|
17 |
return connect_with_option_file($dsn) unless !(-f $ENV{HOME}.'/.my.cnf');
|
| 15 |
|
18 |
|
| Line 16... |
Line 19... |
| 16 |
warn "using hardcoded password (not $ENV{HOME}/.my.cnf)...";
|
19 |
warn "using hardcoded password (not $ENV{HOME}/.my.cnf)...";
|
| 17 |
return (DBI->connect ($dsn, "root", "********", {PrintError => 0, RaiseError => 0}) or db_error ($DBI::errstr));
|
20 |
return (DBI->connect ($dsn, "root", "Jopy666!", {PrintError => 0, RaiseError => 0}) or db_error ($DBI::errstr));
|
| 18 |
}
|
21 |
}
|
| 19 |
|
22 |
|
| - |
|
23 |
# Connect to MySQL server, using name and password from the current
|
| - |
|
24 |
# user's ~/.my.cnf option file. The mysql_read_default_file option,
|
| 20 |
# Connect to MySQL server, using name and password from the current
|
25 |
# when added to the DSN, specifies which option file to read.
|
| - |
|
26 |
sub connect_with_option_file {
|
| 21 |
# user's ~/.my.cnf option file. The mysql_read_default_file option,
|
27 |
my $dsn = shift;
|
| 22 |
# when added to the DSN, specifies which option file to read.
|
28 |
|
| 23 |
sub connect_with_option_file {
|
29 |
$dsn .= ";mysql_read_default_file=$ENV{HOME}/.my.cnf";
|
| 24 |
$dsn .= ";mysql_read_default_file=$ENV{HOME}/.my.cnf";
|
30 |
|
| 25 |
for (shuffle qw(1 2 3 4 5)) {
|
31 |
for (shuffle qw(1 2 3 4 5)) {
|
| 26 |
# warn "Trying connection $_";
|
- |
|
| 27 |
my $connection = DBI->connect ($dsn.".$_", undef, undef, {PrintError => 0, RaiseError => 0});
|
- |
|
| - |
|
32 |
# warn "Trying connection $_";
|
| 28 |
return $connection unless !$connection;
|
33 |
my $connection = DBI->connect ($dsn.".$_", undef, undef, {PrintError => 0, RaiseError => 0});
|
| 29 |
}
|
34 |
return $connection unless !$connection;
|
| Line 30... |
Line 35... |
| 30 |
my $active_users = `/bin/ls -1 /home3/rollerco/vorc_sessions/active/ | /usr/bin/wc -l`; chomp $active_users;
|
35 |
}
|
| 31 |
warn "DB OUT OF CONNECTIONS WITH ACTIVE USERS: $active_users";
|
36 |
|