Skip to content

Commit

Permalink
Merge branch 'misc' of git://github.com/gvalkov/buildbot
Browse files Browse the repository at this point in the history
* 'misc' of git://github.com/gvalkov/buildbot:
  Fix wrong indent level (oops)
  Move buildslave init script and config template to slave/contrib
  Add a short paragraph about the new init scripts
  Add chkconfig compatibility header to init scripts
  Init script fixes and improvements.
  A stop action on an already stopped master/slave should return 0
  Added init scripts capable of starting multiple buildmasters/buildslaves
  • Loading branch information
Dustin J. Mitchell committed Oct 24, 2010
2 parents 2105fad + 99dc8fc commit c669fea
Show file tree
Hide file tree
Showing 7 changed files with 335 additions and 3 deletions.
8 changes: 7 additions & 1 deletion master/buildbot/scripts/runner.py
Expand Up @@ -1131,7 +1131,13 @@ def run():

start(so)
elif command == "stop":
stop(so, wait=True)
try:
stop(so, wait=True)
except BuildbotNotRunningError:
if not so['quiet']:
print "buildmaster not running"
sys.exit(0)

elif command == "restart":
restart(so)
elif command == "reconfig" or command == "sighup":
Expand Down
8 changes: 8 additions & 0 deletions master/contrib/init-scripts/buildmaster.default
@@ -0,0 +1,8 @@
MASTER_RUNNER=/usr/bin/buildbot

MASTER_ENABLED[1]=0 # 0-enabled, other-disabled
MASTER_NAME[1]="buildmaster #1" # short name printed on start/stop
MASTER_USER[1]="buildbot" # user to run master as
MASTER_BASEDIR[1]="" # basedir to master (absolute path)
MASTER_OPTIONS[1]="" # buildbot options
MASTER_PREFIXCMD[1]="" # prefix command, i.e. nice, linux32, dchroot
142 changes: 142 additions & 0 deletions master/contrib/init-scripts/buildmaster.init.sh
@@ -0,0 +1,142 @@
#!/bin/bash

### Maintain compatibility with chkconfig
# chkconfig: 2345 83 17
# description: buildmaster

### BEGIN INIT INFO
# Provides: buildmaster
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
MASTER_RUNNER=/usr/bin/buildbot

. /lib/lsb/init-functions

# Source buildmaster configuration
[[ -r /etc/default/buildbot ]] && . /etc/default/buildbot
#[[ -r /etc/sysconfig/buildbot ]] && . /etc/sysconfig/buildbot

# Or define/override the configuration here
#MASTER_ENABLED[1]=0 # 0-enabled, other-disabled
#MASTER_NAME[1]="buildmaster #1" # short name printed on start/stop
#MASTER_USER[1]="buildbot" # user to run master as
#MASTER_BASEDIR[1]="" # basedir to master (absolute path)
#MASTER_OPTIONS[1]="" # buildbot options
#MASTER_PREFIXCMD[1]="" # prefix command, i.e. nice, linux32, dchroot

if [[ ! -x ${MASTER_RUNNER} ]]; then
log_failure_msg "does not exist or not an executable file: ${MASTER_RUNNER}"
exit 1
fi

