Skip to content

Commit

Permalink
Fix weird *_ENABLED behaviour in /etc/default/* files
Browse files Browse the repository at this point in the history
  • Loading branch information
jollyroger committed May 31, 2011
1 parent fbd9b46 commit eb771d1
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 45 deletions.
5 changes: 5 additions & 0 deletions master/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ step's functionality.

** Deprecations, Removals, and Non-Compatible Changes

*** Init script now uses /etc/default/buildmaster for instance configuration.
Also MASTER_ENABLED used in /etc/default/buildmaster now accepts 'true|yes|1'
to enable instance and 'false|no|0' to disable(not case sensitive). Other
values will be considered as syntax error.

*** 'buildbot.status.words.IRC' now defaults to `AllowForce=False` to prevent
IRC bots from being allowed to force builds by default.

Expand Down
8 changes: 6 additions & 2 deletions master/contrib/init-scripts/buildmaster.default
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
MASTER_RUNNER=/usr/bin/buildbot

MASTER_ENABLED[1]=0 # 0-enabled, other-disabled
# NOTE: MASTER_ENABLED has changed its behaviour in version 0.8.4. Use
# 'true|yes|1' to enable instance and 'false|no|0' to disable. Other
# values will be considered as syntax error.

MASTER_ENABLED[1]=0 # 1-enabled, 0-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_OPTIONS[1]="" # buildbot options
MASTER_PREFIXCMD[1]="" # prefix command, i.e. nice, linux32, dchroot
73 changes: 52 additions & 21 deletions master/contrib/init-scripts/buildmaster.init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MASTER_RUNNER=/usr/bin/buildbot
#[[ -r /etc/sysconfig/buildmaster ]] && . /etc/sysconfig/buildmaster

# Or define/override the configuration here
#MASTER_ENABLED[1]=0 # 0-enabled, other-disabled
#MASTER_ENABLED[1]=0 # 1-enabled, 0-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)
Expand All @@ -34,6 +34,51 @@ if [[ ! -x ${MASTER_RUNNER} ]]; then
exit 1
fi

function is_enabled() {
ANSWER=`echo $1|tr "[:upper:]" "[:lower:]"`
[[ "$ANSWER" == "yes" ]] || [[ "$ANSWER" == "true" ]] || [[ "$ANSWER" == "1" ]]
return $?
}

function is_disabled() {
ANSWER=`echo $1|tr "[:upper:]" "[:lower:]"`
[[ "$ANSWER" == "no" ]] || [[ "$ANSWER" == "false" ]] || [[ "$ANSWER" == "0" ]]
return $?
}


function master_config_valid() {
# Function validates buildmaster instance startup variables based on array
# index
local errors=0
local index=$1

if ! is_enabled "${MASTER_ENABLED[$index]}" && ! is_disabled "${MASTER_ENABLED[$index]}" ; then
log_warning_msg "buildmaster #${i}: invalid enabled status"
errors=$(($errors+1))
fi

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

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

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

return $errors
}

function check_config() {
itemcount="${#MASTER_ENABLED[@]}
${#MASTER_NAME[@]}
Expand All @@ -49,28 +94,12 @@ function check_config() {

errors=0
for i in $( seq ${#MASTER_ENABLED[@]} ); do
if [[ "${MASTER_ENABLED[$i]}" != "0" ]]; then
if is_disabled "${MASTER_ENABLED[$i]}" ; then
log_warning_msg "buildmaster #${i}: disabled"
continue
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
master_config_valid $i
errors=$(($errors+$?))
done

[[ $errors == 0 ]]; return $?
Expand All @@ -93,7 +122,9 @@ function master_op () {
function do_op () {
errors=0
for i in $( seq ${#MASTER_ENABLED[@]} ); do
[[ "${MASTER_ENABLED[$i]}" != "0" ]] && continue
if is_disabled "${MASTER_ENABLED[$i]}" ; then
continue
fi

# Some rhels don't come with all the lsb goodies
if iscallable log_daemon_msg; then
Expand Down
5 changes: 5 additions & 0 deletions slave/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ systems. This means that in most cases child processes are cleaned up
properly, and removes the most common use for usePTY. As of this version,
usePTY should be set to False for almost all users of Buildbot.

** Init script now uses /etc/default/buildslave for instance configuration.
Also SLAVE_ENABLED used in /etc/default/buildslave now accepts 'true|yes|1'
to enable instance and 'false|no|0' to disable(not case sensitive). Other
values will be considered as syntax error.


* Buildbot-Slave 0.8.3 (December 19, 2010)

Expand Down
8 changes: 6 additions & 2 deletions slave/contrib/init-scripts/buildslave.default
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
SLAVE_RUNNER=/usr/bin/buildslave

SLAVE_ENABLED[1]=0 # 0-enabled, other-disabled
# NOTE: SLAVE_ENABLED has changed its behaviour in version 0.8.4. Use
# 'true|yes|1' to enable instance and 'false|no|0' to disable. Other
# values will be considered as syntax error.

SLAVE_ENABLED[1]=0 # 1-enabled, 0-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_OPTIONS[1]="" # buildbot options
SLAVE_PREFIXCMD[1]="" # prefix command, i.e. nice, linux32, dchroot
71 changes: 51 additions & 20 deletions slave/contrib/init-scripts/buildslave.init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,51 @@ if [[ ! -x ${SLAVE_RUNNER} ]]; then
exit 1
fi

function is_enabled() {
ANSWER=`echo $1|tr "[:upper:]" "[:lower:]"`
[[ "$ANSWER" == "yes" ]] || [[ "$ANSWER" == "true" ]] || [[ "$ANSWER" == "1" ]]
return $?
}

function is_disabled() {
ANSWER=`echo $1|tr "[:upper:]" "[:lower:]"`
[[ "$ANSWER" == "no" ]] || [[ "$ANSWER" == "false" ]] || [[ "$ANSWER" == "0" ]]
return $?
}


function slave_config_valid() {
# Function validates buildmaster instance startup variables based on array
# index
local errors=0
local index=$1

if ! is_enabled "${SLAVE_ENABLED[$index]}" && ! is_disabled "${SLAVE_ENABLED[$index]}" ; then
log_warning_msg "buildmaster #${i}: invalid enabled status"
errors=$(($errors+1))
fi

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

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

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

return $errors
}

function check_config() {
itemcount="${#SLAVE_ENABLED[@]}
${#SLAVE_NAME[@]}
Expand All @@ -49,28 +94,12 @@ function check_config() {

errors=0
for i in $( seq ${#SLAVE_ENABLED[@]} ); do
if [[ "${SLAVE_ENABLED[$i]}" != "0" ]]; then
if is_disabled "${SLAVE_ENABLED[$i]}" ; then
log_warning_msg "buildslave #${i}: disabled"
continue
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
slave_config_valid $i
errors=$(($errors+$?))
done

[[ $errors == 0 ]]; return $?
Expand All @@ -93,7 +122,9 @@ function slave_op () {
function do_op () {
errors=0
for i in $( seq ${#SLAVE_ENABLED[@]} ); do
[[ "${SLAVE_ENABLED[$i]}" != "0" ]] && continue
if is_disabled "${SLAVE_ENABLED[$i]}" ; then
continue
fi

# Some rhels don't come with all the lsb goodies
if iscallable log_daemon_msg; then
Expand Down

0 comments on commit eb771d1

Please sign in to comment.