| Server IP : 216.92.14.13 / Your IP : 216.73.216.171 Web Server : Apache System : Linux vps4089.pairvps.com 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 User : rmlac2fmr ( 1040637) PHP Version : 8.2.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /etc/ |
Upload File : |
#!/usr/bin/perl
#
# $Id: my.restart,v 1.14 2013/08/14 18:06:31 erik5 Exp $
=head1 my.restart
To restart all daemons at once just:
% ./my.restart -all
To restart a specific daemon, give a server
name as an argument:
% ./my.restart db49b.pair.com
=cut
use strict;
use Proc::Daemon;
use Getopt::Long;
use lib '/usr/pair/perl';
use Pair::DBServer::Conf qw(user_cnf_info server_cnf_info);
use Pair::Paths qw($PS $GREP $MYSQLD);
use Pair::Serverinfo 'service_enabled';
use Pair::Pidfile;
my $PIDFILE = '/etc/my.restart.pid';
Pair::Pidfile::maintain_pidfile($PIDFILE);
my %opt;
GetOptions (\%opt,"all|a","quiet|q","kill|k");
# Loop Settings
my $MAX_SLEEP = 600;
my $SLEEP_PER = 5;
my $SERVER = &server_cnf_info || die;
my $DAEMONS = grep(/^MYSQLD\d+$/,keys %$SERVER);
service_enabled('MYSQL') or die "MySQL not enabled!\n";
$opt{kill} = 1 if $0 =~ /kill/;
$opt{all} = 1 if $DAEMONS == 0;
#restart specific daemon
if (@ARGV) {
my $socket = $SERVER->{$ARGV[0]};
my ($conf_num) = ($socket =~ /sock(\d+)/i);
die "Unable to determine config file\n" unless $conf_num;
#kill current daemon if running
my $pid = &get_pid("my$conf_num.cnf");
if ($pid >= 2) {
kill('TERM',$pid) if $pid > 1;
sleep($SLEEP_PER);
}
if (&get_pid("my$conf_num.cnf")) {
warn "Failed to exit\n" unless $opt{quiet};
exit;
}
unless ( $opt{kill} || !service_enabled('MYSQL') ) {
Proc::Daemon::Init if $opt{quiet};
system("$MYSQLD --defaults-file=/etc/my$conf_num\.cnf &");
unless ($opt{quiet}) {
sleep 1;
print &get_pid("my$conf_num\.cnf") ? "Restart Succeeded\n"
: "Restart Failed!\n";
}
}
exit;
}
unless ($opt{all} or $opt{kill}) {
print "ERROR: You must specify a specific daemon, or use the '-all' option.\n";
exit;
}
#kill all mysqld`s
my @ps = split(/\n/,`$PS auxww | $GREP mysqld | $GREP -v grep`);
foreach (@ps) {
my ($pid) = (/^mysql\s+(\d+)\s+/);
kill('TERM',$pid) if $pid > 1;
}
#sleep waiting for them to exit
my $slept;
while ($slept < $MAX_SLEEP) {
last unless &get_pid("mysqld");
$slept += sleep($SLEEP_PER);
print "Waiting to exit...$slept\n" unless $opt{quiet};
}
if (&get_pid("mysqld")) {
warn "Error. Current mysqld's haven't died yet\n" unless $opt{quiet};
exit;
}
unless ( $opt{kill} || !service_enabled('MYSQL') ) {
#restart all in config file
my @daemons = grep /MYSQLD\d*$/i, keys %$SERVER;
if (@daemons) {
foreach my $d (@daemons) {
my ($num) = ($d =~ /MYSQLD(\d+)/i);
my $conf = "my$num.cnf";
Proc::Daemon::Init if $opt{quiet};
system("$MYSQLD --defaults-file=/etc/$conf &")
}
exit;
}
#restart default
Proc::Daemon::Init if $opt{quiet};
system("$MYSQLD --defaults-file=/etc/my.cnf &");
}
sub get_pid {
my $find = shift;
open(PS,"$PS auxww | $GREP $find | $GREP -v grep|") ||
return undef;
my ($pid) = (<PS> =~ /^mysql\s+(\d+)\s/);
close(PS);
return $pid || undef;
}