Ensure there are no duplicates in pandora_ha execution
This commit is contained in:
parent
18e6bd1c22
commit
c0ff8b8294
|
@ -82,24 +82,26 @@ sub ha_daemonize($) {
|
||||||
|
|
||||||
# Fork!
|
# Fork!
|
||||||
defined(my $pid = fork) or die "Can't fork: $!";
|
defined(my $pid = fork) or die "Can't fork: $!";
|
||||||
if ($pid) {
|
exit if ($pid);
|
||||||
# Store PID of this process in file presented by config token
|
|
||||||
if ($PID_FILE ne "") {
|
# Child inherits execution.
|
||||||
if ( -e $PID_FILE && open (FILE, $PID_FILE)) {
|
|
||||||
$pid = <FILE> + 0;
|
|
||||||
close FILE;
|
|
||||||
|
|
||||||
# Check if pandora_ha is running.
|
|
||||||
die "[ERROR] pandora_ha is already running with pid: $pid." if (kill (0, $pid));
|
|
||||||
}
|
|
||||||
umask 0022;
|
|
||||||
open (FILE, '>', $PID_FILE) or die "[FATAL] $!";
|
|
||||||
print FILE $pid;
|
|
||||||
close (FILE);
|
|
||||||
}
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
setsid or die "Can't start a new session: $!";
|
setsid or die "Can't start a new session: $!";
|
||||||
|
|
||||||
|
# Store PID of this process in file presented by config token
|
||||||
|
if ($PID_FILE ne "") {
|
||||||
|
if ( -e $PID_FILE && open (FILE, $PID_FILE)) {
|
||||||
|
$pid = <FILE> + 0;
|
||||||
|
close FILE;
|
||||||
|
|
||||||
|
# Check if pandora_ha is running.
|
||||||
|
die "[ERROR] pandora_ha is already running with pid: $pid.\n" if (kill (0, $pid));
|
||||||
|
}
|
||||||
|
|
||||||
|
umask 0022;
|
||||||
|
open (FILE, '>', $PID_FILE) or die "[FATAL] $!";
|
||||||
|
print FILE $$;
|
||||||
|
close (FILE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
|
@ -315,10 +317,10 @@ sub ha_main($) {
|
||||||
# Log to a separate file if needed.
|
# Log to a separate file if needed.
|
||||||
$conf->{'log_file'} = $conf->{'ha_log_file'} if defined ($conf->{'ha_log_file'});
|
$conf->{'log_file'} = $conf->{'ha_log_file'} if defined ($conf->{'ha_log_file'});
|
||||||
|
|
||||||
ha_daemonize($conf) if ($DAEMON == 1);
|
|
||||||
|
|
||||||
$Running = 1;
|
$Running = 1;
|
||||||
|
|
||||||
|
ha_daemonize($conf) if ($DAEMON == 1);
|
||||||
|
|
||||||
while ($Running) {
|
while ($Running) {
|
||||||
eval {
|
eval {
|
||||||
eval {
|
eval {
|
||||||
|
|
Loading…
Reference in New Issue