3
### Maintain compatibility with chkconfig
4
# chkconfig: 2345 83 17
5
# description: buildslave
9
# Required-Start: $remote_fs
10
# Required-Stop: $remote_fs
11
# Default-Start: 2 3 4 5
13
# Short-Description: Buildbot slave init script
14
# Description: This file allows running buildbot slave instances at
18
PATH=/sbin:/bin:/usr/sbin:/usr/bin
19
SLAVE_RUNNER=/usr/bin/buildslave
22
# Source buildslave configuration
23
[[ -r /etc/default/buildslave ]] && . /etc/default/buildslave
26
# Get some LSB-like functions
27
if [ -r /lib/lsb/init-functions ]; then
28
. /lib/lsb/init-functions
30
function log_success_msg() {
33
function log_failure_msg() {
36
function log_warning_msg() {
42
# Some systems don't have seq (e.g. Solaris)
43
if type seq >/dev/null 2>&1; then
47
for ((i=1; i<=$1; i+=1)); do
54
if [[ ! -x ${SLAVE_RUNNER} ]]; then
55
log_failure_msg "does not exist or not an executable file: ${SLAVE_RUNNER}"
59
function is_enabled() {
60
ANSWER=`echo $1|tr "[:upper:]" "[:lower:]"`
61
[[ "$ANSWER" == "yes" ]] || [[ "$ANSWER" == "true" ]] || [[ "$ANSWER" == "1" ]]
65
function is_disabled() {
66
ANSWER=`echo $1|tr "[:upper:]" "[:lower:]"`
67
[[ "$ANSWER" == "no" ]] || [[ "$ANSWER" == "false" ]] || [[ "$ANSWER" == "0" ]]
72
function slave_config_valid() {
73
# Function validates buildslave instance startup variables based on array
78
if ! is_enabled "${SLAVE_ENABLED[$index]}" && ! is_disabled "${SLAVE_ENABLED[$index]}" ; then
79
log_warning_msg "buildslave #${index}: invalid enabled status"
83
if [[ -z ${SLAVE_NAME[$index]} ]]; then
84
log_failure_msg "buildslave #${index}: no name"
88
if [[ -z ${SLAVE_USER[$index]} ]]; then
89
log_failure_msg "buildslave #${index}: no run user specified"
90
errors=$( ($errors+1) )
91
elif ! getent passwd ${SLAVE_USER[$index]} >/dev/null; then
92
log_failure_msg "buildslave #${index}: unknown user ${SLAVE_USER[$index]}"
96
if [[ ! -d "${SLAVE_BASEDIR[$index]}" ]]; then
97
log_failure_msg "buildslave ${index}: basedir does not exist ${SLAVE_BASEDIR[$index]}"
104
function check_config() {
105
itemcount="${#SLAVE_ENABLED[@]}
110
${#SLAVE_PREFIXCMD[@]}"
112
if [[ $(echo "$itemcount" | tr -d ' ' | sort -u | wc -l) -ne 1 ]]; then
113
log_failure_msg "SLAVE_* arrays must have an equal number of elements!"
118
for i in $( seq ${#SLAVE_ENABLED[@]} ); do
119
if is_disabled "${SLAVE_ENABLED[$i]}" ; then
120
log_warning_msg "buildslave #${i}: disabled"
123
slave_config_valid $i
124
errors=$(($errors+$?))
127
[[ $errors == 0 ]]; return $?
130
check_config || exit $?
132
function iscallable () { type $1 2>/dev/null | grep -q 'shell function'; }
134
function slave_op () {
137
if [ `uname` = SunOS ]; then
142
${SLAVE_PREFIXCMD[$mi]} \
143
su $suopt - ${SLAVE_USER[$mi]} \
144
-c "$SLAVE_RUNNER $op ${SLAVE_OPTIONS[$mi]} ${SLAVE_BASEDIR[$mi]} > /dev/null"
150
for i in $( seq ${#SLAVE_ENABLED[@]} ); do
151
if [ -n "$4" ] && [ "$4" != "${SLAVE_NAME[$i]}" ] ; then
153
elif is_disabled "${SLAVE_ENABLED[$i]}" && [ -z "$4" ] ; then
157
# Some rhels don't come with all the lsb goodies
158
if iscallable log_daemon_msg; then
159
log_daemon_msg "$3 \"${SLAVE_NAME[$i]}\""
160
if eval $1 $2 $i; then
164
errors=$(($errors+1))
167
if eval $1 $2 $i; then
168
log_success_msg "$3 \"${SLAVE_NAME[$i]}\""
170
log_failure_msg "$3 \"${SLAVE_NAME[$i]}\""
171
errors=$(($errors+1))
180
do_op "slave_op" "start" "Starting buildslave" "$2"
184
do_op "slave_op" "stop" "Stopping buildslave" "$2"
188
do_op "slave_op" "reload" "Reloading buildslave" "$2"
191
restart|force-reload)
192
do_op "slave_op" "restart" "Restarting buildslave" "$2"
196
echo "Usage: $0 {start|stop|restart|reload|force-reload}"