3 from Exceptions import *
10 ---------------------------------------------------------
11 This machine has entered a temporary debug state, so
12 Planetlab Support can login and fix any problems that
15 Please do not reboot this machine at this point, unless
16 specifically asked to.
19 ---------------------------------------------------------
25 Bring up sshd inside the boot cd environment for debug purposes.
27 Once its running, touch the file /tmp/SSHD_RUNNING so future
28 calls to this function don't do anything.
30 Expect the following variables in vars to be set:
31 BM_SOURCE_DIR The source dir for the boot manager sources that
32 we are currently running from
33 BOOT_CD_VERSION A tuple of the current bootcd version
36 log.write( "\n\nStep: Starting debug mode.\n" )
38 # make sure we have the variables we need
40 BM_SOURCE_DIR= vars["BM_SOURCE_DIR"]
41 if BM_SOURCE_DIR == "":
42 raise ValueError, "BM_SOURCE_DIR"
44 BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
45 if BOOT_CD_VERSION == "":
46 raise ValueError, "BOOT_CD_VERSION"
49 raise BootManagerException, "Missing variable in vars: %s\n" % var
50 except ValueError, var:
51 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
54 log.write( "Starting debug environment\n" )
56 ssh_source_files= "%s/debug_files/" % BM_SOURCE_DIR
58 ssh_home= "/root/.ssh"
59 cancel_boot_flag= "/tmp/CANCEL_BOOT"
60 sshd_started_flag= "/tmp/SSHD_RUNNING"
64 os.stat(sshd_started_flag)
70 log.write( "Creating ssh host keys\n" )
72 utils.makedirs( ssh_dir )
73 utils.sysexec( "ssh-keygen -t rsa1 -b 1024 -f %s/ssh_host_key -N ''" %
75 utils.sysexec( "ssh-keygen -t rsa -f %s/ssh_host_rsa_key -N ''" %
77 utils.sysexec( "ssh-keygen -d -f %s/ssh_host_dsa_key -N ''" %
80 if BOOT_CD_VERSION[0] == 3:
81 utils.sysexec( "cp -f %s/sshd_config_v3 %s/sshd_config" %
82 (ssh_source_files,ssh_dir), log )
84 utils.sysexec( "cp -f %s/sshd_config_v2 %s/sshd_config" %
85 (ssh_source_files,ssh_dir), log )
87 log.write( "ssh host keys already created\n" )
90 # always update the key, may have change in this instance of the bootmanager
91 log.write( "Installing debug ssh key for root user\n" )
93 utils.makedirs( ssh_home )
94 utils.sysexec( "cp -f %s/debug_root_ssh_key %s/authorized_keys" %
95 (ssh_source_files,ssh_home), log )
96 utils.sysexec( "chmod 700 %s" % ssh_home, log )
97 utils.sysexec( "chmod 600 %s/authorized_keys" % ssh_home, log )
100 log.write( "Starting sshd\n" )
102 if BOOT_CD_VERSION[0] == 2:
103 utils.sysexec( "/usr/sbin/sshd", log )
105 utils.sysexec( "service sshd start", log )
107 # flag that ssh is running
108 utils.sysexec( "touch %s" % sshd_started_flag, log )
110 log.write( "sshd already running\n" )
113 # for ease of use, setup lvm on 2.x cds
114 if BOOT_CD_VERSION[0] == 2:
115 compatibility.setup_lvm_2x_cd(vars,log)
118 # this will make the initial script stop requesting scripts from PLC
119 utils.sysexec( "touch %s" % cancel_boot_flag, log )