source: trunk/debathena/config/auto-update/debian/athena-auto-upgrade @ 25253

Revision 25253, 4.7 KB checked in by jdreed, 13 years ago (diff)
In auto-update: * Don't kexec -e, instead reboot and rely on the init script
Line 
1#!/bin/bash
2#
3# This is designed to be called from cron
4
5debug() {
6    [ $DEBUG -eq 1 ] && echo "DEBUG: $*"
7}
8
9complain() {
10    if [ $DEBUG -eq 1 ]; then
11        echo "ERROR: $*"
12    else
13        logger -t "athena-auto-upgrade" -p user.notice "$*"
14    fi
15}
16
17DEBUG=0
18MAYBE=""
19if [ "$1" = "--debug" ]; then
20    DEBUG=1
21    MAYBE=echo
22else
23    # Redirect output to a log file
24    # Unless we're in debug mode
25    exec >>/var/log/athena-upgrade 2>&1
26fi
27
28echo "Starting upgrade at $(date)"
29
30
31UPGRADE_TO_TESTING=no
32UPGRADE_ANYWAY=no
33[ -f /etc/default/debathena-auto-update ] && . /etc/default/debathena-auto-update
34
35if [ $DEBUG -eq 1 ]; then
36    UPGRADE_TO_TESTING=yes
37    UPGRADE_ANYWAY=yes
38fi
39
40# Not supported on Debian
41if [ "$(lsb_release -si)" != "Ubuntu" ]; then
42    debug "Only supported on Ubuntu.".
43    exit 0
44fi
45
46# Skip other sanity checks in debug mode
47if [ $DEBUG -ne 1 ]; then
48    # Only run this on cluster
49    if [ "$(machtype -L)" != "debathena-cluster" ] && \
50       [ "$UPGRADE_ANYWAY" != "yes" ]; then
51        debug "Not a cluster machine and UPGRADE_ANYWAY != yes.".
52        exit 0
53    fi
54   
55    # Bail if someone is logged in (stolen from auto-update)
56    ttys=$(w -h -s | awk '{print $2}')
57    for tty in $ttys; do
58        pids=$(ps --no-heading -j -t "$tty" 2>/dev/null \
59            | awk '($1 == $3) {print $1}')
60        if [ -n "$pids" ]; then
61            debug "Users logged in, won't continue."
62            debug "PIDs: $pids"
63            exit 0
64        fi
65    done
66    # screen processes count as logins.
67    if pgrep '^screen' > /dev/null; then
68        debug "Screen processes found, won't continue."
69        exit 0
70    fi
71fi
72
73CLUSTERINFO=`getcluster -b $(lsb_release -sr)`
74[ $? != 0 ] && complain "Failed to get clusterinfo" && exit 1
75eval $CLUSTERINFO
76if [ ! -z "$NEW_PRODUCTION_RELEASE" ]; then
77    debug "Taking new production release: $NEW_PRODUCTION_RELEASE"
78    NEWCLUSTER=`getcluster -b $NEW_PRODUCTION_RELEASE`
79    [ $? != 0 ] && complain "Failed to get clusterinfo" && exit 1
80    eval $NEWCLUSTER
81elif [ ! -z "$NEW_TESTING_RELEASE" ] && \
82    [ "$UPGRADE_TO_TESTING" = "yes" ]; then
83    debug "Taking new testing release: $NEW_TESTING_RELEASE"
84    NEWCLUSTER=`getcluster -b $NEW_TESTING_RELEASE`
85    [ $? != 0 ] && complain "Failed to get clusterinfo" && exit 1
86    eval $NEWCLUSTER
87else
88    debug "No new releases."
89    exit 0
90fi
91if [ "$(lsb_release -sc)" = "$UBUNTU_RELEASE" ]; then
92    complain "Tried to upgrade to already running release; shouldn't happen"
93    exit 1
94fi
95debug "OK, trying to upgrade to $UBUNTU_RELEASE"
96
97# That's a space and then a tab inside the brackets
98if egrep -q '^flags[    ].* lm( |$)' /proc/cpuinfo; then
99    arch=amd64
100else
101    arch=i386
102fi
103debug "Arch: $arch"
104IPADDR=
105NETMASK=
106eval `ifconfig eth0 |perl -ne'/^\s+inet addr:([\d\.]+).*? Mask:([\d\.]+)/ && print "IPADDR=$1 NETMASK=$2"'`
107if [ -z "$IPADDR" ]; then
108    complain "Couldn't get IPADDR from ifconfig!"
109    exit 0
110fi
111GATEWAY=`route -n | awk '/^0\.0\.0\.0/ { print $2 }'`
112debug "Using IPADDR=$IPADDR"
113debug "Using NETMASK=$NETMASK"
114debug "Using GATEWAY=$GATEWAY"
115if [ -n "$NETMASK" ] && [ -n "$GATEWAY" ]; then
116  knetinfo="netcfg/get_hostname=$(hostname) \
117            netcfg/disable_dhcp=true \
118            netcfg/get_domain=mit.edu \
119            netcfg/get_nameservers=\"18.72.0.3 18.70.0.160\"\
120            netcfg/get_ipaddress=$IPADDR \
121            netcfg/get_netmask=$NETMASK \
122            netcfg/get_gateway=$GATEWAY \
123            netcfg/confirm_static=true"
124else
125  knetinfo="netcfg/dhcp_timeout=60 netcfg/get_hostname=$(hostname)"
126fi
127
128$MAYBE mkdir /h
129$MAYBE cd /h
130$MAYBE wget -N http://debathena.mit.edu/net-install/${UBUNTU_RELEASE}/${arch}/initrd.gz
131$MAYBE wget -N http://debathena.mit.edu/net-install/${UBUNTU_RELEASE}/${arch}/linux
132case "$UBUNTU_RELEASE" in
133    natty)
134        # Sigh
135        kbdcode="keyboard-configuration/layoutcode=us"
136        ;;
137    *)
138        kbdcode="console-setup/layoutcode=us"
139        ;;
140esac
141# This is just the guts of the hackboot script:
142dkargs="DEBCONF_DEBUG=5"
143kargs="$knetinfo locale=en_US $kbdcode \
144       interface=auto \
145       url=http://18.9.60.73/installer/${UBUNTU_RELEASE}/debathena.preseed \
146       debathena/pxetype=cluster --"
147if [ $(echo $kargs | wc -c) -ge 512 ]; then
148  complain "kargs exceeds 512 bytes.  That's not good."
149fi
150debug "Would execute kexec with --append=\"$dkargs $kargs\""
151if [ $DEBUG -eq 1 ]; then
152    exit 0
153fi
154# Don't kexec -e here, because modern Ubuntu is unable to kexec while
155# X is running.  Instead, kexec -l and let the init script take care of.
156# Until Oneiric, when this will probably stop working if kexec-tools hasn't
157# been Upstartified.
158/sbin/kexec -l linux --append="$dkargs $kargs" --initrd=initrd.gz
159if [ "`cat /sys/kernel/kexec_loaded`" != "1" ]; then
160  echo "Hrm, looks like kexec -l didn't work.  This upgrade might fail."
161fi
162reboot
163exit 0
Note: See TracBrowser for help on using the repository browser.