Skip to content

Commit d8e64db

Browse files
author
MySQL Build Team
committed
fixing Bug #34984 [patch] mysqld_multi to support reload option
1 parent a88d42a commit d8e64db

File tree

1 file changed

+99
-8
lines changed

1 file changed

+99
-8
lines changed

scripts/mysqld_multi.sh

+99-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use Getopt::Long;
2121
use POSIX qw(strftime getcwd);
22+
use File::Path qw(mkpath);
2223

2324
$|=1;
2425
$VER="2.16";
@@ -123,6 +124,7 @@ sub main
123124
usage() if (!defined($ARGV[0]) ||
124125
(!($ARGV[0] =~ m/^start$/i) &&
125126
!($ARGV[0] =~ m/^stop$/i) &&
127+
!($ARGV[0] =~ m/^reload$/i) &&
126128
!($ARGV[0] =~ m/^report$/i)));
127129

128130
if (!$opt_no_log)
@@ -136,7 +138,7 @@ sub main
136138
print strftime "%a %b %e %H:%M:%S %Y", localtime;
137139
print "\n";
138140
}
139-
if ($ARGV[0] =~ m/^start$/i)
141+
if (($ARGV[0] =~ m/^start$/i) || ($ARGV[0] =~ m/^reload$/i))
140142
{
141143
if (!defined(($mysqld= my_which($opt_mysqld))) && $opt_verbose)
142144
{
@@ -145,7 +147,11 @@ sub main
145147
print "This is OK, if you are using option \"mysqld=...\" in ";
146148
print "groups [mysqldN] separately for each.\n\n";
147149
}
148-
start_mysqlds();
150+
if ($ARGV[0] =~ m/^start$/i) {
151+
start_mysqlds();
152+
} elsif ($ARGV[0] =~ m/^reload$/i) {
153+
reload_mysqlds();
154+
}
149155
}
150156
else
151157
{
@@ -301,6 +307,39 @@ sub start_mysqlds()
301307
$com= "$mysqld";
302308
for ($j = 0, $tmp= ""; defined($options[$j]); $j++)
303309
{
310+
if ("--datadir=" eq substr($options[$j], 0, 10)) {
311+
$datadir = $options[$j];
312+
$datadir =~ s/\-\-datadir\=//;
313+
eval { mkpath($datadir) };
314+
if ($@) {
315+
print "FATAL ERROR: Cannot create data directory $datadir: $!\n";
316+
exit(1);
317+
}
318+
if (! -d $datadir."/mysql") {
319+
if (-w $datadir) {
320+
print "\n\nInstalling new database in $datadir\n\n";
321+
$install_cmd="@bindir@/mysql_install_db ";
322+
$install_cmd.="--user=mysql ";
323+
$install_cmd.="--datadir=$datadir";
324+
system($install_cmd);
325+
} else {
326+
print "\n";
327+
print "FATAL ERROR: Tried to create mysqld under group [$groups[$i]],\n";
328+
print "but the data directory is not writable.\n";
329+
print "data directory used: $datadir\n";
330+
exit(1);
331+
}
332+
}
333+
334+
if (! -d $datadir."/mysql") {
335+
print "\n";
336+
print "FATAL ERROR: Tried to start mysqld under group [$groups[$i]],\n";
337+
print "but no data directory was found or could be created.\n";
338+
print "data directory used: $datadir\n";
339+
exit(1);
340+
}
341+
}
342+
304343
if ("--mysqladmin=" eq substr($options[$j], 0, 13))
305344
{
306345
# catch this and ignore
@@ -365,6 +404,58 @@ sub start_mysqlds()
365404
}
366405

367406
####
407+
#### reload multiple servers
408+
####
409+
410+
sub reload_mysqlds()
411+
{
412+
my (@groups, $com, $tmp, $i, @options, $j);
413+
414+
if (!$opt_no_log)
415+
{
416+
w2log("\nReloading MySQL servers\n","$opt_log",0,0);
417+
}
418+
else
419+
{
420+
print "\nReloading MySQL servers\n";
421+
}
422+
@groups = &find_groups($groupids);
423+
for ($i = 0; defined($groups[$i]); $i++)
424+
{
425+
$mysqld_server = $mysqld;
426+
@options = defaults_for_group($groups[$i]);
427+
428+
for ($j = 0, $tmp= ""; defined($options[$j]); $j++)
429+
{
430+
if ("--mysqladmin=" eq substr($options[$j], 0, 13))
431+
{
432+
# catch this and ignore
433+
}
434+
elsif ("--mysqld=" eq substr($options[$j], 0, 9))
435+
{
436+
$options[$j] =~ s/\-\-mysqld\=//;
437+
$mysqld_server = $options[$j];
438+
}
439+
elsif ("--pid-file=" eq substr($options[$j], 0, 11))
440+
{
441+
$options[$j] =~ s/\-\-pid-file\=//;
442+
$pid_file = $options[$j];
443+
}
444+
}
445+
$com = "killproc -p $pid_file -HUP $mysqld_server";
446+
system($com);
447+
448+
$com = "touch $pid_file";
449+
system($com);
450+
}
451+
if (!$i && !$opt_no_log)
452+
{
453+
w2log("No MySQL servers to be reloaded (check your GNRs)",
454+
"$opt_log", 0, 0);
455+
}
456+
}
457+
458+
###
368459
#### stop multiple servers
369460
####
370461

@@ -727,7 +818,7 @@ sub usage
727818
$my_progname version $VER by Jani Tolonen
728819
729820
Description:
730-
$my_progname can be used to start, or stop any number of separate
821+
$my_progname can be used to start, reload, or stop any number of separate
731822
mysqld processes running in different TCP/IP ports and UNIX sockets.
732823
733824
$my_progname can read group [mysqld_multi] from my.cnf file. You may
@@ -745,16 +836,16 @@ integer starting from 1. These groups should be the same as the regular
745836
[mysqld] group, but with those port, socket and any other options
746837
that are to be used with each separate mysqld process. The number
747838
in the group name has another function; it can be used for starting,
748-
stopping, or reporting any specific mysqld server.
839+
reloading, stopping, or reporting any specific mysqld server.
749840
750-
Usage: $my_progname [OPTIONS] {start|stop|report} [GNR,GNR,GNR...]
751-
or $my_progname [OPTIONS] {start|stop|report} [GNR-GNR,GNR,GNR-GNR,...]
841+
Usage: $my_progname [OPTIONS] {start|reload|stop|report} [GNR,GNR,GNR...]
842+
or $my_progname [OPTIONS] {start|reload|stop|report} [GNR-GNR,GNR,GNR-GNR,...]
752843
753-
The GNR means the group number. You can start, stop or report any GNR,
844+
The GNR means the group number. You can start, reload, stop or report any GNR,
754845
or several of them at the same time. (See --example) The GNRs list can
755846
be comma separated or a dash combined. The latter means that all the
756847
GNRs between GNR1-GNR2 will be affected. Without GNR argument all the
757-
groups found will either be started, stopped, or reported. Note that
848+
groups found will either be started, reloaded, stopped, or reported. Note that
758849
syntax for specifying GNRs must appear without spaces.
759850
760851
Options:

0 commit comments

Comments
 (0)