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

Revision 24926, 3.8 KB checked in by jdreed, 13 years ago (diff)
In auto-update: * Don't depend on at, because bad things happen (Trac #782)
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
17# Redirect output to a log file
18exec >>/var/log/athena-upgrade 2>&1
19echo "Starting upgrade at $(date)"
20
21DEBUG=0
22MAYBE=""
23if [ "$1" = "--debug" ]; then
24    DEBUG=1
25    MAYBE=echo
26fi
27
28UPGRADE_TO_TESTING=no
29UPGRADE_ANYWAY=no
30[ -f /etc/default/debathena-auto-update ] && . /etc/default/debathena-auto-update
31
32if [ $DEBUG -eq 1 ]; then
33    UPGRADE_TO_TESTING=yes
34    UPGRADE_ANYWAY=yes
35fi
36
37# Not supported on Debian
38if [ "$(lsb_release -si)" != "Ubuntu" ]; then
39    debug "Only supported on Ubuntu.".
40    exit 0
41fi
42
43# Skip other sanity checks in debug mode
44if [ $DEBUG -ne 1 ]; then
45    # Only run this on cluster
46    if [ "$(machtype -L)" != "debathena-cluster" ] && \
47       [ "$UPGRADE_ANYWAY" != "yes" ]; then
48        debug "Not a cluster machine and UPGRADE_ANYWAY != yes.".
49        exit 0
50    fi
51   
52    # Bail if someone is logged in (stolen from auto-update)
53    ttys=$(w -h -s | awk '{print $2}')
54    for tty in $ttys; do
55        pids=$(ps --no-heading -j -t "$tty" 2>/dev/null \
56            | awk '($1 == $3) {print $1}')
57        if [ -n "$pids" ]; then
58            debug "Users logged in, won't continue."
59            debug "PIDs: $pids"
60            exit 0
61        fi
62    done
63    # screen processes count as logins.
64    if pgrep '^screen' > /dev/null; then
65        debug "Screen processes found, won't continue."
66        exit 0
67    fi
68fi
69
70if [ "$1" = "cron" ]; then
71    interval=21600
72    shopt -s nocasematch
73    case `hostname` in
74        m38-370*)
75            interval=43200
76            ;;
77        w20-575*)
78            interval=28800
79            ;;
80    esac
81    if ! desync -t /var/run/athena-upgrade.desync $interval; then
82        exit 0
83    fi
84fi   
85
86CLUSTERINFO=`getcluster -b $(lsb_release -sr)`
87[ $? != 0 ] && complain "Failed to get clusterinfo" && exit 1
88eval $CLUSTERINFO
89if [ ! -z "$NEW_PRODUCTION_RELEASE" ]; then
90    debug "Taking new production release: $NEW_PRODUCTION_RELEASE"
91    NEWCLUSTER=`getcluster -b $NEW_PRODUCTION_RELEASE`
92    [ $? != 0 ] && complain "Failed to get clusterinfo" && exit 1
93    eval $NEWCLUSTER
94elif [ ! -z "$NEW_TESTING_RELEASE" ] && \
95    [ "$UPGRADE_TO_TESTING" = "yes" ]; then
96    debug "Taking new testing release: $NEW_TESTING_RELEASE"
97    NEWCLUSTER=`getcluster -b $NEW_TESTING_RELEASE`
98    [ $? != 0 ] && complain "Failed to get clusterinfo" && exit 1
99    eval $NEWCLUSTER
100else
101    debug "No new releases."
102    exit 0
103fi
104if [ "$(lsb_release -sc)" = "$UBUNTU_RELEASE" ]; then
105    complain "Tried to upgrade to already running release; shouldn't happen"
106    exit 1
107fi
108debug "OK, trying to upgrade to $UBUNTU_RELEASE"
109
110# That's a space and then a tab inside the brackets
111if egrep -q '^flags[    ].* lm( |$)' /proc/cpuinfo; then
112    arch=amd64
113else
114    arch=i386
115fi
116debug "Arch: $arch"
117IPADDR=`ifconfig eth0 |perl -ne'/^\s+inet addr:([\d\.]+)/ && print $1'`
118if [ -z "$IPADDR" ]; then
119    complain "Couldn't get IP address from ifconfig!"
120    exit 0
121fi
122debug "Using IPADDR=$IPADDR"
123$MAYBE mkdir /h
124$MAYBE cd /h
125$MAYBE wget -N http://debathena.mit.edu/net-install/${UBUNTU_RELEASE}/${arch}/initrd.gz
126$MAYBE wget -N http://debathena.mit.edu/net-install/${UBUNTU_RELEASE}/${arch}/linux
127# This is just the guts of the hackboot script:
128dkargs="DEBCONF_DEBUG=5"
129kargs="netcfg/get_hostname= locale=en_US console-setup/layoutcode=us \
130       interface=auto \
131       url=http://18.9.60.73/installer/${UBUNTU_RELEASE}/debathena.preseed \
132       debathena/clusterforce=yes debathena/clusteraddr=$IPADDR --"
133debug "Would execute kexec with --append=\"$dkargs $kargs\""
134if [ $DEBUG -eq 1 ]; then
135    exit 0
136fi
137/sbin/kexec -l linux --append="$dkargs $kargs" --initrd=initrd.gz \
138    && sleep 3 && chvt 1 && sleep 2 && /sbin/kexec -e
139complain "Failed to kexec."
140exit 1
Note: See TracBrowser for help on using the repository browser.