3 # Provides: buildbot-master
4 # Required-Start: $remote_fs
5 # Required-Stop: $remote_fs
6 # Default-Start: 2 3 4 5
8 # Short-Description: Buildbot master init script
9 # Description: This file allows running buildbot master instances at
13 # Author: Andriy Senkovych <andriysenkovych@gmail.com>
17 # PATH should only include /usr/* if it runs after the mountnfs.sh script
18 PATH
=/sbin
:/usr
/local
/bin
:/usr
/bin
:/bin
20 DAEMON
=/usr
/bin
/twistd
21 DESC
="buildbot-master"
22 CONFIG_DIR
=/etc
/buildbot
/masters-enabled
23 PID_DIR
=/var
/run
/buildbot-master
24 LOG_DIR
=/var
/log
/buildbot-master
26 SCRIPTNAME
=/etc
/init.d
/buildbot-master
28 # Exit if the package is not installed
29 [ -x "$DAEMON" ] ||
exit 0
31 # Read configuration variable file if it is present
32 [ -r /etc
/default
/buildbot-master
] && .
/etc
/default
/buildbot-master
35 [ "$ENABLED" = "true" ] ||
exit 0
37 # Exit if no configuration files available
38 [ -d "$CONFIG_DIR" ] ||
exit 0
40 # Load the VERBOSE setting and other rcS variables
43 # Define LSB log_* functions.
44 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
45 # and status_of_proc is working.
46 .
/lib
/lsb
/init-functions
49 # Function that checks the configuration file
53 if [ -z "$BB_NAME" ] ; then
54 log_failure_msg
"BB_NAME not set for $CONFIG_FILE"
58 if [ -z "$BB_BASEDIR" ] ; then
59 log_failure_msg
"BB_BASEDIR not set for $CONFIG_FILE"
63 if [ -z "$BB_USER" ] ; then
64 log_failure_msg
"BB_USER not set for $CONFIG_FILE"
66 elif ! getent passwd
$BB_USER >/dev
/null
; then
67 log_failure_msg
"Unknown user $BB_USER in $CONFIG_FILE"
75 # Function that actually starts a buildbot instance.
85 PIDSDIR
="/var/run/buildbot/$USER"
86 PIDFILE
="$PID_DIR/$USER/$BOT_NAME.pid"
87 LOGFILE
="$LOG_DIR/$USER/$BOT_NAME.log"
88 # twistd is insensitive to logfile argument due to buildbot.tac overrides
89 #DAEMON_ARGS="--no_save --pidfile $PIDFILE --logfile $LOGFILE -y $BOT_DIR/buildbot.tac"
90 DAEMON_ARGS
="--no_save --pidfile $PIDFILE -y $BOT_DIR/buildbot.tac $OPTIONS"
92 # Create user PID directory"
93 if ! [ -d "$PID_DIR/$USER" ] ; then
94 mkdir
-m 755 "$PID_DIR/$USER"
95 chown
$USER: "$PID_DIR/$USER"
98 # logfile argument does not affect twistd because of overrides in
100 ## Create user log directory. Give read permission to adm group
101 #if ! [ -d "$LOG_DIR/$USER" ] ; then
102 # mkdir -m 750 "$LOG_DIR/$USER"
103 # chown $USER:adm "$LOG_DIR/$USER"
107 # 0 if daemon has been started
108 # 1 if daemon was already running
109 # 2 if daemon could not be started
110 start-stop-daemon
--start --quiet --pidfile $PIDFILE --user $USER \
111 --startas $DAEMON --test > /dev
/null \
113 start-stop-daemon
--start --quiet --pidfile $PIDFILE --chuid $USER \
114 --chdir $BOT_DIR --startas $DAEMON -- $DAEMON_ARGS \
119 # Start wrapper function that does fancy things
121 wrap_start_buildbot
()
123 local CONFIG_FILE
=$CONFIG_DIR/$1
125 check_config ||
return 2
127 log_daemon_msg
"Starting $BB_NAME"
128 start_buildbot
"$BB_NAME" "$BB_BASEDIR" "$BB_USER" \
129 "$BB_OPTIONS" "$BB_PREFIXCMD"
133 0) log_success_msg
"done" ;;
134 1) log_warning_msg
"already running" ;;
135 *) log_failure_msg
;;
142 # Function that starts the daemon/service
146 # Start all enabled buildmaster instances.
148 ls $CONFIG_DIR|
while read CONFIG_FILE
; do
149 wrap_start_buildbot
$CONFIG_FILE
151 if [ $RETVAL -gt 0 ] && [ "$SKIP_FAILED" != "true" ] ; then
158 # Function that actually stops a buildbot instance.
165 PIDSDIR
="/var/run/buildbot/$USER"
166 PIDFILE
="$PID_DIR/$USER/$BOT_NAME.pid"
169 # 0 if daemon has been stopped
170 # 1 if daemon was already stopped
171 # 2 if daemon could not be stopped
172 # other if a failure occurred
173 start-stop-daemon
--stop --quiet --retry=INT
/30/KILL
/5 \
174 --pidfile $PIDFILE --name $NAME --user $USER
177 # Many daemons don't delete their pidfiles when they exit.
184 # Stop wrapper function that does fancy things
188 local CONFIG_FILE
=$CONFIG_DIR/$1
190 check_config ||
return 2
192 log_daemon_msg
"Stopping $BB_NAME"
193 stop_buildbot
"$BB_NAME" "$BB_USER"
197 0) log_success_msg
"done" ;;
198 1) log_warning_msg
"already stopped" ;;
199 *) log_failure_msg
;;
206 # Function that stops the daemon/service
210 # Stop all enabled buildmaster instances.
212 ls $CONFIG_DIR|
while read CONFIG_FILE
; do
213 wrap_stop_buildbot
$CONFIG_FILE
218 # Function that actually stops a buildbot instance.
225 PIDSDIR
="/var/run/buildbot/$USER"
226 PIDFILE
="$PID_DIR/$USER/$BOT_NAME.pid"
228 # If the daemon can reload its configuration without
229 # restarting (for example, when it is sent a SIGHUP),
230 # then implement that here.
232 start-stop-daemon
--stop --signal 1 --quiet \
233 --pidfile $PIDFILE --name $NAME --user $USER
238 # Reload wrapper function that does fancy things
240 wrap_reload_buildbot
()
242 local CONFIG_FILE
=$CONFIG_DIR/$1
244 check_config ||
return 2
246 log_daemon_msg
"$BB_NAME"
247 reload_buildbot
"$BB_NAME" "$BB_USER"
251 0) log_success_msg
"done" ;;
252 1) log_warning_msg
"already stopped" ;;
253 *) log_failure_msg
;;
260 # Function that sends a SIGHUP to the daemon/service
263 # Stop all enabled buildmaster instances.
265 ls $CONFIG_DIR|
while read CONFIG_FILE
; do
266 wrap_reload_buildbot
$CONFIG_FILE
272 # Start all enabled buildmaster instances.
274 ls $CONFIG_DIR|
while read CONFIG_FILE
; do
275 wrap_stop_buildbot
$CONFIG_FILE
279 wrap_start_buildbot
$CONFIG_FILE
282 1) log_end_msg
1 ;; # Old process is still running
284 log_end_msg
1 # Failed to start
285 if [ "$SKIP_FAILED" != "true" ] ; then
297 if [ $RETVAL -gt 0 ] && [ "$SKIP_FAILED" != "true" ] ; then
305 log_daemon_msg
"Starting $DESC" "$NAME"
310 log_daemon_msg
"Stopping $DESC" "$NAME"
315 status_of_proc
"$DAEMON" "$NAME" && exit 0 ||
exit $?
318 log_daemon_msg
"Reloading $DESC" "$NAME"
323 log_daemon_msg
"Restarting $DESC" "$NAME"
328 #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
329 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2