function check_config() {
itemcount="${#MASTER_ENABLED[@]}
${#MASTER_NAME[@]}
${#MASTER_USER[@]}
${#MASTER_BASEDIR[@]}
${#MASTER_OPTIONS[@]}
${#MASTER_PREFIXCMD[@]}"

if [[ $(echo "$itemcount" | tr -d ' ' | sort -u | wc -l) -ne 1 ]]; then
log_failure_msg "MASTER_* arrays must have an equal number of elements!"
return 1
fi

errors=0
for i in $( seq ${#MASTER_ENABLED[@]} ); do
if [[ ${MASTER_ENABLED[$i]} -ne 0 ]]; then
log_failure_msg "buildmaster #${i}: unknown run status"
errors=$(($errors+1))
fi

if [[ -z ${MASTER_NAME[$i]} ]]; then
log_failure_msg "buildmaster #${i}: no name"
errors=$(($errors+1))
fi

if [[ -z ${MASTER_USER[$i]} ]]; then
log_failure_msg "buildmaster #${i}: no run user specified"
errors=$( ($errors+1) )
elif ! getent passwd ${MASTER_USER[$i]} >/dev/null; then
log_failure_msg "buildmaster #${i}: unknown user ${MASTER_USER[$i]}"
errors=$(($errors+1))
fi

if [[ ! -d "${MASTER_BASEDIR[$i]}" ]]; then
log_failure_msg "buildmaster ${i}: basedir does not exist ${MASTER_BASEDIR[$i]}"
errors=$(($errors+1))
fi
done

[[ $errors == 0 ]]; return $?
}

check_config || exit $?

function iscallable () { type $1 2>/dev/null | grep -q 'shell function'; }

function master_op () {
op=$1 ; mi=$2

${MASTER_PREFIXCMD[$1]} \
su -s /bin/sh \
-c "$MASTER_RUNNER $op --quiet ${MASTER_OPTIONS[$mi]} ${MASTER_BASEDIR[$mi]}" \
- ${MASTER_USER[$mi]}
return $?
}

function do_op () {
errors=0
for i in $( seq ${#MASTER_ENABLED[@]} ); do
[[ ${MASTER_ENABLED[$i]} -ne 0 ]] && continue

# Some rhels don't come with all the lsb goodies
if iscallable log_daemon_msg; then
log_daemon_msg "$3 \"${MASTER_NAME[$i]}\""
if eval $1 $2 $i; then
log_end_msg 0
else
log_end_msg 1
errors=$(($errors+1))
fi
else
if eval $1 $2 $i; then
log_success_msg "$3 \"${MASTER_NAME[$i]}\""
else
log_failure_msg "$3 \"${MASTER_NAME[$i]}\""
errors=$(($errors+1))
fi
fi
done
return $errors
}

case "$1" in
start)
do_op "master_op" "start" "Starting buildmaster"
exit $?
;;
stop)
do_op "master_op" "stop" "Stopping buildmaster"
exit $?
;;
reload)
do_op "master_op" "reload" "Reloading buildmaster"
exit $?
;;
restart|force-reload)
do_op "master_op" "restart" "Restarting buildmaster"
exit $?
;;
*)
echo "Usage: $0 {start|stop|restart|reload|force-reload}"
exit 1
;;
esac

exit 0
26 changes: 26 additions & 0 deletions master/docs/installation.texinfo
Expand Up @@ -654,6 +654,32 @@ Debian-based distributions, you may only need to modify
@code{/etc/default/buildbot} (see also @code{/etc/init.d/buildbot}, which
reads the configuration in @code{/etc/default/buildbot}).

Buildbot also comes with its own init scripts that provide support for
controlling multi-slave and multi-master setups (mostly because they are based
on the init script from the debian package). With a little modification these
scripts can be used both on debian and rhel based distributions and may thus
prove helpful to package maintainers who are working on buildbot (or those that
haven't yet split buildbot into master and slave packages).

@example
# install as /etc/default|sysconfig/buildslave
master/contrib/init-scripts/buildslave.default
# install /etc/default|sysconfig/buildslave
master/contrib/init-scripts/buildmaster.default
# install as /etc/init.d/buildslave
slave/contrib/init-scripts/buildslave.init.sh
# install as /etc/init.d/buildmaster
slave/contrib/init-scripts/buildmaster.init.sh
# ... and tell sysvinit about them
chkconfig buildmaster reset
# ... or
update-rc.d buildmaster defaults
@end example

@node Logfiles
@section Logfiles

Expand Down
4 changes: 2 additions & 2 deletions slave/buildslave/scripts/runner.py
Expand Up @@ -182,8 +182,8 @@ def stop(config, signame="TERM", wait=False, returnFalseOnNotRunning=False):
except:
if returnFalseOnNotRunning:
return False
print "buildslave not running."
sys.exit(1)
if not quiet: print "buildslave not running."
sys.exit(0)
pid = int(f.read().strip())
signum = getattr(signal, "SIG"+signame)
timer = 0
Expand Down
8 changes: 8 additions & 0 deletions slave/contrib/init-scripts/buildslave.default
@@ -0,0 +1,8 @@
SLAVE_RUNNER=/usr/bin/buildslave

SLAVE_ENABLED[1]=0 # 0-enabled, other-disabled
SLAVE_NAME[1]="buildslave #1" # short name printed on start/stop
SLAVE_USER[1]="buildbot" # user to run slave as
SLAVE_BASEDIR[1]="" # basedir to slave (absolute path)
SLAVE_OPTIONS[1]="" # buildbot options
SLAVE_PREFIXCMD[1]="" # prefix command, i.e. nice, linux32, dchroot
142 changes: 142 additions & 0 deletions slave/contrib/init-scripts/buildslave.init.sh
@@ -0,0 +1,142 @@
#!/bin/bash

### Maintain compatibility with chkconfig
# chkconfig: 2345 83 17
# description: buildslave

### BEGIN INIT INFO
# Provides: buildslave
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
SLAVE_RUNNER=/usr/bin/buildslave

. /lib/lsb/init-functions

# Source buildslave configuration
[[ -r /etc/default/buildslave ]] && . /etc/default/buildslave
#[[ -r /etc/sysconfig/buildslave ]] && . /etc/sysconfig/buildslave

# Or define/override the configuration here
#SLAVE_ENABLED[1]=0 # 0-enabled, other-disabled
#SLAVE_NAME[1]="buildslave #1" # short name printed on start/stop
#SLAVE_USER[1]="buildbot" # user to run slave as
#SLAVE_BASEDIR[1]="" # basedir to slave (absolute path)
#SLAVE_OPTIONS[1]="" # buildbot options
#SLAVE_PREFIXCMD[1]="" # prefix command, i.e. nice, linux32, dchroot

if [[ ! -x ${SLAVE_RUNNER} ]]; then
log_failure_msg "does not exist or not an executable file: ${SLAVE_RUNNER}"
exit 1
fi

function check_config() {
itemcount="${#SLAVE_ENABLED[@]}
${#SLAVE_NAME[@]}
${#SLAVE_USER[@]}
${#SLAVE_BASEDIR[@]}
${#SLAVE_OPTIONS[@]}
${#SLAVE_PREFIXCMD[@]}"

if [[ $(echo "$itemcount" | tr -d ' ' | sort -u | wc -l) -ne 1 ]]; then
log_failure_msg "SLAVE_* arrays must have an equal number of elements!"
return 1
fi

errors=0
for i in $( seq ${#SLAVE_ENABLED[@]} ); do
if [[ ${SLAVE_ENABLED[$i]} -ne 0 ]]; then
log_failure_msg "buildslave #${i}: unknown run status"
errors=$(($errors+1))
fi

if [[ -z ${SLAVE_NAME[$i]} ]]; then
log_failure_msg "buildslave #${i}: no name"
errors=$(($errors+1))
fi

if [[ -z ${SLAVE_USER[$i]} ]]; then
log_failure_msg "buildslave #${i}: no run user specified"
errors=$( ($errors+1) )
elif ! getent passwd ${SLAVE_USER[$i]} >/dev/null; then
log_failure_msg "buildslave #${i}: unknown user ${SLAVE_USER[$i]}"
errors=$(($errors+1))
fi

if [[ ! -d "${SLAVE_BASEDIR[$i]}" ]]; then
log_failure_msg "buildslave ${i}: basedir does not exist ${SLAVE_BASEDIR[$i]}"
errors=$(($errors+1))
fi
done

[[ $errors == 0 ]]; return $?
}

check_config || exit $?

function iscallable () { type $1 2>/dev/null | grep -q 'shell function'; }

function slave_op () {
op=$1 ; mi=$2

${SLAVE_PREFIXCMD[$1]} \
su -s /bin/sh \
-c "$SLAVE_RUNNER $op --quiet ${SLAVE_OPTIONS[$mi]} ${SLAVE_BASEDIR[$mi]}" \
- ${SLAVE_USER[$mi]}
return $?
}

function do_op () {
errors=0
for i in $( seq ${#SLAVE_ENABLED[@]} ); do
[[ ${SLAVE_ENABLED[$i]} -ne 0 ]] && continue

# Some rhels don't come with all the lsb goodies
if iscallable log_daemon_msg; then
log_daemon_msg "$3 \"${SLAVE_NAME[$i]}\""
if eval $1 $2 $i; then
log_end_msg 0
else
log_end_msg 1
errors=$(($errors+1))
fi
else
if eval $1 $2 $i; then
log_success_msg "$3 \"${SLAVE_NAME[$i]}\""
else
log_failure_msg "$3 \"${SLAVE_NAME[$i]}\""
errors=$(($errors+1))
fi
fi
done
return $errors
}

case "$1" in
start)
do_op "slave_op" "start" "Starting buildslave"
exit $?
;;
stop)
do_op "slave_op" "stop" "Stopping buildslave"
exit $?
;;
reload)
do_op "slave_op" "reload" "Reloading buildslave"
exit $?
;;
restart|force-reload)
do_op "slave_op" "restart" "Restarting buildslave"
exit $?
;;
*)
echo "Usage: $0 {start|stop|restart|reload|force-reload}"
exit 1
;;
esac

exit 0

0 comments on commit c669fea

Please sign in to comment.