Code

- update with possible tracker issue
[roundup.git] / scripts / server-ctl
1 #!/bin/sh
3 #
4 # Configuration
5 #
6 CONFFILE="/var/roundup/server-config.ini"
8 # this will end up with extra space, but it should be ignored in the script
9 PIDFILE=`grep '^pidfile' ${CONFFILE} | awk -F = '{print $2}' `
10 SERVER="/usr/local/bin/roundup-server -C ${CONFFILE}"
11 ERROR=0
12 ARGV="$@"
13 if [ "x$ARGV" = "x" ] ; then
14     ARGS="help"
15 fi
17 if [ -z "${PIDFILE}" ] ; then
18     echo "pidfile option must be set in configuration file"
19     exit 1
20 fi
22 for ARG in $@ $ARGS
23 do
24     # check for pidfile
25     if [ -f $PIDFILE ] ; then
26         PID=`cat $PIDFILE`
27         if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
28             STATUS="roundup-server (pid $PID) running"
29             RUNNING=1
30         else
31             STATUS="roundup-server (pid $PID?) not running"
32             RUNNING=0
33         fi
34     else
35         STATUS="roundup-server (no pid file) not running"
36         RUNNING=0
37     fi
39     case $ARG in
40     start)
41         if [ $RUNNING -eq 1 ] ; then
42             echo "$0 $ARG: roundup-server (pid $PID) already running"
43             continue
44         fi
45         if $SERVER ; then
46             echo "$0 $ARG: roundup-server started"
47         else
48             echo "$0 $ARG: roundup-server could not be started"
49             ERROR=1
50         fi
51         ;;
52     condstart)
53         if [ $RUNNING -eq 1 ] ; then
54             continue
55         fi
56         if $SERVER ; then
57             echo "$0 $ARG: roundup-server started"
58         else
59             echo "$0 $ARG: roundup-server could not be started"
60             ERROR=1
61         fi
62         ;;
63     stop)
64         if [ $RUNNING -eq 0 ] ; then
65             echo "$0 $ARG: $STATUS"
66             continue
67         fi
68         if kill $PID ; then
69             echo "$0 $ARG: roundup-server stopped"
70         else
71             echo "$0 $ARG: roundup-server could not be stopped"
72             ERROR=2
73         fi
74         ;;
75     status)
76         echo $STATUS
77         ;;
78     *)
79         echo "usage: $0 (start|condstart|stop|status)"
80         cat <<EOF
82     start      - start roundup-server
83     condstart  - start roundup-server if it's not running
84     stop       - stop roundup-server
85     status     - display roundup-server status
87 EOF
88         ERROR=3
89     ;;
91     esac
93 done
95 exit $ERROR