Skip to content

Commit

Permalink
Init script fixes and improvements.
Browse files Browse the repository at this point in the history
Although this was based on the init script from debian's buildbot
package, it should also run on rhels if you tweak it a bit (default <->
sysconfig).
  • Loading branch information
gvalkov committed Oct 24, 2010
1 parent 76d27c8 commit 5577889
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 45 deletions.
2 changes: 1 addition & 1 deletion master/contrib/init-scripts/buildmaster.default
@@ -1,4 +1,4 @@
BUILDBOT_RUNNER=/usr/bin/buildbot
MASTER_RUNNER=/usr/bin/buildbot

MASTER_ENABLED[1]=0 # 0-enabled, other-disabled
MASTER_NAME[1]="buildmaster #1" # short name printed on start/stop
Expand Down
68 changes: 46 additions & 22 deletions master/contrib/init-scripts/buildmaster.init.sh
Expand Up @@ -3,20 +3,32 @@
### BEGIN INIT INFO
# Provides: buildmaster
# Required-Start: $remote_fs
# Required-Stop: $remote_fs buildslave
# 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

test -x ${MASTER_RUNNER} || exit 0
# 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

. /lib/lsb/init-functions
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[@]}
Expand All @@ -27,32 +39,32 @@ function check_config() {
${#MASTER_PREFIXCMD[@]}"

if [[ $(echo "$itemcount" | tr -d ' ' | sort -u | wc -l) -ne 1 ]]; then
echo "@todo: think of error msg" >&2
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
echo "buildmaster #${i}: unknown run status" >&2
log_failure_msg "buildmaster #${i}: unknown run status"
errors=$(($errors+1))
fi

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

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

if [[ ! -d "${MASTER_BASEDIR[$i]}" ]]; then
echo "buildmaster ${i}: basedir does not exist ${MASTER_BASEDIR[$i]}" >&2
log_failure_msg "buildmaster ${i}: basedir does not exist ${MASTER_BASEDIR[$i]}"
errors=$(($errors+1))
fi
done
Expand All @@ -62,13 +74,15 @@ function check_config() {

check_config || exit $?

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

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

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

Expand All @@ -77,36 +91,46 @@ function do_op () {
for i in $( seq ${#MASTER_ENABLED[@]} ); do
[[ ${MASTER_ENABLED[$i]} -ne 0 ]] && continue

log_daemon_msg "$2 \"${MASTER_NAME[$i]}\""
if $(eval $1 $i); then
log_end_msg 0
# 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
log_end_msg 1
errors=$(($errors+1))
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"
do_op "master_op" "start" "Starting buildmaster"
exit $?
;;
stop)
do_op "master_op stop" "Stopping buildmaster"
do_op "master_op" "stop" "Stopping buildmaster"
exit $?
;;
reload)
do_op "master_op reload" "Reloading buildmaster"
do_op "master_op" "reload" "Reloading buildmaster"
exit $?
;;
restart|force-reload)
do_op "master_op restart" "Restarting buildmaster"
do_op "master_op" "restart" "Restarting buildmaster"
exit $?
;;
*)
log_warning_msg "Usage: $0 {start|stop|restart|reload|force-reload}"
echo "Usage: $0 {start|stop|restart|reload|force-reload}"
exit 1
;;
esac
Expand Down
6 changes: 3 additions & 3 deletions master/contrib/init-scripts/buildslave.default
@@ -1,8 +1,8 @@
BUILDSLAVE_RUNNER=/usr/bin/buildslave
SLAVE_RUNNER=/usr/bin/buildslave

SLAVE_ENABLED[1]=0 # 0-enabled, other-disabled
SLAVE_NAME[1]="buildmaster #1" # short name printed on start/stop
SLAVE_USER[1]="buildbot" # user to run master as
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
62 changes: 43 additions & 19 deletions master/contrib/init-scripts/buildslave.init.sh
Expand Up @@ -9,14 +9,26 @@
### END INIT INFO

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

# Source buildslave configuration
. /lib/lsb/init-functions

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

test -x ${SLAVE_RUNNER} || exit 0
# 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

. /lib/lsb/init-functions
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[@]}
Expand All @@ -27,32 +39,32 @@ function check_config() {
${#SLAVE_PREFIXCMD[@]}"

if [[ $(echo "$itemcount" | tr -d ' ' | sort -u | wc -l) -ne 1 ]]; then
echo "@todo: think of error msg" >&2
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
echo "buildslave #${i}: unknown run status" >&2
log_failure_msg "buildslave #${i}: unknown run status"
errors=$(($errors+1))
fi

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

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

if [[ ! -d "${SLAVE_BASEDIR[$i]}" ]]; then
echo "buildslave ${i}: basedir does not exist ${SLAVE_BASEDIR[$i]}" >&2
log_failure_msg "buildslave ${i}: basedir does not exist ${SLAVE_BASEDIR[$i]}"
errors=$(($errors+1))
fi
done
Expand All @@ -62,13 +74,15 @@ function check_config() {

check_config || exit $?

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

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

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

Expand All @@ -77,12 +91,22 @@ function do_op () {
for i in $( seq ${#SLAVE_ENABLED[@]} ); do
[[ ${SLAVE_ENABLED[$i]} -ne 0 ]] && continue

log_daemon_msg "$3 \"${SLAVE_NAME[$i]}\""
if $(eval $1 $2 $i); then
log_end_msg 0
# 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
log_end_msg 1
errors=$(($errors+1))
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
Expand All @@ -106,7 +130,7 @@ case "$1" in
exit $?
;;
*)
log_warning_msg "Usage: $0 {start|stop|restart|reload|force-reload}"
echo "Usage: $0 {start|stop|restart|reload|force-reload}"
exit 1
;;
esac
Expand Down

0 comments on commit 5577889

Please sign in to comment.