]> jspc29.x-matter.uni-frankfurt.de Git - hadesicinga.git/commitdiff
put in daemonize option. Sergey.
authorhadaq <hadaq>
Wed, 28 Jan 2009 12:48:29 +0000 (12:48 +0000)
committerhadaq <hadaq>
Wed, 28 Jan 2009 12:48:29 +0000 (12:48 +0000)
plugins/check_lustre.pl

index 3d8ba4fd6a245d38b060d1a9bc041faba08ec880..cf49ce2c047a8cf4a4c3aca2d810e375321a95a5 100755 (executable)
@@ -24,8 +24,8 @@ use threads::shared;
 use IO::Socket;
 use IO::Select;
 
-our ($opt_s, $opt_h);
-getopts('hs');
+our ($opt_s, $opt_d, $opt_h);
+getopts('hsd');
 
 if($opt_h){
     &showHelp();
@@ -39,7 +39,19 @@ my $sleep_time : shared = 600;         # 10 minutes
 our $server_port = '50502';
 our $protocol    = 'tcp';
 
+#--- Daemonize
+if($opt_d){
+    open( STDIN,  '/dev/null'  );
+    open( STDOUT, '>/dev/null' );
+    open( STDERR, '>/dev/null' );
+
+    my $pid = fork();
+    exit( 0 ) if ($pid);
+    die "ERROR: Cannot fork to background: $!\n" unless (defined( $pid ));
+}
+
 threads->new( \&statusServer );
+
 &main();
 
 exit(0);
@@ -185,8 +197,9 @@ sub showHelp
       a local machine. The script also runs a status server 
       in a separate thread for reporting the status to Nagios.
       
-    Usage: check_lustre.pl [-s] [-h]
+    Usage: check_lustre.pl [-d] [-s] [-h]
 
+      -d : Run as a daemon.
       -s : Check also a disk space used on Lustre file system.
       -h : Print this help.