blob: 5c3f7c5273778f008b4ba7d1d4189a475ab8004c (
plain)
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
|
#!/bin/bash
#
# init file for Gitorious GIT-Poller daemon
#
# chkconfig: 2345 55 25
# description: GIT-Poller server daemon
#
# processname: poller
# pidfile: /var/www/gitorious/tmp/pids/poller0.pid
# Author: Antonio Marques <acmarques@gmail.com>
# source function library
. /etc/rc.d/init.d/functions
RUBY_HOME="/opt/ruby-enterprise"
GITORIOUS_HOME="/var/www/gitorious"
RETVAL=0
PROG="poller"
GIT_POLLER="$RUBY_HOME/bin/ruby $GITORIOUS_HOME/script/poller"
LOCK_FILE=/var/lock/git-poller
PID_FILE=$GITORIOUS_HOME/tmp/pids/poller0.pid
export RAILS_ENV=production
do_check_pid() {
if [ -f $PID_FILE ]; then
PID=`cat $PID_FILE`
RUNNING=`ps --pid $PID | wc -l`
else
PID=0
RUNNING=0
fi
}
runlevel=$(set -- $(runlevel); eval "echo $$#" )
start()
{
do_check_pid
if [ $RUNNING != 2 ] ; then
echo -n $"Starting $PROG:"
/bin/su - git -c "RAILS_ENV=$RAILS_ENV $GIT_POLLER start"
sleep 4
if [ -f $PID_FILE ] ; then
echo "Success"
RETVAL=0
else
echo "FAILURE"
RETVAL=1
fi
RETVAL=$?
else
echo -n $"$PROG already running"
failure
fi
[ "$RETVAL" = 0 ] && touch $LOCK_FILE
echo
}
stop()
{
do_check_pid
echo -n $"Stopping $PROG: "
if [ $RUNNING != 2 ] ; then
failure $"Stopping $PROG"
else
#killproc -p $PID_FILE
/bin/su - git -c "RAILS_ENV=$RAILS_ENV $GIT_POLLER stop"
sleep 4
fi
RETVAL=$?
# if we are in halt or reboot runlevel kill all running sessions
# so the TCP connections are closed cleanly
if [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; then
killproc -p $PID 2>/dev/null
fi
[ "$RETVAL" = 0 ] && rm -f $LOCK_FILE
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if [ -f $LOCK_FILE ] ; then
if [ "$RETVAL" = 0 ] ; then
stop
# avoid race
sleep 5
start
fi
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart}"
RETVAL=1
esac
exit $RETVAL
|