merge from trunk : upload log & early sshd start
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 26 Feb 2009 17:36:51 +0000 (17:36 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 26 Feb 2009 17:36:51 +0000 (17:36 +0000)
the rest of it unintentionally made it into changeset 12257

source/BootManager.py
source/utils.py

index 2098c41..6012661 100755 (executable)
@@ -17,8 +17,8 @@ import notify_messages
 import BootServerRequest
 
 # all output is written to this file
-LOG_FILE= "/tmp/bm.log"
-UPLOAD_LOG_PATH = "/alpina-logs/upload.php"
+BM_NODE_LOG= "/tmp/bm.log"
+UPLOAD_LOG_SCRIPT = "/boot/upload-bmlog.php"
 
 # the new contents of PATH when the boot manager is running
 BIN_PATH= ('/usr/local/bin',
@@ -36,14 +36,12 @@ NodeRunStates = {}
 class log:
 
     def __init__( self, OutputFilePath= None ):
-        if OutputFilePath:
-            try:
-                self.OutputFilePath= OutputFilePath
-                self.OutputFile= GzipFile( OutputFilePath, "w", 9 )
-            except:
-                print( "Unable to open output file for log, continuing" )
-                self.OutputFile= None
-
+        try:
+            self.OutputFile= open( OutputFilePath, "w")
+            self.OutputFilePath= OutputFilePath
+        except:
+            print( "bootmanager log : Unable to open output file %r, continuing"%OutputFilePath )
+            self.OutputFile= None
     
     def LogEntry( self, str, inc_newline= 1, display_screen= 1 ):
         if self.OutputFile:
@@ -71,19 +69,21 @@ class log:
 
 
     
+    # bm log uploading is available back again, as of nodeconfig-5.0-2
     def Upload( self ):
         """
         upload the contents of the log to the server
         """
-
         if self.OutputFile is not None:
-            self.LogEntry( "Uploading logs to %s" % UPLOAD_LOG_PATH )
+            self.OutputFile.flush()
+
+            self.LogEntry( "Uploading logs to %s" % UPLOAD_LOG_SCRIPT )
             
             self.OutputFile.close()
             self.OutputFile= None
 
             bs_request = BootServerRequest.BootServerRequest()
-            bs_request.MakeRequest(PartialPath = UPLOAD_LOG_PATH,
+            bs_request.MakeRequest(PartialPath = UPLOAD_LOG_SCRIPT,
                                    GetVars = None, PostVars = None,
                                    FormData = ["log=@" + self.OutputFilePath],
                                    DoSSL = True, DoCertCheck = True)
@@ -188,6 +188,14 @@ class BootManager:
             # checking whether someone added or changed disks, and
             # then finally chain boots.
 
+            # starting the fallback/debug ssh daemon for safety:
+            # if the node install somehow hangs, or if it simply takes ages, 
+            # we can still enter and investigate
+            try:
+                StartDebug.Run(self.VARS, self.LOG, last_resort = False)
+            except:
+                pass
+
             InstallInit.Run( self.VARS, self.LOG )                    
             if ValidateNodeInstall.Run( self.VARS, self.LOG ):
                 WriteModprobeConfig.Run( self.VARS, self.LOG )
@@ -200,6 +208,15 @@ class BootManager:
                 _nodeNotInstalled()
 
         def _rinsRun():
+
+            # starting the fallback/debug ssh daemon for safety:
+            # if the node install somehow hangs, or if it simply takes ages, 
+            # we can still enter and investigate
+            try:
+                StartDebug.Run(self.VARS, self.LOG, last_resort = False)
+            except:
+                pass
+
             # implements the reinstall logic, which will check whether
             # the min. hardware requirements are met, install the
             # software, and upon correct installation will switch too
@@ -314,7 +331,7 @@ def main(argv):
     
     # all output goes through this class so we can save it and post
     # the data back to PlanetLab central
-    LOG= log( LOG_FILE )
+    LOG= log( BM_NODE_LOG )
 
     LOG.LogEntry( "BootManager started at: %s" % \
                   strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()) )
index 23b45f2..8dc6876 100644 (file)
@@ -16,7 +16,61 @@ import exceptions
 
 from Exceptions import *
 
+### handling breakpoints in the startup process
+import select, sys, string
+
+### global debug settings
+# NOTE. when BREAKPOINT_MODE turns out enabled,
+# you have to attend the boot phase, that would hang otherwise 
+
+# enabling this will cause the node to ask for breakpoint-mode at startup
+# production code should read False/False
+PROMPT_MODE=False
+# default for when prompt is turned off, or it's on but the timeout triggers
+BREAKPOINT_MODE=False
+VERBOSE_MODE=False
+VERBOSE_MODE=True
+# in seconds : if no input, proceed
+PROMPT_TIMEOUT=5
+
+def prompt_for_breakpoint_mode ():
+
+    global BREAKPOINT_MODE
+    if PROMPT_MODE:
+        default_answer=BREAKPOINT_MODE
+        answer=''
+        if BREAKPOINT_MODE:
+            display="[y]/n"
+        else:
+            display="y/[n]"
+        sys.stdout.write ("Want to run in breakpoint mode ? %s "%display)
+        sys.stdout.flush()
+        r,w,e = select.select ([sys.stdin],[],[],PROMPT_TIMEOUT)
+        if r:
+            answer = string.strip(sys.stdin.readline())
+        else:
+            sys.stdout.write("\nTimed-out (%d s)"%PROMPT_TIMEOUT)
+        if answer:
+            BREAKPOINT_MODE = ( answer == "y" or answer == "Y")
+        else:
+            BREAKPOINT_MODE = default_answer
+    label="Off"
+    if BREAKPOINT_MODE:
+        label="On"
+    sys.stdout.write("\nCurrent BREAKPOINT_MODE is %s\n"%label)
+
+def breakpoint (message, cmd = None):
 
+    if BREAKPOINT_MODE:
+
+        if cmd is None:
+            cmd="/bin/sh"
+            message=message+" -- Entering bash - type ^D to proceed"
+
+        print message
+        os.system(cmd)
+
+##############################
 def makedirs( path ):
     """
     from python docs for os.makedirs:
@@ -70,7 +124,7 @@ def sysexec( cmd, log= None ):
     0 if failed. A BootManagerException is raised if the command
     was unable to execute or was interrupted by the user with Ctrl+C
     """
-    if BREAKPOINT_MODE:
+    if VERBOSE_MODE:
         print ("sysexec >>> %s" % cmd)
     prog= popen2.Popen4( cmd, 0 )
     if prog is None:
@@ -190,54 +244,3 @@ def get_mac_from_interface(ifname):
         
     return ret
 
-### handling breakpoints in the startup process
-import select, sys, string
-
-### global debug settings
-# NOTE. when BREAKPOINT_MODE turns out enabled,
-# you have to attend the boot phase, that would hang otherwise 
-
-# enabling this will cause the node to ask for breakpoint-mode at startup
-# production code should read False/False
-PROMPT_MODE=False
-# default for when prompt is turned off, or it's on but the timeout triggers
-BREAKPOINT_MODE=False
-# in seconds : if no input, proceed
-PROMPT_TIMEOUT=5
-
-def prompt_for_breakpoint_mode ():
-
-    global BREAKPOINT_MODE
-    if PROMPT_MODE:
-        default_answer=BREAKPOINT_MODE
-        answer=''
-        if BREAKPOINT_MODE:
-            display="[y]/n"
-        else:
-            display="y/[n]"
-        sys.stdout.write ("Want to run in breakpoint mode ? %s "%display)
-        sys.stdout.flush()
-        r,w,e = select.select ([sys.stdin],[],[],PROMPT_TIMEOUT)
-        if r:
-            answer = string.strip(sys.stdin.readline())
-        else:
-            sys.stdout.write("\nTimed-out (%d s)"%PROMPT_TIMEOUT)
-        if answer:
-            BREAKPOINT_MODE = ( answer == "y" or answer == "Y")
-        else:
-            BREAKPOINT_MODE = default_answer
-    label="Off"
-    if BREAKPOINT_MODE:
-        label="On"
-    sys.stdout.write("\nCurrent BREAKPOINT_MODE is %s\n"%label)
-
-def breakpoint (message, cmd = None):
-
-    if BREAKPOINT_MODE:
-
-        if cmd is None:
-            cmd="/bin/sh"
-            message=message+" -- Entering bash - type ^D to proceed"
-
-        print message
-        os.system(cmd)