~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/buildd/scan-for-processes

  • Committer: mbp at canonical
  • Date: 2011-11-20 23:37:23 UTC
  • mto: This revision was merged to the branch mainline in revision 14344.
  • Revision ID: mbp@canonical.com-20111120233723-370p96db2crru5tm
Delete canonical.buildd again

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
#
3
 
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
 
# GNU Affero General Public License version 3 (see the file LICENSE).
5
 
 
6
 
# Buildd Slave tool to scan a chroot in case any processes are underneath it
7
 
 
8
 
## This script uses bashisms, must be run under bash
9
 
 
10
 
# Expects build id as arg 1, makes build-id to contain the build
11
 
 
12
 
# Needs SUDO to be set to a sudo instance for passwordless access
13
 
 
14
 
SUDO=/usr/bin/sudo
15
 
BUILDID="$1"
16
 
REALHOME=$(cd $HOME && pwd -P)
17
 
 
18
 
set -e
19
 
 
20
 
exec 2>&1
21
 
 
22
 
[ $(id -u) = "0" ] || exec $SUDO $0 "$REALHOME/build-$BUILDID/chroot-autobuild"
23
 
 
24
 
echo "Scanning for processes to kill in build $BUILDID..."
25
 
 
26
 
PREFIX="$BUILDID"
27
 
FOUND=0
28
 
 
29
 
for ROOT in /proc/*/root; do
30
 
    LINK=$(readlink $ROOT)
31
 
    if [ "x$LINK" != "x" ]; then
32
 
        if [ "x${LINK:0:${#PREFIX}}" = "x$PREFIX" ]; then
33
 
            # this process is in the chroot...
34
 
            PID=$(basename $(dirname "$ROOT"))
35
 
            kill -9 "$PID"
36
 
            FOUND=1
37
 
        fi
38
 
    fi
39
 
done
40
 
 
41
 
if [ "x$FOUND" = "x1" ]; then
42
 
  exec $0 $1
43
 
fi