]> jspc29.x-matter.uni-frankfurt.de Git - hadesicinga.git/commitdiff
new option [-r] restart and [-k] only kill. Sergey.
authorhadaq <hadaq>
Thu, 29 Jan 2009 12:01:53 +0000 (12:01 +0000)
committerhadaq <hadaq>
Thu, 29 Jan 2009 12:01:53 +0000 (12:01 +0000)
plugins/restart.pl

index 3ae83d7dc8f4ed61fb89ddce3395357bc209a0b6..1465dd96373527cf0b49c977cf340aa5c9f2cfd9 100755 (executable)
@@ -10,8 +10,8 @@ use strict;
 use warnings;
 use Getopt::Std;
 
-our ($opt_s, $opt_p, $opt_k, $opt_h);
-getopts('hs:p:k');
+our ($opt_s, $opt_r, $opt_k, $opt_h);
+getopts('hs:p:kr');
 
 if($opt_h){
     &showHelp();
@@ -20,40 +20,51 @@ if($opt_h){
 
 &checkArgs();
 
+#--- on these PCs the script should be restarted:
+#my @PCList = ('lxg0429','lxg0433','lxg0435','lxg0437','lxg0439','lxg0440','lxg0441','lxg0442','lxg0443','lxg0444','lxg0445','lxg0446','lxg0447','lxg0448','lxg0452','lxg0453','lxg0454','lxg0455');
+my @PCList = ('lxg0447');
+my $args   = "-d";       #- arguments of script to be restarted
+
 &main();
 
 exit(0);
 
-#---------------- END ---------------------
+#------------------------ END -------------------------
 
 sub main
 {
     
     #--- on these PCs the script should be restarted:
-    my @PCList = ('lxg0429','lxg0433','lxg0435','lxg0437','lxg0439','lxg0440','lxg0441','lxg0442','lxg0443','lxg0444','lxg0445','lxg0446','lxg0447','lxg0448','lxg0452','lxg0453','lxg0454','lxg0455');
-
+    #my @PCList = ('lxg0429','lxg0433','lxg0435','lxg0437','lxg0439','lxg0440','lxg0441','lxg0442','lxg0443','lxg0444','lxg0445','lxg0446','lxg0447','lxg0448','lxg0452','lxg0453','lxg0454','lxg0455');
+    my @PCList = ('lxg0447');
 
     foreach my $PC (@PCList) {
 
        print "restart on $PC ...\n";
 
-       if($opt_k){
-           #--- first kill then restart
+       if( $opt_k || $opt_r ){
+           #--- get PIDs of running scripts
            my $command = "ssh $PC \"pidof -x $opt_s\" ";
            my $out = `$command`;
            chomp($out);
 
            #--- is there anything to kill?
-           if($out){
-               system("ssh $PC \"pidof -x $opt_s | xargs kill -9; sleep 1; $opt_s -d\" ");
+           if($out && $opt_k){
+               #--- kill
+               system("ssh $PC \"pidof -x $opt_s | xargs kill -9\" ");
+           }
+           elsif($out && $opt_r){
+               #--- kill and restart
+               system("ssh $PC \"pidof -x $opt_s | xargs kill -9; sleep 1; $opt_s $args\" ");
            }
-           else{
-               system("ssh $PC \"$opt_s -d\" ");
+           elsif($opt_r){
+               #--- restart
+               system("ssh $PC \"$opt_s $args\" ");
            }
        }
        else{
            #--- restart without killing
-           my $command = "ssh $PC \"$opt_s -d\" ";
+           my $command = "ssh $PC \"$opt_s $args\" ";
            system($command);
        }
     }
@@ -84,7 +95,8 @@ sub showHelp
 
       -s <name> : Name of script to be restarted. Name must 
                   contain a path to a script on remote PC!
-      -k        : Try to kill a running script before restarting.
+      -r        : Kill a running script before restarting.
+      -k        : Kill a running script without restarting.
       -h        : Print this help.
 
 EOF