1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#! /bin/sh
# ex: et sw=4 ts=4 sts=4
set -e
HOME_DIR=/var/lib/buildbot
WORKERS_DIR=$HOME_DIR/workers
SLAVES_DIR=$HOME_DIR/slaves
USER_NAME=buildbot
USER_DESCR="Buildbot system user"
handle_old_slave()
{
local basedir="$1"
local pid
echo "Buildbot slave instance in $basedir has been created with a 0.x version and cannot be automatically upgraded."
echo "Please see buildbot-worker(7) for instructions."
if [ -r "$basedir/twistd.pid" ]; then
pid=$(cat $basedir/twistd.pid)
fi
if kill -0 "$pid" >/dev/null 2>&1; then
echo "Stopping buildbot slave in $basedir (PID $pid) ..."
kill -TERM "$pid" || true
fi
}
restart_worker()
{
local basedir="$1"
local name="$(basename $basedir)"
if ! [ -d "$basedir" ]; then
return
fi
if [ "$(dirname $basedir)" = "$SLAVES_DIR" ]; then
handle_old_slave "$basedir"
return
fi
if [ -d /run/systemd/system ]; then
if systemctl is-active --quiet "buildbot-worker@$name.service"; then
echo "Restarting buildbot worker instance in $basedir ..."
deb-systemd-invoke restart "buildbot-worker@$name.service" >/dev/null
fi
else
if invoke-rc.d buildbot-worker status "$name" >/dev/null 2>&1; then
echo "Restarting buildbot worker instance in $basedir ..."
invoke-rc.d buildbot-worker restart "$name" >/dev/null
fi
fi
}
case "$1" in
configure)
# Create builbot user account if not exist
if ! getent passwd buildbot>/dev/null; then
echo "Creating $USER_DESCR ..."
useradd \
--system \
--shell /bin/false \
--no-create-home \
--user-group \
--comment "$USER_DESCR" \
--home-dir "$HOME_DIR" \
"$USER_NAME"
fi
mkdir -p $HOME_DIR
mkdir -p $WORKERS_DIR
# Fix permissions
chown $USER_NAME: $HOME_DIR $WORKERS_DIR
existing_workers=$(find $WORKERS_DIR -mindepth 1 -maxdepth 1 -type d -print -quit)
if [ -z "$1" ]; then
# first install
if [ -z "$existing_workers" ]; then
echo "No worker instances are configured. See buildbot-worker(7) for instructions."
fi
else
# package upgrade
for inst in $SLAVES_DIR/* $WORKERS_DIR/*; do
restart_worker $inst
done
fi
update-rc.d buildbot-worker defaults >/dev/null
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
exit 0
|