19
19
20
20
use Getopt::Long;
21
21
use POSIX qw( strftime getcwd) ;
22
+ use File::Path qw( mkpath) ;
22
23
23
24
$| =1;
24
25
$VER =" 2.16" ;
@@ -123,6 +124,7 @@ sub main
123
124
usage() if (!defined ($ARGV [0]) ||
124
125
(!($ARGV [0] =~ m / ^start$ / i ) &&
125
126
!($ARGV [0] =~ m / ^stop$ / i ) &&
127
+ !($ARGV [0] =~ m / ^reload$ / i ) &&
126
128
!($ARGV [0] =~ m / ^report$ / i )));
127
129
128
130
if (!$opt_no_log )
@@ -136,7 +138,7 @@ sub main
136
138
print strftime " %a %b %e %H :%M :%S %Y " , localtime ;
137
139
print " \n " ;
138
140
}
139
- if ($ARGV [0] =~ m / ^start$ / i )
141
+ if (( $ARGV [0] =~ m / ^start$ / i ) || ( $ARGV [0] =~ m / ^reload $ / i ) )
140
142
{
141
143
if (!defined (($mysqld = my_which($opt_mysqld ))) && $opt_verbose )
142
144
{
@@ -145,7 +147,11 @@ sub main
145
147
print " This is OK, if you are using option \" mysqld=...\" in " ;
146
148
print " groups [mysqldN] separately for each.\n\n " ;
147
149
}
148
- start_mysqlds();
150
+ if ($ARGV [0] =~ m / ^start$ / i ) {
151
+ start_mysqlds();
152
+ } elsif ($ARGV [0] =~ m / ^reload$ / i ) {
153
+ reload_mysqlds();
154
+ }
149
155
}
150
156
else
151
157
{
@@ -301,6 +307,39 @@ sub start_mysqlds()
301
307
$com = " $mysqld " ;
302
308
for ($j = 0, $tmp = " " ; defined ($options [$j ]); $j ++)
303
309
{
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\n Installing 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
+
304
343
if (" --mysqladmin=" eq substr ($options [$j ], 0, 13))
305
344
{
306
345
# catch this and ignore
@@ -365,6 +404,58 @@ sub start_mysqlds()
365
404
}
366
405
367
406
# ###
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(" \n Reloading MySQL servers\n " ," $opt_log " ,0,0);
417
+ }
418
+ else
419
+ {
420
+ print " \n Reloading 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
+ # ##
368
459
# ### stop multiple servers
369
460
# ###
370
461
@@ -727,7 +818,7 @@ sub usage
727
818
$my_progname version $VER by Jani Tolonen
728
819
729
820
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
731
822
mysqld processes running in different TCP/IP ports and UNIX sockets.
732
823
733
824
$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
745
836
[mysqld] group, but with those port, socket and any other options
746
837
that are to be used with each separate mysqld process. The number
747
838
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.
749
840
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,...]
752
843
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,
754
845
or several of them at the same time. (See --example) The GNRs list can
755
846
be comma separated or a dash combined. The latter means that all the
756
847
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
758
849
syntax for specifying GNRs must appear without spaces.
759
850
760
851
Options:
0 commit comments