From: Stephen L Johnson Date: Tue, 14 Mar 2000 22:06:25 +0000 (+0000) Subject: added check to abort spong-client if it is already running X-Git-Tag: spong-2_7-alpha5~38 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c172619f7cbde25f101c07ba7215d55535a1f37d;p=spong.git added check to abort spong-client if it is already running --- diff --git a/src/spong-client.pl b/src/spong-client.pl index 9d3b0b9..04b9193 100755 --- a/src/spong-client.pl +++ b/src/spong-client.pl @@ -56,12 +56,16 @@ Spong::Daemon::Daemonize # Daemonize if not signalling or debugging unless ($restart || $kill || $nosleep || $debug); &handle_signals(); # Set up handlers, and signal the current server if asked + %CHECKFUNCS = (); &load_checks(); +&debug("Done loading check modules",1); # Pretty simple program, check the stuff that we are looking at, report it to # the server, sleep, and do it all again... +$0 = "spong-client"; + while( 1 ) { my ($check); @@ -190,11 +194,33 @@ sub handle_signals { exit(0); } + # Check to see if we are already running + &already_running(); + # Write our pid to the spong tmp directory. system( "echo $$ >$SPONGTMP/spong-client.pid" ) unless $nosleep; } +# This routine check to see if another instance of spong-server is already +# running. If there is another instance, this instance will complain and die + +sub already_running { + # if there is a PID file + if ( -f "$SPONGTMP/spong-client.pid" ) { + # Read the pid + open( PID, "$SPONGTMP/spong-client.pid" ) || die "Can't open pid: $!"; + my $pid = ; chomp $pid; + close PID; + + if ( kill 0,$pid ) { + &error("Spong-client is already running as pid $pid"); + exit 1; + } + } +} + + # Output functions, one for debugging information, the other for errors. @@ -235,7 +261,7 @@ sub load_checks { }; foreach $check (split / /,$CHECKS) { - &debug( "Loading client check $check" ); + &debug( "Loading client check $check", 3 ); eval "require 'Spong/Client/plugins/check_$check';"; if ( $@ ) { &error( "Could not load $check check plugin" ); } }