File: buildbot.init

package info (click to toggle)
buildbot 0.7.4-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,968 kB
  • ctags: 3,745
  • sloc: python: 20,806; sh: 194; makefile: 59
file content (173 lines) | stat: -rw-r--r-- 3,541 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#! /bin/bash
# initscript for buildbot

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC="BuildBot"

USER=buildbot

DAEMON=/usr/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/sh -c "${DAEMON} start ${BASEDIR} ${OPTIONS}" - ${USER}
    return $?
}

stop_buildbot() {
    NAME="$1"
    USER="$2"
    BASEDIR="$3"
    PREFIXCMD="$4"

    ${PREFIXCMD} su -s /bin/sh -c "${DAEMON} stop ${BASEDIR}" - ${USER}
    return $?
}

reload_buildbot() {
    NAME="$1"
    USER="$2"
    BASEDIR="$3"
    PREFIXCMD="$4"

    ${PREFIXCMD} su -s /bin/sh -c "${DAEMON} sighup ${BASEDIR}" - ${USER}
    return $?
}

do_start () {
    errors=0
    for i in ${BB_NUMBER[@]}; do
	[ $i -ge 0 ] || continue
	log_daemon_msg "Starting buildbot ${BB_NAME[$i]}"
	if start_buildbot "${BB_NAME[$i]}" "${BB_USER[$i]}" "${BB_BASEDIR[$i]}" \
	    "${BB_PREFIXCMD[$i]}" "${BB_OPTIONS[$i]}"
	then
	    log_end_msg 0
	else
	    log_end_msg 1
	    errors=$(($errors+1))
	fi
    done
    return $errors
}

do_stop () {
    errors=0
    for i in ${BB_NUMBER[@]}; do
	[ $i -ge 0 ] || continue
	log_daemon_msg "Stopping buildbot ${BB_NAME[$i]}"
	if stop_buildbot "${BB_NAME[$i]}" "${BB_USER[$i]}" "${BB_BASEDIR[$i]}" \
	    "${BB_PREFIXCMD[$i]}"
	then
	    log_end_msg 0
	else
	    log_end_msg 1
	    errors=$(($errors+1))
	fi
    done
    return $errors
}

do_reload () {
    errors=0
    for i in ${BB_NUMBER[@]}; do
	[ $i -ge 0 ] || continue
	log_daemon_msg "Reload buildbot ${BB_NAME[$i]}"
	if reload_buildbot "${BB_NAME[$i]}" "${BB_USER[$i]}" "${BB_BASEDIR[$i]}" \
	    "${BB_PREFIXCMD[$i]}"
	then
	    log_end_msg 0
	else
	    log_end_msg 1
	    errors=$(($errors+1))
	fi
    done
    return $errors
}

do_restart () {
    errors=0
    for i in ${BB_NUMBER[@]}; do
	[ $i -ge 0 ] || continue
	log_daemon_msg "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
	    log_end_msg 0
	else
	    log_end_msg 1
	    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