3 # Copyright (c) 2003 Intel Corporation
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
11 from Exceptions import *
17 ---------------------------------------------------------
18 This machine has entered a temporary debug state, so
19 Planetlab Support can login and fix any problems that
22 Please do not reboot this machine at this point, unless
23 specifically asked to.
26 ---------------------------------------------------------
30 # either at the end of the bm logic, because something failed (last_resort = True)
31 # and/or it can be invoked as a fallback very early in the bootmanager logic,
32 # so we can reach the node regardless of what happens (e.g. bm sometimes hangs)
34 def Run( vars, log, last_resort = True):
37 Bring up sshd inside the boot cd environment for debug purposes.
39 Once its running, touch the file /tmp/SSHD_RUNNING so future
40 calls to this function don't do anything.
42 Expect the following variables in vars to be set:
43 BM_SOURCE_DIR The source dir for the boot manager sources that
44 we are currently running from
48 message="Starting debug mode"
50 message="Starting fallback sshd"
53 log.write( "\n\nStep: %s.\n"%message )
55 # make sure we have the variables we need
57 BM_SOURCE_DIR= vars["BM_SOURCE_DIR"]
58 if BM_SOURCE_DIR == "":
59 raise ValueError, "BM_SOURCE_DIR"
62 raise BootManagerException, "Missing variable in vars: %s\n" % var
63 except ValueError, var:
64 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
67 ssh_source_files= "%s/debug_files/" % BM_SOURCE_DIR
69 ssh_home= "/root/.ssh"
70 cancel_boot_flag= "/tmp/CANCEL_BOOT"
71 sshd_started_flag= "/tmp/SSHD_RUNNING"
73 # create host keys if needed
74 if not os.path.isdir (ssh_dir):
75 utils.makedirs (ssh_dir)
76 key=ssh_dir+"/ssh_host_key"
77 if not os.path.isfile (key):
78 log.write("Creating host rsa1 key %s\n"%key)
79 utils.sysexec( "ssh-keygen -t rsa1 -b 1024 -f %s -N ''" % key, log )
80 key=ssh_dir+"/ssh_host_rsa_key"
81 if not os.path.isfile (key):
82 log.write("Creating host rsa key %s\n"%key)
83 utils.sysexec( "ssh-keygen -t rsa -f %s -N ''" % key, log )
84 key=ssh_dir+"/ssh_host_dsa_key"
85 if not os.path.isfile (key):
86 log.write("Creating host dsa key %s\n"%key)
87 utils.sysexec( "ssh-keygen -d -f %s -N ''" % key, log )
89 # (over)write sshd config
90 utils.sysexec( "cp -f %s/sshd_config %s/sshd_config" % (ssh_source_files,ssh_dir), log )
92 ### xxx ### xxx ### xxx ### xxx ### xxx
94 # always update the key, may have changed in this instance of the bootmanager
95 log.write( "Installing debug ssh key for root user\n" )
96 if not os.path.isdir ( ssh_home):
97 utils.makedirs( ssh_home )
98 utils.sysexec( "cp -f %s/debug_root_ssh_key %s/authorized_keys" % (ssh_source_files,ssh_home), log )
99 utils.sysexec( "chmod 700 %s" % ssh_home, log )
100 utils.sysexec( "chmod 600 %s/authorized_keys" % ssh_home, log )
103 if not os.path.isfile(sshd_started_flag):
104 log.write( "Starting sshd\n" )
105 utils.sysexec( "service sshd start", log )
106 # flag that ssh is running
107 utils.sysexec( "touch %s" % sshd_started_flag, log )
109 # it is expected that sshd is already running when last_resort==True
111 log.write( "sshd is already running\n" )
114 # this will make the initial script stop requesting scripts from PLC
115 utils.sysexec( "touch %s" % cancel_boot_flag, log )
118 print warning_message