add --soft option to trash stuff without rebooting the phy boxes
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 14 Jan 2011 15:31:03 +0000 (16:31 +0100)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 14 Jan 2011 15:31:03 +0000 (16:31 +0100)
scripts/manage-infrastructure.py

index 11fc8c3..ccc381f 100755 (executable)
@@ -190,6 +190,21 @@ class BuildBoxes:
     def margin_outline (self, string): return self.margin(self.outline(string))
 
     def handle_plc_box (self,box):
+# initial approach was to first scan vserver-stat, but it's not needed
+        if not self.options.probe:
+#            # remove mark for all running servers to avoid resurrection
+#            if vserver_names:
+#                bash="; ".join( [ "rm -f /etc/vservers/%s/apps/init/mark"%vs for vs in vserver_names ] )
+#                stop_command=['bash','-c',"'" + bash + "'"]
+#                self.run_ssh(box,stop_command,"Removing mark on running vservers on %s"%box)
+            # just trash all marks 
+            stop_command=['rm','-rf','/etc/vservers/*/apps/init/mark']
+            self.run_ssh(box,stop_command,"Removing all vserver marks on %s"%box)
+            if not self.options.soft:
+                self.reboot(box)
+            else:
+                self.run_ssh(box,['service','util-vserver','stop'],"Stopping all running vservers")
+            return
         # even for rebooting we need to scan vserver-stat to stop the vservers properly
         vserver_names=[]
         command=['vserver-stat']
@@ -219,16 +234,6 @@ class BuildBoxes:
             longname=ctx_dict[context]
             vserver_names.append(longname)
             print self.margin_outline(self.vplcname(longname)),"%(vserver_line)s [=%(longname)s]"%locals()
-        if not self.options.probe:
-#            # remove mark for all running servers to avoid resurrection
-#            if vserver_names:
-#                bash="; ".join( [ "rm -f /etc/vservers/%s/apps/init/mark"%vs for vs in vserver_names ] )
-#                stop_command=['bash','-c',"'" + bash + "'"]
-#                self.run_ssh(box,stop_command,"Removing mark on running vservers on %s"%box)
-            # just trash all marks 
-            stop_command=['rm','-rf','/etc/vservers/*/apps/init/mark']
-            self.run_ssh(box,stop_command,"Removing all vserver marks on %s"%box)
-            self.reboot(box)
 
     vnode_matcher = re.compile(".*(vnode[0-9]+)")
     def vnodename (self, ps_line):
@@ -238,7 +243,10 @@ class BuildBoxes:
 
     def handle_qemu_box (self,box):
         if not self.options.probe:
-            self.reboot(box)
+            if not self.options.soft:
+                self.reboot(box)
+            else:
+                self.run_ssh(box,['pkill','qemu'],"Killing qemu instances")
         else:
             command=['lsmod']
             modules=self.backquote_ssh(box,command).split('\n')
@@ -316,16 +324,19 @@ Default is to act on test boxes only"""
                            help="Dry run")
         parser.add_option ("-r","--reboot", action="store_false",dest="probe",default=True,
                            help="Actually reset/reboot stuff instead of just probing it")
+        parser.add_option ("-s","--soft",action="store_true",dest="soft",default=False,
+                           help="Soft reset instead of hard reboot of the boxes")
         # no need for -p = probe, as this is the default
         parser.add_option ("-p","--plc", action="store_true",dest="plc_only",default=False,
                            help="Acts on the plc box only")
 
+        parser.add_option ("-e","--deep",action="store_true", dest="deep", default=False,
+                           help="on build boxes, shows vbuild processes in vservers as well; signif. slower")
+
         parser.add_option ("-a","--all",action="store_true",dest="all_boxes",default=False,
                            help="Acts on build and test boxes")
         parser.add_option ("-b","--build",action="store_true",dest="build_only",default=False,
                            help="Acts on build boxes only")
-        parser.add_option ("-e","--deep",action="store_true", dest="deep", default=False,
-                           help="on build boxes, shows vbuild processes in vservers as well; signif. slower")
         parser.add_option ("-q","--qemu",action="store_true",dest="qemu_only",default=False,
                            help="Only acts on the qemu boxes")
         parser.add_option ("-t","--trackers",action="store_true",dest="trackers_only",default=False,