- Added --verbose
- Made some of the warnings under --verbose only - Added possibility to add mysqladmin= under groups [mysqldN] mysqladmin=... is no longer mandatory under [mysqld_multi] - Made 'start', 'stop' and 'report' commands truly case-insensitive - Some other common places code merge and cleanup
This commit is contained in:
parent
84ad2489ec
commit
412f9da8c6
@ -4,7 +4,7 @@ use Getopt::Long;
|
|||||||
use POSIX qw(strftime);
|
use POSIX qw(strftime);
|
||||||
|
|
||||||
$|=1;
|
$|=1;
|
||||||
$VER="2.9";
|
$VER="2.10";
|
||||||
|
|
||||||
$opt_config_file = undef();
|
$opt_config_file = undef();
|
||||||
$opt_example = 0;
|
$opt_example = 0;
|
||||||
@ -18,6 +18,7 @@ $opt_tcp_ip = 0;
|
|||||||
$opt_user = "root";
|
$opt_user = "root";
|
||||||
$opt_version = 0;
|
$opt_version = 0;
|
||||||
$opt_silent = 0;
|
$opt_silent = 0;
|
||||||
|
$opt_verbose = 0;
|
||||||
|
|
||||||
my $my_print_defaults_exists= 1;
|
my $my_print_defaults_exists= 1;
|
||||||
my $logdir= undef();
|
my $logdir= undef();
|
||||||
@ -42,13 +43,10 @@ sub main
|
|||||||
{
|
{
|
||||||
# We can't throw out yet, since --version, --help, or --example may
|
# We can't throw out yet, since --version, --help, or --example may
|
||||||
# have been given
|
# have been given
|
||||||
if (!$opt_silent)
|
print "WARNING! my_print_defaults command not found!\n";
|
||||||
{
|
print "Please make sure you have this command available and\n";
|
||||||
print "WARNING! my_print_defaults command not found!\n";
|
print "in your path. The command is available from the latest\n";
|
||||||
print "Please make sure you have this command available and\n";
|
print "MySQL distribution.\n";
|
||||||
print "in your path. The command is available from the latest\n";
|
|
||||||
print "MySQL distribution.\n";
|
|
||||||
}
|
|
||||||
$my_print_defaults_exists= 0;
|
$my_print_defaults_exists= 0;
|
||||||
}
|
}
|
||||||
if ($my_print_defaults_exists)
|
if ($my_print_defaults_exists)
|
||||||
@ -80,7 +78,7 @@ sub main
|
|||||||
}
|
}
|
||||||
GetOptions("help","example","version","mysqld=s","mysqladmin=s",
|
GetOptions("help","example","version","mysqld=s","mysqladmin=s",
|
||||||
"config-file=s","user=s","password=s","log=s","no-log","tcp-ip",
|
"config-file=s","user=s","password=s","log=s","no-log","tcp-ip",
|
||||||
"silent")
|
"silent","verbose")
|
||||||
|| die "Wrong option! See $my_progname --help for detailed information!\n";
|
|| die "Wrong option! See $my_progname --help for detailed information!\n";
|
||||||
|
|
||||||
init_log() if (!defined($opt_log));
|
init_log() if (!defined($opt_log));
|
||||||
@ -91,11 +89,6 @@ sub main
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
example() if ($opt_example);
|
example() if ($opt_example);
|
||||||
if (!defined(($mysqladmin = my_which($opt_mysqladmin))))
|
|
||||||
{
|
|
||||||
print "Couldn't find the mysqladmin binary! Tried: $opt_mysqladmin\n";
|
|
||||||
$flag_exit=1;
|
|
||||||
}
|
|
||||||
usage() if ($opt_help);
|
usage() if ($opt_help);
|
||||||
if ($flag_exit)
|
if ($flag_exit)
|
||||||
{
|
{
|
||||||
@ -111,9 +104,9 @@ sub main
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
usage() if (!defined($ARGV[0]) ||
|
usage() if (!defined($ARGV[0]) ||
|
||||||
($ARGV[0] ne 'start' && $ARGV[0] ne 'START' &&
|
(!($ARGV[0] =~ m/^start$/i) &&
|
||||||
$ARGV[0] ne 'stop' && $ARGV[0] ne 'STOP' &&
|
!($ARGV[0] =~ m/^stop$/i) &&
|
||||||
$ARGV[0] ne 'report' && $ARGV[0] ne 'REPORT'));
|
!($ARGV[0] =~ m/^report$/i)));
|
||||||
|
|
||||||
if (!$opt_no_log)
|
if (!$opt_no_log)
|
||||||
{
|
{
|
||||||
@ -126,25 +119,34 @@ sub main
|
|||||||
print strftime "%a %b %e %H:%M:%S %Y", localtime;
|
print strftime "%a %b %e %H:%M:%S %Y", localtime;
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
}
|
||||||
if ($ARGV[0] eq 'report' || $ARGV[0] eq 'REPORT')
|
if ($ARGV[0] =~ m/^start$/i)
|
||||||
{
|
{
|
||||||
report_mysqlds();
|
if (!defined(($mysqld= my_which($opt_mysqld))) && $opt_verbose)
|
||||||
}
|
|
||||||
elsif ($ARGV[0] eq 'start' || $ARGV[0] eq 'START')
|
|
||||||
{
|
|
||||||
if (!defined(($mysqld = my_which($opt_mysqld))) && !$opt_silent)
|
|
||||||
{
|
{
|
||||||
print "WARNING: Couldn't find the default mysqld binary. ";
|
print "WARNING: Couldn't find the default mysqld binary.\n";
|
||||||
print "Tried: $opt_mysqld\n";
|
print "Tried: $opt_mysqld\n";
|
||||||
print "This is OK, if you are using option --mysqld= under groups";
|
print "This is OK, if you are using option \"mysqld=...\" in ";
|
||||||
print " [mysqldN] separately for each.\n";
|
print "groups [mysqldN] separately for each.\n\n";
|
||||||
print "(Disable warnings with --silent)\n";
|
|
||||||
}
|
}
|
||||||
start_mysqlds();
|
start_mysqlds();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stop_mysqlds();
|
if (!defined(($mysqladmin= my_which($opt_mysqladmin))) && $opt_verbose)
|
||||||
|
{
|
||||||
|
print "WARNING: Couldn't find the default mysqladmin binary.\n";
|
||||||
|
print "Tried: $opt_mysqladmin\n";
|
||||||
|
print "This is OK, if you are using option \"mysqladmin=...\" in ";
|
||||||
|
print "groups [mysqldN] separately for each.\n\n";
|
||||||
|
}
|
||||||
|
if ($ARGV[0] =~ m/^report$/i)
|
||||||
|
{
|
||||||
|
report_mysqlds();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stop_mysqlds();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +198,7 @@ sub init_log
|
|||||||
|
|
||||||
sub report_mysqlds
|
sub report_mysqlds
|
||||||
{
|
{
|
||||||
my (@groups, $com, $i, @options, $j, $pec);
|
my (@groups, $com, $i, @options, $pec);
|
||||||
|
|
||||||
print "Reporting MySQL servers\n";
|
print "Reporting MySQL servers\n";
|
||||||
if (!$opt_no_log)
|
if (!$opt_no_log)
|
||||||
@ -206,23 +208,7 @@ sub report_mysqlds
|
|||||||
@groups = &find_groups($groupids);
|
@groups = &find_groups($groupids);
|
||||||
for ($i = 0; defined($groups[$i]); $i++)
|
for ($i = 0; defined($groups[$i]); $i++)
|
||||||
{
|
{
|
||||||
$com = "my_print_defaults";
|
$com= get_mysqladmin_options($i, @groups);
|
||||||
$com.= defined($opt_config_file) ? " --config-file=$opt_config_file" : "";
|
|
||||||
$com.= " $groups[$i]";
|
|
||||||
@options = `$com`;
|
|
||||||
chop @options;
|
|
||||||
|
|
||||||
$com = "$mysqladmin -u $opt_user";
|
|
||||||
$com.= defined($opt_password) ? " -p$opt_password" : "";
|
|
||||||
$com.= $opt_tcp_ip ? " -h 127.0.0.1" : "";
|
|
||||||
for ($j = 0; defined($options[$j]); $j++)
|
|
||||||
{
|
|
||||||
if ((($options[$j] =~ m/^(\-\-socket\=)(.*)$/) && !$opt_tcp_ip) ||
|
|
||||||
($options[$j] =~ m/^(\-\-port\=)(.*)$/))
|
|
||||||
{
|
|
||||||
$com.= " $options[$j]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$com.= " ping >> /dev/null 2>&1";
|
$com.= " ping >> /dev/null 2>&1";
|
||||||
system($com);
|
system($com);
|
||||||
$pec = $? >> 8;
|
$pec = $? >> 8;
|
||||||
@ -261,7 +247,7 @@ sub report_mysqlds
|
|||||||
|
|
||||||
sub start_mysqlds()
|
sub start_mysqlds()
|
||||||
{
|
{
|
||||||
my (@groups, $com, $tmp, $i, @options, $j);
|
my (@groups, $com, $tmp, $i, @options, $j, $mysqld_found);
|
||||||
|
|
||||||
if (!$opt_no_log)
|
if (!$opt_no_log)
|
||||||
{
|
{
|
||||||
@ -285,7 +271,11 @@ sub start_mysqlds()
|
|||||||
$com= "$mysqld";
|
$com= "$mysqld";
|
||||||
for ($j = 0, $tmp= ""; defined($options[$j]); $j++)
|
for ($j = 0, $tmp= ""; defined($options[$j]); $j++)
|
||||||
{
|
{
|
||||||
if ("--mysqld=" eq substr($options[$j], 0, 9))
|
if ("--mysqladmin=" eq substr($options[$j], 0, 13))
|
||||||
|
{
|
||||||
|
# catch this and ignore
|
||||||
|
}
|
||||||
|
elsif ("--mysqld=" eq substr($options[$j], 0, 9))
|
||||||
{
|
{
|
||||||
$options[$j]=~ s/\-\-mysqld\=//;
|
$options[$j]=~ s/\-\-mysqld\=//;
|
||||||
$com= $options[$j];
|
$com= $options[$j];
|
||||||
@ -302,10 +292,10 @@ sub start_mysqlds()
|
|||||||
$com.= " &";
|
$com.= " &";
|
||||||
if (!$mysqld_found)
|
if (!$mysqld_found)
|
||||||
{
|
{
|
||||||
print "\n\n";
|
print "\n";
|
||||||
print "FATAL ERROR: Tried to start mysqld under group [$groups[$i]], ";
|
print "FATAL ERROR: Tried to start mysqld under group [$groups[$i]], ";
|
||||||
print "but no mysqld binary was found.\n";
|
print "but no mysqld binary was found.\n";
|
||||||
print "Please add --mysqld=... in group [mysqld_multi], or add it to ";
|
print "Please add \"mysqld=...\" in group [mysqld_multi], or add it to ";
|
||||||
print "group [$groups[$i]] separately.\n";
|
print "group [$groups[$i]] separately.\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -324,7 +314,7 @@ sub start_mysqlds()
|
|||||||
|
|
||||||
sub stop_mysqlds()
|
sub stop_mysqlds()
|
||||||
{
|
{
|
||||||
my (@groups, $com, $i, @options, $j);
|
my (@groups, $com, $i, @options);
|
||||||
|
|
||||||
if (!$opt_no_log)
|
if (!$opt_no_log)
|
||||||
{
|
{
|
||||||
@ -337,23 +327,7 @@ sub stop_mysqlds()
|
|||||||
@groups = &find_groups($groupids);
|
@groups = &find_groups($groupids);
|
||||||
for ($i = 0; defined($groups[$i]); $i++)
|
for ($i = 0; defined($groups[$i]); $i++)
|
||||||
{
|
{
|
||||||
$com = "my_print_defaults";
|
$com= get_mysqladmin_options($i, @groups);
|
||||||
$com.= defined($opt_config_file) ? " --config-file=$opt_config_file" : "";
|
|
||||||
$com.= " $groups[$i]";
|
|
||||||
@options = `$com`;
|
|
||||||
chop @options;
|
|
||||||
|
|
||||||
$com = "$mysqladmin -u $opt_user";
|
|
||||||
$com.= defined($opt_password) ? " -p$opt_password" : "";
|
|
||||||
$com.= $opt_tcp_ip ? " -h 127.0.0.1" : "";
|
|
||||||
for ($j = 0; defined($options[$j]); $j++)
|
|
||||||
{
|
|
||||||
if ((($options[$j] =~ m/^(\-\-socket\=)(.*)$/) && !$opt_tcp_ip) ||
|
|
||||||
($options[$j] =~ m/^(\-\-port\=)(.*)$/))
|
|
||||||
{
|
|
||||||
$com.= " $options[$j]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$com.= " shutdown";
|
$com.= " shutdown";
|
||||||
$com.= " >> $opt_log 2>&1" if (!$opt_no_log);
|
$com.= " >> $opt_log 2>&1" if (!$opt_no_log);
|
||||||
$com.= " &";
|
$com.= " &";
|
||||||
@ -366,6 +340,54 @@ sub stop_mysqlds()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
####
|
||||||
|
#### Sub function for mysqladmin option parsing
|
||||||
|
####
|
||||||
|
|
||||||
|
sub get_mysqladmin_options
|
||||||
|
{
|
||||||
|
my ($i, @groups)= @_;
|
||||||
|
my ($mysqladmin_found, $com, $tmp, $j);
|
||||||
|
|
||||||
|
$com = "my_print_defaults";
|
||||||
|
$com.= defined($opt_config_file) ? " --config-file=$opt_config_file" : "";
|
||||||
|
$com.= " $groups[$i]";
|
||||||
|
@options = `$com`;
|
||||||
|
chop @options;
|
||||||
|
|
||||||
|
$mysqladmin_found= 1; # The default
|
||||||
|
$mysqladmin_found= 0 if (!length($mysqladmin));
|
||||||
|
$com = "$mysqladmin";
|
||||||
|
$tmp = " -u $opt_user";
|
||||||
|
$tmp.= defined($opt_password) ? " -p$opt_password" : "";
|
||||||
|
$tmp.= $opt_tcp_ip ? " -h 127.0.0.1" : "";
|
||||||
|
for ($j = 0; defined($options[$j]); $j++)
|
||||||
|
{
|
||||||
|
if ("--mysqladmin=" eq substr($options[$j], 0, 13))
|
||||||
|
{
|
||||||
|
$options[$j]=~ s/\-\-mysqladmin\=//;
|
||||||
|
$com= $options[$j];
|
||||||
|
$mysqladmin_found= 1;
|
||||||
|
}
|
||||||
|
elsif ((($options[$j] =~ m/^(\-\-socket\=)(.*)$/) && !$opt_tcp_ip) ||
|
||||||
|
($options[$j] =~ m/^(\-\-port\=)(.*)$/))
|
||||||
|
{
|
||||||
|
$tmp.= " $options[$j]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$mysqladmin_found)
|
||||||
|
{
|
||||||
|
print "\n";
|
||||||
|
print "FATAL ERROR: Tried to use mysqladmin in group [$groups[$i]], ";
|
||||||
|
print "but no mysqladmin binary was found.\n";
|
||||||
|
print "Please add \"mysqladmin=...\" in group [mysqld_multi], or ";
|
||||||
|
print "in group [$groups[$i]].\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
$com.= $tmp;
|
||||||
|
return $com;
|
||||||
|
}
|
||||||
|
|
||||||
####
|
####
|
||||||
#### Find groups. Takes the valid group numbers as an argument, parses
|
#### Find groups. Takes the valid group numbers as an argument, parses
|
||||||
#### them, puts them in the ascending order, removes duplicates and
|
#### them, puts them in the ascending order, removes duplicates and
|
||||||
@ -702,6 +724,7 @@ Options:
|
|||||||
file is turned on.
|
file is turned on.
|
||||||
--password=... Password for user for mysqladmin.
|
--password=... Password for user for mysqladmin.
|
||||||
--silent Disable warnings.
|
--silent Disable warnings.
|
||||||
|
--verbose Be more verbose.
|
||||||
--tcp-ip Connect to the MySQL server(s) via the TCP/IP port instead
|
--tcp-ip Connect to the MySQL server(s) via the TCP/IP port instead
|
||||||
of the UNIX socket. This affects stopping and reporting.
|
of the UNIX socket. This affects stopping and reporting.
|
||||||
If a socket file is missing, the server may still be
|
If a socket file is missing, the server may still be
|
||||||
|
Loading…
x
Reference in New Issue
Block a user