mmmd_mon

来自「mysql+ha. 实现高可用性 http://code.google.com」· 代码 · 共 115 行

TXT
115
字号
#!/usr/bin/env perl# Use mandatory external modulesuse strict;use Cwd;use File::Basename;use Data::Dumper;use POSIX;use Config;use Getopt::Long;use threads;use threads::shared;use Thread::Queue;#use Thread::Semaphore;use IO::Socket;use Proc::Daemon;use Time::HiRes;use DBI;# Check perl for threads support$Config{useithreads} or die "Recompile Perl with threads to run this program.";# Determine installation dir nameour $SELF_DIR = dirname(dirname(Cwd::abs_path(__FILE__)));# Include semaphores bug fixrequire $SELF_DIR . '/lib/semaphore.pm';# Include parts of the systemrequire $SELF_DIR . '/lib/config.pm';require $SELF_DIR . '/lib/log.pm';require $SELF_DIR . '/lib/checkers.pm';require $SELF_DIR . '/lib/mon_commands.pm';require $SELF_DIR . '/lib/daemon.pm';require $SELF_DIR . '/lib/commands.pm';#-----------------------------------------------------------------# Read config filemy $postfix = "";our $cluster_name : shared = "";if (scalar(@ARGV) && $ARGV[0] =~ /^@(.*)/) {    shift(@ARGV);    $postfix = "_$1";    $cluster_name = $1;}my $cfg_file = "mmm_mon$postfix.conf";print "Reading config file: '$cfg_file'\n";our $config : shared = ReadConfig($cfg_file);# Mysql protection semaphoreour $mysql_sem = new Thread::Semaphore;# Status changing semaphoreour $status_sem = new Thread::Semaphore;# Roles listour $roles : shared = CreateRolesList();# Checks status dataour $checks_status : shared = CreateChecksStatus();# Servers status dataour $servers_status : shared = CreateServersStatus();#print Dumper($servers_status);# We need to know how previous session has been finishedour $unclean_start : shared = CheckPidFile();# Go to backgroundProc::Daemon::Init if ($config->{debug} =~ /^(off|no|0)$/i);CreatePidFile();# Shutdown flagour $shutdown : shared = 0;# Start time to calculate uptimeour $start_time : shared = time();# Catch signals$SIG{INT} = \&SignalHandler;$SIG{TERM} = \&SignalHandler;$SIG{PIPE} = 'IGNORE';#-----------------------------------------------------------------# Creating message queuesmy $status_queue = new Thread::Queue();my $command_queue = new Thread::Queue();# Creating command workermy $command_thread = new threads(\&CommandMain, $command_queue, $status_queue);# Creating status monitoring threadmy $checker_threads = StartCheckerThreads($command_queue, $status_queue);# Creating main threadDaemonMain($command_queue, $status_queue);# Waiting for threads shutdown$command_thread->join();ShutdownCheckerThreads($checker_threads);# Delete pid file and update status fileunlink($config->{pid_path});UpdateStatusFile();exit(0);#-----------------------------------------------------------------sub SignalHandler() {    LogDebug("Core: Signal received: exiting...");    $shutdown = 1;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?