3 # Copyright (c) 2003 Intel Corporation
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
11 from Exceptions import *
18 ---------------------------------------------------------
19 This machine has entered a temporary debug state, so
20 Planetlab Support can login and fix any problems that
23 Please do not reboot this machine at this point, unless
24 specifically asked to.
27 ---------------------------------------------------------
33 Bring up sshd inside the boot cd environment for debug purposes.
35 Once its running, touch the file /tmp/SSHD_RUNNING so future
36 calls to this function don't do anything.
38 Expect the following variables in vars to be set:
39 BM_SOURCE_DIR The source dir for the boot manager sources that
40 we are currently running from
41 BOOT_CD_VERSION A tuple of the current bootcd version
44 log.write( "\n\nStep: Starting debug mode.\n" )
46 # make sure we have the variables we need
48 BM_SOURCE_DIR= vars["BM_SOURCE_DIR"]
49 if BM_SOURCE_DIR == "":
50 raise ValueError, "BM_SOURCE_DIR"
52 BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
53 if BOOT_CD_VERSION == "":
54 raise ValueError, "BOOT_CD_VERSION"
57 raise BootManagerException, "Missing variable in vars: %s\n" % var
58 except ValueError, var:
59 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
62 log.write( "Starting debug environment\n" )
64 ssh_source_files= "%s/debug_files/" % BM_SOURCE_DIR
66 ssh_home= "/root/.ssh"
67 cancel_boot_flag= "/tmp/CANCEL_BOOT"
68 sshd_started_flag= "/tmp/SSHD_RUNNING"
72 os.stat(sshd_started_flag)
78 log.write( "Creating ssh host keys\n" )
80 utils.makedirs( ssh_dir )
81 utils.sysexec( "ssh-keygen -t rsa1 -b 1024 -f %s/ssh_host_key -N ''" %
83 utils.sysexec( "ssh-keygen -t rsa -f %s/ssh_host_rsa_key -N ''" %
85 utils.sysexec( "ssh-keygen -d -f %s/ssh_host_dsa_key -N ''" %
88 if BOOT_CD_VERSION[0] >= 3:
89 utils.sysexec( "cp -f %s/sshd_config_v3 %s/sshd_config" %
90 (ssh_source_files,ssh_dir), log )
92 utils.sysexec( "cp -f %s/sshd_config_v2 %s/sshd_config" %
93 (ssh_source_files,ssh_dir), log )
95 log.write( "ssh host keys already created\n" )
98 # always update the key, may have change in this instance of the bootmanager
99 log.write( "Installing debug ssh key for root user\n" )
101 utils.makedirs( ssh_home )
102 utils.sysexec( "cp -f %s/debug_root_ssh_key %s/authorized_keys" %
103 (ssh_source_files,ssh_home), log )
104 utils.sysexec( "chmod 700 %s" % ssh_home, log )
105 utils.sysexec( "chmod 600 %s/authorized_keys" % ssh_home, log )
108 log.write( "Starting sshd\n" )
110 if BOOT_CD_VERSION[0] == 2:
111 utils.sysexec( "/usr/sbin/sshd", log )
113 utils.sysexec( "service sshd start", log )
115 # flag that ssh is running
116 utils.sysexec( "touch %s" % sshd_started_flag, log )
118 log.write( "sshd already running\n" )
121 # for ease of use, setup lvm on 2.x cds
122 if BOOT_CD_VERSION[0] == 2:
123 compatibility.setup_lvm_2x_cd(vars,log)
126 # this will make the initial script stop requesting scripts from PLC
127 utils.sysexec( "touch %s" % cancel_boot_flag, log )