#!/usr/bin/perl -I /usr/cytanet/admin/advanced_web  -I /usr/cytanet/admin/etc 
#
# iptables      Start iptables firewall
#
# chkconfig: 35 98 92
# description:  Mount mysql customers partition
#


use customer_conf;
use strict;
use DBI;







my $dbh;



$dbh = DBI->connect($CUSTOMER_CONF'dbase,$CUSTOMER_CONF'username,$CUSTOMER_CONF'password) ||
                 die( "Can't connect to database $CUSTOMER_CONF'dbase $DBI::errstr");
        $dbh->{PrintError}=0;






my $entries = &get_mysql_entries;

for my $i (0 .. $#$entries) { 
 	my $block= '/dev/Hosted/' . $entries->[$i]->{'username'};
	my $dir='/var/lib/mysql/' . $entries->[$i]->{'username'};
	 system("/bin/mount -i $block $dir");
	print "/bin/mount $block $dir \n";
}







sub get_mysql_entries {
        shift if ( ref($_[0]) );
        my @arr;



        my $sth = $dbh->prepare
        ("
                SELECT *  FROM web_services
                WHERE apache='new_virt'
                and mysql='y'


        ");

        $sth->execute or die( "get_table $_[0] $_[1] $_[2]: $DBI::errstr ");
        while ( my $row = $sth->fetchrow_hashref ) {
                push @arr ,$row;
                }
        $sth->finish;
        return(\@arr);
}
