updated on Thu Jan 26 00:18:00 UTC 2012
[aur-mirror.git] / gitorious-git / gitorious-daemon.rc.d
blob8bb0b195791374265229ad384177807ad0b07422
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
6 BUNDLE="/opt/ruby-enterprise/bin/bundle"
7 PID_FILE="$GITORIOUS_HOME/log/git-daemon.pid"
9 check_pid() {
10 local PIDFILE="$1"
11 [ ! -f "$PIDFILE" ] && return 1
12 local PID=$(cat "$PIDFILE" 2> /dev/null)
13 [ -z "$PID" ] && return 1
14 if [ ! -d "/proc/$PID" ]; then
15 rm -f "$PIDFILE" 2> /dev/null
16 return 1
18 return 0
21 kill_pid() {
22 local PIDFILE="$1"
23 if check_pid "$PIDFILE"; then
24 local PID=$(cat "$PIDFILE" 2> /dev/null)
25 kill $PID &> /dev/null
26 local RET=$?
27 check_pid "$PIDFILE"
28 return $RET
30 return 1
33 wait_pid() {
34 while check_pid "$1"; do sleep 1; done
37 case "$1" in
38 start)
39 stat_busy "Starting gitorious daemon"
40 check_pid "$PID_FILE" || su - git -c "$BUNDLE exec script/git-daemon -d"
41 if [ $? -gt 0 ]; then
42 stat_fail
43 else
44 add_daemon gitorious-daemon
45 stat_done
48 stop)
49 stat_busy "Stopping gitorious daemon"
50 if ! kill_pid "$PID_FILE"; then
51 stat_fail
52 else
53 rm_daemon gitorious-daemon
54 stat_done
57 restart)
58 $0 stop
59 wait_pid "$PID_FILE"
60 $0 start
63 echo "usage: $0 {start|stop|restart}"
64 esac
65 exit 0