diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index db09b6f99a..8864296d58 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,15 @@ +2011-06-23 Koichiro Kikuchi + + * lib/PandoraFMS/Tools.pm: Checked if pandora_server is already + running, in order to prevent multiple instances with same PID + file from running. And made PID file permissions 644, rather + than 666. + + * bin/pandora_server: Remove PID file on shutdown. + + * FreeBSD/pandora_server: Use -P option for PID file instead of + pgrep. + 2011-06-22 Ramon Novoa * lib/PandoraFMS/Config.pm: Added a new SNMP server (enterprise). diff --git a/pandora_server/FreeBSD/pandora_server b/pandora_server/FreeBSD/pandora_server index 4d9164f037..f8ddeafcc3 100755 --- a/pandora_server/FreeBSD/pandora_server +++ b/pandora_server/FreeBSD/pandora_server @@ -26,25 +26,11 @@ load_rc_config $name PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin -command=/usr/local/bin/${name} -command_args="-D /usr/local/etc/pandora/pandora_server.conf" - pidfile=/var/run/$name.pid +command=/usr/local/bin/${name} +command_args="-D -P ${pidfile} /usr/local/etc/pandora/pandora_server.conf" required_files="/usr/local/etc/pandora/pandora_server.conf" -start_postcmd=start_postcmd -stop_postcmd=stop_postcmd procname="/usr/local/bin/perl" -start_postcmd() -{ - PANDORA_PID=`pgrep -f -j none $name` - echo $PANDORA_PID > $pidfile -} - -stop_postcmd() -{ - rm -f $pidfile -} - run_rc_command "$1" diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server index 482e8464c2..a2eaecbdf8 100755 --- a/pandora_server/bin/pandora_server +++ b/pandora_server/bin/pandora_server @@ -56,6 +56,9 @@ sub pandora_shutdown () { print_message (\%Config, ' [*] Shutting down ' . $Config{'servername'} . "(received signal)...\n", 1); db_disconnect ($DBH); + if ($Config{'PID'} ne "") { + unlink($Config{'PID'}) or logger (\%Config, "[W] Could not remove PID file: $!",1); + } exit (0); } diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 86dcf8f8d9..2d9d8be444 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -284,14 +284,26 @@ sub pandora_daemonize { defined(my $pid = fork) or die "Can't fork: $!"; exit if $pid; setsid or die "Can't start a new session: $!"; - umask 0; # Store PID of this process in file presented by config token if ($pa_config->{'PID'} ne ""){ + + if ( -e $pa_config->{'PID'} && open (FILE, $pa_config->{'PID'})) { + $pid = + 0; + close FILE; + + # check if pandora_server is running + if (kill (0, $pid)) { + die "[FATAL] pandora_server already running, pid: $pid."; + } + logger ($pa_config, '[W] Stale PID file, overwriting.', 1); + } + umask 022; open (FILE, "> ".$pa_config->{'PID'}) or die "[FATAL] Cannot open PIDfile at ".$pa_config->{'PID'}; print FILE "$$"; close (FILE); } + umask 0; }