updated on Sat Jan 14 12:12:45 UTC 2012
[aur-mirror.git] / gitorious / gitorious-poller.rc.d
blobab98af45cfecaa401a0321ba1d0080031361a9df
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
6 GITORIOUS_HOME="/usr/share/webapps/gitorious"
7 BUNDLE="/opt/ruby-enterprise/bin/bundle"
8 PID_FILE="$GITORIOUS_HOME/tmp/pids/poller0.pid"
10 check_pid() {
11 local PIDFILE="$1"
12 [ ! -f "$PIDFILE" ] && return 1
13 local PID=$(cat "$PIDFILE" 2> /dev/null)
14 [ -z "$PID" ] && return 1
15 if [ ! -d "/proc/$PID" ]; then
16 rm -f "$PIDFILE" 2> /dev/null
17 return 1
19 return 0
22 kill_pid() {
23 local PIDFILE="$1"
24 if check_pid "$PIDFILE"; then
25 local PID=$(cat "$PIDFILE" 2> /dev/null)
26 kill $PID &> /dev/null
27 local RET=$?
28 check_pid "$PIDFILE"
29 return $RET
31 return 1
34 wait_pid() {
35 while check_pid "$1"; do sleep 1; done
38 case "$1" in
39 start)
40 stat_busy "Starting gitorious poller"
41 if [ ! -d "$GITORIOUS_HOME/tmp/pids" ]; then
42 mkdir "$GITORIOUS_HOME/tmp/pids"
43 chown git:git "$GITORIOUS_HOME/tmp/pids"
45 check_pid "$PID_FILE" || su - git -c "env RAILS_ENV=production $BUNDLE exec script/poller start" > /dev/null 2>&1
46 if [ $? -gt 0 ]; then
47 stat_fail
48 else
49 add_daemon gitorious-poller
50 stat_done
53 stop)
54 stat_busy "Stopping gitorious poller"
55 if ! kill_pid "$PID_FILE"; then
56 stat_fail
57 else
58 rm_daemon gitorious-poller
59 stat_done
62 restart)
63 $0 stop
64 wait_pid "$PID_FILE"
65 $0 start
68 echo "usage: $0 {start|stop|restart}"
69 esac
70 exit 0