use Time::Local;
use Time::localtime;
use Getopt::Std;
+#use POSIX qw(sys_wait_h signal_h); # Perl interface to IEEE Std 1003.1
# the following is for the status server
# to communicate with Nagios plugin
exit(0);
}
-my $status : shared = "OK";
+my $status : shared = "OK"; # status reported by Nagios
my $time_ls : shared = &getTime();
my $sleep_time : shared = 600; # 10 minutes
+my $ExitCode : shared = -1; # used to stop threads
our $server_port = '50502';
our $protocol = 'tcp';
+#--- POSIX signal handlers: see signal(7) or kill(1) for available signals
+foreach my $signal (qw(HUP INT QUIT ILL ABRT FPE SEGV TERM USR1 USR2))
+{
+ $SIG{$signal} = sub { &exitProgram( $signal ); };
+}
+
#--- Daemonize
if($opt_d){
open( STDIN, '/dev/null' );
Listen => SOMAXCONN ) ))
{
print "ERROR: Cannot start status server!\n";
+ &exitProgram(2);
}
$selector = new IO::Select( $server_socket );
unless (defined( $client_socket = $server_socket->accept() ))
{
print "ERROR: Cannot open socket to send status!\n";
+ &exitProgram(2);
}
#--- report the status
return $totsize;
}
-sub checkLustreSize
+sub checkLustreSize()
{
my $lustre_size = shift;
}
}
+sub exitProgram()
+{
+ #--- don't allow nested signal handling
+ return if ($ExitCode ne "-1");
+
+ #--- this will stop the treads, too
+ $ExitCode = shift;
+
+ #--- wait until all threads ended
+ foreach my $thread (threads->list())
+ {
+ $thread->join()
+ if ($thread->tid() && !threads::equal( $thread, threads->self() ));
+ }
+
+ #--- exit with code 0 in case a signal was caught
+ exit( $ExitCode !~ /^\d+$/ ? 0 : $ExitCode );
+}
+
sub showHelp
{
print << 'EOF';