$debug = $restart = $kill = 0;
-Getopt::Long::Configure('pass_through');
-if ( ! GetOptions("debug:i" => \$debuglevel, "restart" => \$restart,
+#Getopt::Long::Configure('pass_through');
+if ( ! GetOptions("debug=i" => \$debuglevel, "restart" => \$restart,
"kill" => \$kill, "nosleep|refresh" => \$nosleep ) ) {
&usage();
exit 1;
while( 1 ) {
foreach $host ( @HOSTS_LIST ) {
- &debug( "checking network services ($checks) on $host" );
+ &debug( "checking network services on $host" );
my $check;
foreach $check (('ping',split(/\s+/,$HOSTS{$host}->{'services'}))) {
exit(0);
}
+ # Check to see if we are already running
+ &already_running();
+
# Write our pid to the spong tmp directory.
system( "echo $$ >$SPONGTMP/spong-network.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-network.pid" ) {
+ # Read the pid
+ open( PID, "$SPONGTMP/spong-network.pid" ) || die "Can't open pid: $!";
+ my $pid = <PID>; chomp $pid;
+ close PID;
+
+ if ( kill 0,$pid ) {
+ &error("Spong-network is already running as pid $pid");
+ exit 1;
+ }
+ }
+}
+
+
# Output functions, one for debugging information, the other for errors.
sub debug { Spong::Log::debug($_[0],$_[1]); }