From: Peter Palfrader Date: Fri, 23 Oct 2009 17:58:12 +0000 (+0200) Subject: Add buildd-reboot script X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dsa-metapackages.git;a=commitdiff_plain;h=205d6d70eb332f0e2070abff5750b7ea34ad4795;ds=sidebyside Add buildd-reboot script --- diff --git a/Makefile b/Makefile index bc1c7ad..1637ee0 100644 --- a/Makefile +++ b/Makefile @@ -4,3 +4,4 @@ install: install -d -m 755 $(DESTDIR)/usr/sbin install -m755 upgrade-porter-chroots $(DESTDIR)/usr/sbin install -m755 apache2-vhost-update $(DESTDIR)/usr/sbin + install -m755 buildd-reboot $(DESTDIR)/usr/sbin diff --git a/buildd-reboot b/buildd-reboot new file mode 100755 index 0000000..d082ef2 --- /dev/null +++ b/buildd-reboot @@ -0,0 +1,114 @@ +#!/bin/bash + +# script to shutdown a system running buildd in a controlled way + +# Copyright (c) 2009 Peter Palfrader +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +set -e +set -u + + +usage() { + echo "Usage: $0 [-h] " >&2 + echo " -h is for halt, not for help" + exit 3 +} + +halt=0 +if [ "${1:-""}" == '-h' ] ; then + halt=1 + shift +fi + +if [ "$#" != 1 ]; then + usage +fi +reason="$1" + + + +wall_counter=0 +maybe_wall() { + wall_counter=$((wall_counter-1)) + if [ "$wall_counter" -le 0 ]; then + if [ "$host" = 1 ]; then + echo "System will halt for $reason when buildd has stopped" | wall + else + echo "System will reboot for $reason when buildd has stopped" | wall + fi + wall_counter=720 + fi +} + +buildd_wait_and_reboot() { + echo -n "Waiting for buildd to shut down" + + while test -e ~buildd/build/buildd.pid ; do + echo -n "." + sleep 5 + maybe_wall + done + echo + + if pgrep -u buildd -x buildd ; then + echo "pidfile is gone, but buildd process still runs" + while pgrep -u buildd -x buildd ; do + echo -n "." + sleep 5 + maybe_wall + done + echo + fi + + if [ "$host" = 1 ]; then + /sbin/shutdown -p 15 "$reason" + else + /sbin/shutdown -p 15 "$reason" + fi +} + +if [ "`id -u`" != 0 ]; then + echo "This probably wants running as root" >&2 + exit 3 +fi +if ! id buildd > /dev/null 2>&1; then + echo "Is there a buildd user?" >&2 + exit 3 +fi +if ! [ -d ~buildd ]; then + echo "No ~buildd?" >&2 + exit 3 +fi + +if ! test -e ~buildd/NO-DAEMON-PLEASE; then + echo "Touching ~buildd/NO-DAEMON-PLEASE ~buildd/EXIT-DAEMON-PLEASE" + sudo -u buildd touch ~buildd/NO-DAEMON-PLEASE ~buildd/EXIT-DAEMON-PLEASE + sudo -u buildd sh -c 'echo delete-on-boot > ~buildd/NO-DAEMON-PLEASE' + sudo chgrp -v adm ~buildd/NO-DAEMON-PLEASE + + echo "Sending HUP to buildd" + sudo -u buildd kill -HUP `sudo cat ~buildd/build/buildd.pid` +else + echo "no-daemon-please already exists" +fi + +buildd_wait_and_reboot diff --git a/debian/changelog b/debian/changelog index 2568632..975bcff 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -debian.org (2X) Xtable; urgency=low +debian.org (23) stable; urgency=low * New dependencies of debian.org-recommended: - man-db @@ -9,8 +9,9 @@ debian.org (2X) Xtable; urgency=low - python-apt * New dependencies of debian.org-buildd.debian.org: - r-cran-lattice + * Add buildd-reboot script. - -- Peter Palfrader Tue, 06 Oct 2009 22:04:16 +0200 + -- Peter Palfrader Fri, 23 Oct 2009 19:56:43 +0200 debian.org (22) stable; urgency=low