source: trunk/debathena/scripts/build-server/autodebathenify @ 24866

Revision 24866, 4.3 KB checked in by jdreed, 14 years ago (diff)
Whine loudly if ignored
  • Property svn:executable set to *
RevLine 
[24352]1#!/bin/bash
[23045]2
3# This script is intended to be run from a cron job by a local account
4# on a build machine--either debuild on debuild.mit.edu or builder on
5# linux-build-10.mit.edu.  The account should have:
6#
7# * A keytab installed in $HOME/keytab containing a keytab for
8#   daemon/HOSTNAME, which should have write access to the build
9#   directory and apt repository.
10#
11# * A GPG secret key capable of signing packages for the apt
12#   repository.
13#
14# * A file named $HOME/autodebathenify.config specifying shell
15#   variable assignments for:
16#   - error_addr: An email address to send errors to
17#   - scripts_dir: Directory containing Debathena scripts (da, etc.)
18#   - build_dir: Build directory location, up through "third".
19#   - packages: A list of packages to keep up to date
20#   It should also specify an environment variable assignment for
21#   DEBATHENA_APT.
22
23# Send all output to a logfile.
24mkdir -p "$HOME/logs"
25logfile=$HOME/logs/$(date '+%Y-%m-%d-%H').log
26exec </dev/null >>$logfile 2>&1
27
28# Read configuration; if it's not complete, do nothing.
29config=$HOME/autodebathenify.config
30. $HOME/autodebathenify.config
31if [ ! -n "$error_addr" -o ! -n "$scripts_dir" -o ! -n "$build_dir" -o \
32     ! -n "$packages" ]; then
33  echo "Incomplete $config; doing nothing."
34  exit
35fi
36
37suppress=$HOME/autodebathenify.suppress
38if [ -e "$suppress" ]; then
[24866]39  if [ $(($(date +%s) - $(stat -c %Y "$suppress"))) -ge 86400 ]; then
40    /usr/sbin/sendmail -t << EOM
41From: Autodebathenify <$error_addr>
42To: Autodebathenify <$error_addr>
43Subject: WARNING: Previous autodebathenify failure has not been addressed
44
45Autodebathenify previously experienced a failure on $(stat -c %y "$suppress")
46
47Please correct this failure immediately.
48
49Autodebathenify will stop running until $suppress is removed.
50EOM
51  fi
[23045]52  echo "$suppress exists; not running."
53  exit
54fi
55
56# Send an error report to $error_addr and suppress future runs until a
57# human has checked things out.  This function does not remove the run
58# file and does not exit the script.
59error() {
60  touch "$suppress"
61  /usr/sbin/sendmail -t << EOM
62From: Autodebathenify <$error_addr>
63To: Autodebathenify <$error_addr>
64Subject: Autodebathenify failure: $1
65
66Autodebathenify has experienced a failure.
67
68Please see $logfile on $(hostname) for more details.
69
70Autodebathenify will stop running until $suppress is removed.
71EOM
72}
73
[23118]74# Similar to error, but do not suppress future runs.
75error_transient() {
76  /usr/sbin/sendmail -t << EOM
77From: Autodebathenify <$error_addr>
78To: Autodebathenify <$error_addr>
79Subject: Autodebathenify failure: $1
80
81Autodebathenify has experienced a transient failure.
82
83Autodebathenify will continue running; investigation is not required
84unless this failure repeats itself.  If that happens, see $logfile on
85$(hostname) for more details.
86EOM
87}
88
89# Exit handler.  If a subsidiary command exited with status 3, we
90# treat it as a transient failure; otherwise we treat it as a failure
91# requiring human investigation.  In either case, remove the run file.
92on_failure() {
93  if [ 3 -eq "$?" ]; then
94    error_transient "$state"
95  else
96    error "$state"
97  fi
98  rm -f "$runfile"
99}
100
[23045]101# Make sure runs of this script do not overlap.
102runfile=$HOME/autodebathenify.running
103if [ -e "$runfile" ]; then
104  # A previous invocation appears to still be running.
105  pid=$(cat "$runfile")
106  if ! kill -0 "$pid" 2>/dev/null; then
107    # Okay, it's not really running.  Perhaps the machine has
108    # rebooted.  Wait for manual intervention before running again.
109    error "Stale runfile"
110  else
111    echo "$runfile exists; not running."
112  fi
[23079]113  exit
[23045]114fi
115echo $$ > $runfile
116
[23118]117trap on_failure EXIT
[23121]118set -e
[23045]119
120# Acquire credentials.
121state="acquiring credentials"
122export KRB5CCNAME=$HOME/autodebathenify.ccache
123kinit -k -t "$HOME/keytab" daemon/$(hostname --fqdn)
[23586]124aklog
[23045]125
126export PATH=${scripts_dir}:$PATH
[23118]127. "$scripts_dir"/debian-versions.sh
[23045]128
129state="changing to build dir"
130cd "$build_dir"
131for pkg in $packages; do
[23120]132  state="changing to $pkg in build dir"
133  cd "$pkg"
[23118]134  for code in $DEBIAN_CODES; do
135    state="updating $pkg for $code"
[23122]136    echo "--- Updating $pkg for $code (amd64) ---"
[23118]137    ./debathenify-"$pkg" "$code"-amd64 -A source binary upload
[23122]138    echo "--- Updating $pkg for $code (i386) ---"
[23184]139    ./debathenify-"$pkg" "$code"-i386 source binary upload
[23118]140  done
[23120]141  cd ..
[23045]142done
143
144state="cleaning up"
145kdestroy
146rm -f "$runfile"
147trap '' EXIT
Note: See TracBrowser for help on using the repository browser.