From: hadaq Date: Thu, 29 Jan 2009 12:01:53 +0000 (+0000) Subject: new option [-r] restart and [-k] only kill. Sergey. X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=c9f55e9f2c6883d55f8ead7d975499f892670e4d;p=hadesicinga.git new option [-r] restart and [-k] only kill. Sergey. --- diff --git a/plugins/restart.pl b/plugins/restart.pl index 3ae83d7..1465dd9 100755 --- a/plugins/restart.pl +++ b/plugins/restart.pl @@ -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 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