~rlane/nova/ldapimprovements

« back to all changes in this revision

Viewing changes to tools/nova-debug

  • Committer: Ryan Lane
  • Date: 2010-11-24 15:46:32 UTC
  • mfrom: (382.48.1 trunk)
  • Revision ID: laner@controller-20101124154632-zh7kwjuyyd02a2lh
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
3
 
 
4
# Copyright 2010 United States Government as represented by the
 
5
# Administrator of the National Aeronautics and Space Administration.
 
6
# All Rights Reserved.
 
7
#
 
8
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
9
#    not use this file except in compliance with the License. You may obtain
 
10
#    a copy of the License at
 
11
#
 
12
#         http://www.apache.org/licenses/LICENSE-2.0
 
13
#
 
14
#    Unless required by applicable law or agreed to in writing, software
 
15
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
16
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
17
#    License for the specific language governing permissions and limitations
 
18
#    under the License.
 
19
 
 
20
INSTANCES_PATH=${INSTANCES_PATH:-/var/lib/nova/instances}
 
21
if [ -z "$1" ]; then echo "specify an instance id to debug"; exit; fi
 
22
 
 
23
if [ -n "$3" ]; then DEVICE=$3; fi
 
24
 
 
25
CMD="all"
 
26
if [ -n "$2" ]; then CMD=$2; fi
 
27
 
 
28
cd $INSTANCES_PATH/$1
 
29
 
 
30
if [ $CMD != "umount" ] && [ $CMD != "launch" ]; then
 
31
# destroy the instance
 
32
virsh destroy $1
 
33
 
 
34
# mount the filesystem
 
35
mkdir t
 
36
DEVICE=`losetup --show -f disk`
 
37
echo $DEVICE
 
38
kpartx -a $DEVICE
 
39
mount /dev/mapper/${DEVICE:4}p1 t
 
40
 
 
41
fi
 
42
if [ $CMD != "mount" ] &&  [ $CMD != "umount" ]; then
 
43
 
 
44
# make serial console listen on ttyS0
 
45
cat >t/etc/init/ttyS0.conf <<TTY_EOF
 
46
# ttyS0 - getty
 
47
#
 
48
# This service maintains a getty on ttyS0 from the point the system is
 
49
# started until it is shut down again.
 
50
 
 
51
start on stopped rc RUNLEVEL=[2345]
 
52
stop on runlevel [!2345]
 
53
 
 
54
respawn
 
55
exec /sbin/getty -L 115200 ttyS0 xterm
 
56
TTY_EOF
 
57
 
 
58
echo
 
59
# set debug root password
 
60
chroot t passwd -u root
 
61
# TODO(vish): automate this with expect
 
62
chroot t passwd root
 
63
 
 
64
tr -d '\n' < libvirt.xml > debug.xml
 
65
sed -i "s/<serial type=\"file\">.*<\/serial>/<serial type=\"pty\"><source path=\"\/dev\/pts\/1\"\/><target port=\"0\"\/><\/serial>/g" debug.xml
 
66
 
 
67
umount t
 
68
 
 
69
virsh create debug.xml
 
70
virsh console $1
 
71
virsh destroy $1
 
72
 
 
73
mount /dev/mapper/${DEVICE:4}p1 t
 
74
 
 
75
# clear debug root password
 
76
chroot t passwd -l root
 
77
 
 
78
# remove the serial console conf
 
79
rm -f t/etc/init/ttyS0.conf
 
80
 
 
81
fi
 
82
if [ $CMD != "mount" ] && [ $CMD != "launch" ]; then
 
83
 
 
84
# unmount the filesystem
 
85
umount t
 
86
kpartx -d $DEVICE
 
87
losetup -d $DEVICE
 
88
rmdir t
 
89
 
 
90
# recreate the instance
 
91
virsh create libvirt.xml
 
92
fi