updated on Sat Jan 21 20:03:50 UTC 2012
[aur-mirror.git] / bitten-svn / bitten-slave
blob51166e3a0db4eda255a7201880a8b8c7582be528
1 #!/bin/sh
3 # This script supports multiple slaves in parallel with
4 # different configurations. Simply create a symlink from
5 # bitten-slave to bitten-foo, add the configuration in
6 # /etc/conf.d/bitten-foo and add bitten-foo to the DAEMONS
7 # variable in rc.conf.
9 DAEMON_NAME=$(basename $0)
11 # general config
12 . /etc/rc.conf
13 . /etc/rc.d/functions
14 [ -f /etc/conf.d/$DAEMON_NAME ] && . /etc/conf.d/$DAEMON_NAME
16 : ${BITTEN_USER:="bitten-slave"}
17 : ${BITTEN_URL:="http://localhost/trac/builds"}
19 getpid() {
20 NAME="$1"
21 : ${NAME:="$DAEMON_NAME"}
22 PATTERN="$2"
23 : ${PATTERN:="$NAME"}
24 if [ -f /var/run/daemons/$NAME ]; then
25 PID=$(cat /var/run/daemons/$NAME)
26 if [ -f /proc/$PID/cmdline ] && grep -q "$PATTERN" /proc/$PID/cmdline; then
27 echo $PID
28 else
29 echo -1
31 else
32 echo -1
36 start() {
37 cd /home/$BITTEN_USER
38 nice setsid sudo -u $BITTEN_USER LANG=C HOME=/home/$BITTEN_USER USER=$BITTEN_USER LOGNAME=$BITTEN_USER bitten-slave $BITTEN_OPTS "$BITTEN_URL" > /var/log/$DAEMON_NAME.log 2>&1 &
39 PID=$!
40 sleep 1
41 if [ -f /proc/$PID/cmdline ] && grep -q bitten-slave /proc/$PID/cmdline; then
42 echo $PID > /var/run/daemons/$DAEMON_NAME
43 return 0
44 else
45 return 1
49 stop() {
50 PID=$(getpid $DAEMON_NAME "$BITTEN_URL")
51 if [ $PID -gt 0 ]; then
52 kill -TERM -$PID
53 count=0
54 while [ $count -lt 5 ] && [ $(getpid $DAEMON_NAME "$BITTEN_URL") -gt 0 ]; do
55 sleep 1
56 count=$(expr $count + 1)
57 done
58 if [ $(getpid $DAEMON_NAME "$BITTEN_URL") -gt 0 ]; then
59 kill -KILL -$PID
61 rm -f /var/run/daemons/$DAEMON_NAME
65 case "$1" in
66 start)
67 stat_busy "Starting $DAEMON_NAME: "
68 if [ $(getpid $DAEMON_NAME "$BITTEN_URL") -gt 0 ]; then
69 stat_done
70 else
71 if start; then
72 stat_done
73 else
74 stat_fail
78 status)
79 PID=$(getpid $DAEMON_NAME "$BITTEN_URL")
80 if [ $PID -gt 0 ]; then
81 echo $DAEMON_NAME is running with PID $PID.
82 exit 0
83 else
84 echo $DAEMON_NAME is stopped.
85 exit 1
88 stop)
89 stat_busy "Shutting down $DAEMON_NAME: "
90 stop
91 stat_done
93 reload)
94 stop
95 if ! start; then
96 echo Failed to restart $DAEMON_NAME >&2
99 restart)
100 $0 stop
101 $0 start
103 cond-restart)
104 if [ $(getpid $DAEMON_NAME "$BITTEN_URL") -gt 0 ]; then
105 stop
106 if ! start; then
107 echo Failed to restart $DAEMON_NAME >&2
112 echo "Usage: $0 {start|stop|status|restart|reload|cond-restart}"
113 esac