User:Bhearsum:Build/Buildserver ref image: Difference between revisions

added buildbot start with system
(→‎Create a buildbot master: changed bb master dir)
(added buildbot start with system)
Line 200: Line 200:
</pre>
</pre>


TODO: Have Buildbot start with the machine.
== Set-up Buildbot to start with the system ==
Create the file '/etc/default/buildbot' with the following contents:
<pre>
# buildbots to manage
# add a new set of variables for each buildbot to start
 
# BB_NUMBER    -> index for the buildbot
# BB_NAME      -> short name that is printed when starting/stopping
# BB_USER      -> user to run the buildbot as
# BB_BASEDIR  -> the absolute path to the buildbot master or slave
# BB_OPTIONS  -> extra options to pass to buildbot
# BB_PREFIXCMD -> prefix command, ie. nice, linux32, etc.
#
# Each of the preceeding are arrays. Each Buildbot you wish to run should
# increase the index of each. For example, the first Buildbot should use
# [0] on each array. The next one uses [1], etc.
 
BB_NUMBER[0]=0
BB_NAME[0]="Default Buildbot"
BB_USER[0]="buildbot"
BB_BASEDIR[0]="/buildbot/default/"
BB_OPTIONS[0]=""
BB_PREFIXCMD[0]=""
</pre>
 
Create the file '/etc/init.d/buildbot' with the following contents:
<pre>
#! /bin/bash
# initscript for buildbot
 
### BEGIN INIT INFO
# Provides:          cvsd
# Required-Start:    $local_fs $network
# Required-Stop:    $local_fs
# Should-Start:      $remote_fs
# Should-Stop:      $remote_fs
# Default-Start:    2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: Buildbot
# Description:      Buildbot
### END INIT INFO
 
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC="BuildBot"
 
USER=buildbot
 
DAEMON=/tools/buildbot/bin/buildbot
DNAME=buildbot
PROCNAME=$NAME
 
[ -r /etc/default/buildbot ] && . /etc/default/buildbot
 
test -x ${DAEMON} || exit 0
 
. /lib/lsb/init-functions
 
check_config()
{
    errors=0
    for i in ${BB_NUMBER[@]}; do
[ $i -ge 0 ] || continue
if [ -z "${BB_NAME[$i]}" ]; then
    echo >&2 "buildbot $i: no name"
    errors=$(($errors+1))
fi
if [ -z "${BB_USER[$i]}" ]; then
    echo >&2 "buildbot $i: no user"
    errors=$(($errors+1))
elif ! getent passwd ${BB_USER[$i]} >/dev/null; then
    echo >&2 "buildbot $i: unknown user ${BB_USER[$i]}"
    errors=$(($errors+1))
fi
if [ ! -d "${BB_BASEDIR[$i]}" ]; then
    echo >&2 "buildbot $i: no base directory ${BB_BASEDIR[$i]}"
    errors=$(($errors+1))
fi
    done
    [ $errors -eq 0 ] || exit 1
}
 
check_config
 
start_buildbot() {
    NAME="$1"
    USER="$2"
    BASEDIR="$3"
    PREFIXCMD="$4"
    OPTIONS="$5"
 
    #START="--start --quiet --exec ${DAEMON} --name ${NAME} --pidfile ${BASEDIR}/twistd.pid"
    #[ -n "${USER}" ] && START="${START} --chuid ${USER}"
    #START="${START} -- start ${BASEDIR} ${OPTIONS}"
    #${PREFIXCMD} start-stop-daemon ${START} >/dev/null 2>&1
    ${PREFIXCMD} su -s /bin/bash -c "${DAEMON} start ${BASEDIR} ${OPTIONS}" - ${USER}
    return $?
}
 
stop_buildbot() {
    NAME="$1"
    USER="$2"
    BASEDIR="$3"
    PREFIXCMD="$4"
 
    ${PREFIXCMD} su -s /bin/bash -c "${DAEMON} stop ${BASEDIR}" - ${USER}
    return $?
}
 
reload_buildbot() {
    NAME="$1"
    USER="$2"
    BASEDIR="$3"
    PREFIXCMD="$4"
 
    ${PREFIXCMD} su -s /bin/bash -c "${DAEMON} sighup ${BASEDIR}" - ${USER}
    return $?
}
 
do_start () {
    errors=0
    for i in ${BB_NUMBER[@]}; do
[ $i -ge 0 ] || continue
echo "Starting buildbot ${BB_NAME[$i]}"
if start_buildbot "${BB_NAME[$i]}" "${BB_USER[$i]}" "${BB_BASEDIR[$i]}" \
    "${BB_PREFIXCMD[$i]}" "${BB_OPTIONS[$i]}"
then
    echo "started"
else
    echo "not started"
    errors=$(($errors+1))
fi
    done
    return $errors
}
 
do_stop () {
    errors=0
    for i in ${BB_NUMBER[@]}; do
[ $i -ge 0 ] || continue
echo "Stopping buildbot ${BB_NAME[$i]}"
if stop_buildbot "${BB_NAME[$i]}" "${BB_USER[$i]}" "${BB_BASEDIR[$i]}" \
    "${BB_PREFIXCMD[$i]}"
then
    echo "stopped"
else
    echo "not stopped"
    errors=$(($errors+1))
fi
    done
    return $errors
}
 
do_reload () {
    errors=0
    for i in ${BB_NUMBER[@]}; do
[ $i -ge 0 ] || continue
echo "Reload buildbot ${BB_NAME[$i]}"
if reload_buildbot "${BB_NAME[$i]}" "${BB_USER[$i]}" "${BB_BASEDIR[$i]}" \
    "${BB_PREFIXCMD[$i]}"
then
    echo "reloaded"
else
    echo "not reloaded"
    errors=$(($errors+1))
fi
    done
    return $errors
}
 
do_restart () {
    errors=0
    for i in ${BB_NUMBER[@]}; do
[ $i -ge 0 ] || continue
echo "Restarting buildbot ${BB_NAME[$i]}"
stop_buildbot "${BB_NAME[$i]}" "${BB_USER[$i]}" "${BB_BASEDIR[$i]}" \
    "${BB_PREFIXCMD[$i]}" || true
if start_buildbot "${BB_NAME[$i]}" "${BB_USER[$i]}" "${BB_BASEDIR[$i]}" \
    "${BB_PREFIXCMD[$i]}" "${BB_OPTIONS[$i]}"
then
    echo "restarted"
else
    echo "not restarted"
    errors=$(($errors+1))
fi
    done
    return $errors
}
 
case "$1" in
  start)
  do_start
  exit $?
;;
  stop)
  do_stop
  exit $?
;;
  reload)
  do_reload
  exit $?
;;
  restart|force-reload)
  do_restart
  exit $?
;;
  *)
log_warning_msg "Usage: $0 {start|stop|restart|reload|force-reload}"
exit 1
;;
esac
 
exit 0
</pre>
 
Run the following command to add buildbot to the init scripts:
chkconfig --add buildbot
canmove, Confirmed users
6,441

edits