Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 263 lines (240 sloc) 8.253 kb
#! /bin/sh
# Copyright (c) 2007-2011, SUSE Inc.
#
# Author: adrian@suse.de
#
# /etc/init.d/obsworker
# and its symbolic link
# /usr/sbin/rcobsworker
#
### BEGIN INIT INFO
# Provides: obsworker
# Required-Start: $time $network $syslog
# Required-Stop: $time $network $syslog
# Should-Start: $remote_fs obsstoragesetup obssrcserver obsrepserver xendomains
# Should-Stop: $none
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Description: Open Build Service worker
### END INIT INFO
. /etc/rc.status
. /etc/sysconfig/proxy
if test -e /etc/sysconfig/obs-server; then
# optional on workers
. /etc/sysconfig/obs-server
fi
# This file may still exist from OBS 2.1 and before.
if test -e /etc/sysconfig/obs-worker; then
. /etc/sysconfig/obs-worker
fi
# Determine the base and follow a runlevel link name.
base=${0##*/}
link=${base#*[SK][0-9][0-9]}
# Preconfigured by obsstoragesetup runlevel setup script
if [ -f /etc/buildhost.config ];then
. /etc/buildhost.config
fi
if [ -z "$OBS_WORKER_DIRECTORY" ]; then
OBS_WORKER_DIRECTORY="/var/cache/obs/worker"
fi
mkdir -p "$OBS_WORKER_DIRECTORY"
if [ -z "$OBS_RUN_DIR" ]; then
OBS_RUN_DIR="/var/run/obs"
fi
if [ -z "$OBS_LOG_DIR" ]; then
OBS_LOG_DIR="/var/log/obs"
fi
if [ -z "$OBS_REPO_SERVERS" ]; then
OBS_REPO_SERVERS="localhost:5252"
fi
if [ -n "$OBS_WORKER_TEST_MODE" ]; then
OBS_TEST="--test"
fi
if [ -n "$OBS_WORKER_JOBS" ]; then
OBS_JOBS="--jobs $OBS_WORKER_JOBS"
fi
if [ -n "$OBS_WORKER_NICE_LEVEL" ]; then
OBS_NICE=$OBS_WORKER_NICE_LEVEL
else
OBS_NICE=18
fi
REPO_PARAM=
for i in $OBS_REPO_SERVERS; do
REPO_PARAM="$REPO_PARAM --reposerver http://$i"
WORKER_CODE="http://$i"
done
obsrundir="$OBS_RUN_DIR"
workerdir="$obsrundir"/worker
workerbootdir="$workerdir"/boot
screenrc="$workerdir"/boot/screenrc
OBS_WORKER_OPT=""
if [ -n "$OBS_CACHE_SIZE" -a -n "$OBS_CACHE_DIR" ]; then
OBS_WORKER_OPT="--cachedir $OBS_CACHE_DIR"
mkdir -p $OBS_CACHE_DIR
OBS_WORKER_OPT="$OBS_WORKER_OPT --cachesize $OBS_CACHE_SIZE"
fi
if [ -n "$OBS_VM_KERNEL" -a "$OBS_VM_KERNEL" != "none" ] ; then
if [ -n "$OBS_VM_INITRD" -a "$OBS_VM_INITRD" != "none" ] ; then
OBS_WORKER_OPT="$OBS_WORKER_OPT --vm-kernel $OBS_VM_KERNEL --vm-initrd $OBS_VM_INITRD"
fi
fi
if [ -n "$OBS_WORKER_LOCALKIWI_DIRECTORY" ]; then
OBS_WORKER_OPT="$OBS_WORKER_OPT --localkiwi $OBS_WORKER_LOCALKIWI_DIRECTORY --arch local"
fi
[ -z "$OBS_INSTANCE_MEMORY" ] && OBS_INSTANCE_MEMORY=256
vmopt=
if [ -n "$OBS_VM_TYPE" -a "$OBS_VM_TYPE" != "auto" ] ; then
if [ "$OBS_VM_TYPE" != "none" ] ; then
vmopt="--$OBS_VM_TYPE"
fi
elif [ -e /dev/kvm ] ; then
vmopt=--kvm
OBS_VM_TYPE="kvm"
elif [ -e /sys/hypervisor/type ] && grep -q xen /sys/hypervisor/type; then
vmopt=--xen
OBS_VM_TYPE="xen"
fi
if [ "$OBS_VM_TYPE" = "xen" -o "$OBS_VM_TYPE" = "kvm" ]; then
# we start up in VM mode, check for the worker disk options
if [ -n "$OBS_VM_DISK_AUTOSETUP_ROOT_FILESIZE" -a -n "$OBS_VM_DISK_AUTOSETUP_SWAP_FILESIZE" ]; then
VMDISK_ROOT_FILESIZE="--vmdisk-rootsize ${OBS_VM_DISK_AUTOSETUP_ROOT_FILESIZE}"
VMDISK_SWAP_FILESIZE="--vmdisk-swapsize ${OBS_VM_DISK_AUTOSETUP_SWAP_FILESIZE}"
if [ -n "$OBS_VM_DISK_AUTOSETUP_FILESYSTEM" ]; then
VMDISK_FILESYSTEM="--vmdisk-filesystem ${OBS_VM_DISK_AUTOSETUP_FILESYSTEM}"
fi
if [ -n "$OBS_VM_DISK_AUTOSETUP_MOUNT_OPTIONS" ]; then
VMDISK_MOUNT_OPTIONS="--vmdisk-mount-options ${OBS_VM_DISK_AUTOSETUP_MOUNT_OPTIONS}"
fi
fi
fi
rc_reset
case "$1" in
start)
# reset screenrc
mkdir -p "$obsrundir"
chown obsrun:obsrun "$obsrundir"
rm -rf "$workerdir"
mkdir -p "$workerbootdir"
# echo "zombie on" > $screenrc
echo "caption always" >> $screenrc
if [ 0"$OBS_WORKER_INSTANCES" -gt 0 ]; then
NUM="$OBS_WORKER_INSTANCES"
else
# start one build backend per CPU
NUM=`ls -d /sys/devices/system/cpu/cpu[0-9]* | wc -l`
fi
# print some config data
echo "Run $NUM obsworker using $OBS_WORKER_DIRECTORY"
echo -n "Type of obsworker is "
if [ "--kvm" == "$vmopt" ]; then echo "KVM virtual machine"
elif [ "--xen" == "$vmopt" ]; then echo "XEN virtual machine"
else echo "chroot"
fi
# find SLP announced OBS servers
if [ "$OBS_USE_SLP" == "yes" ]; then
for i in `slptool findsrvs service:obs.repo_server | sed -n 's/service:obs.repo_server:\([^,]*\),.*/\1/p'`; do
[ "${i#http://localhost}" != "$i" ] && continue
[ "${i#http://127.}" != "$i" ] && continue
REPO_PARAM="$REPO_PARAM --reposerver $i"
# any of them should be okay
WORKER_CODE="$i"
done
fi
# fetch worker sources from server
echo "Fetching initial worker code from $WORKER_CODE"
mkdir -p "$workerbootdir"
pushd "$workerbootdir" > /dev/null
curl -s "$WORKER_CODE"/getworkercode | cpio --quiet --extract
ln -s . XML
chmod 755 bs_worker
popd > /dev/null
OBS_WORKER_OPT1="$OBS_WORKER_OPT"
I=0
while test "$NUM" -gt "$I"; do
if [ 0"$OBS_WORKER_PORTBASE" -gt 0 ]; then
port="--port $((OBS_WORKER_PORTBASE + I))"
else
port=""
fi
I=$(( $I + 1 ))
title="$HOSTNAME/$I"
R=$OBS_WORKER_DIRECTORY/root_$I
# prepare obsworker startup in screen...
TMPFS=
if [ -n "$vmopt" -a "$OBS_VM_TYPE" = "xen" -o "$OBS_VM_TYPE" = "kvm" ]; then
mkdir -p $R
DEVICE="$OBS_WORKER_DIRECTORY/root_$I/root"
SWAP="$OBS_WORKER_DIRECTORY/root_$I/swap"
if [ -n "$OBS_VM_DISK_AUTOSETUP_ROOT_FILESIZE" -a -n "$OBS_VM_DISK_AUTOSETUP_SWAP_FILESIZE" ]; then
OBS_WORKER_OPT="$OBS_WORKER_OPT1 $VMDISK_AUTOSETUP $VMDISK_ROOT_FILESIZE $VMDISK_SWAP_FILESIZE $VMDISK_FILESYSTEM"
elif [ ! -e "$DEVICE" -o ! -e "$SWAP" ]; then
echo "ERROR: worker is configured to use a VM, but one or all of the following devices/files do not exist: $DEVICE, $SWAP"
exit 1
fi
if [ -n "$OBS_VM_USE_TMPFS" ]; then
TMPFS="--tmpfs"
fi
DEVICE="--device $DEVICE"
SWAP="--swap $SWAP"
MEMORY="--vm-memory $OBS_INSTANCE_MEMORY"
else
mkdir -p $R
DEVICE=
SWAP=
MEMORY=
fi
echo "screen -t $title nice -n $OBS_NICE ./bs_worker $vmopt $port --root $R" \
"--statedir $workerdir/$I --id $HOSTNAME/$I $REPO_PARAM" \
"$OBS_JOBS $OBS_TEST $OBS_WORKER_OPT $TMPFS $DEVICE $SWAP $MEMORY" \
>> $screenrc
mkdir -p $workerdir/$I
done
pushd "$workerbootdir" > /dev/null
screen -m -d -c $screenrc
popd > /dev/null
;;
stop)
echo -n "Shutting down obsworker"
for I in "$workerdir"/*; do
test -d "$I" || continue
test -e "$I/state" || continue
pushd "$workerbootdir" > /dev/null
./bs_worker --statedir "$I" --exit &
popd > /dev/null
done
wait
killall bs_worker 2>/dev/null
sleep 2
killall -s 9 bs_worker 2>/dev/null
rc_status -v
;;
restart)
## If first returns OK call the second, if first or
## second command fails, set echo return value.
$0 stop
$0 start
rc_status
;;
try-restart)
$0 status
if test $? = 0; then
$0 restart
else
rc_reset # Not running is not a failure.
fi
# Remember status and be quiet
rc_status
;;
reload)
;;
status)
echo -n "Checking for obsworker: "
checkproc bs_worker
rc_status -v
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart|reload}"
exit 1
;;
esac
rc_exit
Jump to Line
Something went wrong with that request. Please try again.