Proper check for exit code in keepalive script
[yazpp-moved-to-github.git] / etc / yaz-proxy.sh
1 #!/bin/sh
2 # $Id: yaz-proxy.sh,v 1.3 2003-10-24 11:19:54 adam Exp $
3 # YAZ proxy start/stop init.d script.
4 #
5 PATH=/usr/local/bin:/bin:/usr/bin
6 export PATH
7
8 # Proxy CWD is here. Should be writable by it.
9 DIR=/var/yaz-proxy
10 # Proxy Path (either the actual one, or the keepalive one (for testing)
11 DAEMON=/usr/local/bin/yaz-proxy
12 DAEMON=/var/yaz-proxy/yaz-proxy-ka.sh
13
14 # Proxy PIDFILE. Must be writable by it.
15 PIDFILE="/var/run/yaz-proxy.pid"
16
17 # Log file
18 LOGFILE=/var/log/yaz-proxy.log
19
20 # Port
21 PORT=9000
22
23 # Run as this user. Set to empty to keep uid as is
24 RUNAS=nobody
25
26 # Extra args . Config file _WITH_ option
27 ARGS="-c config.xml"
28
29 if test -n "RUNAS"; then
30         ARGS="-u $RUNAS $ARGS"
31 fi
32
33 # Increase number of sockets, if needed
34 #ulimit -n 1050
35
36 # Name, Description (not essential)
37 NAME=yaz-proxy
38 DESC="YAZ proxy"
39
40 test -d $DIR || exit 0
41 test -f $DAEMON || exit 0
42
43 set -e
44
45 case "$1" in
46   start)
47         printf "%s" "Starting $DESC: "
48         cd $DIR
49         $DAEMON -l $LOGFILE -p $PIDFILE $ARGS @:$PORT &
50         echo "$NAME."
51         ;;
52   stop)
53         printf "%s" "Stopping $DESC: "
54
55         if test -f $PIDFILE; then
56                 kill `cat $PIDFILE`
57                 rm -f $PIDFILE
58                 echo "$NAME."
59         else
60                 echo "No PID $PIDFILE"
61         fi
62         ;;
63   reload)
64         if test -f $PIDFILE; then
65                 kill -HUP `cat $PIDFILE`
66         fi
67   ;;
68   restart|force-reload)
69         printf "%s" "Restarting $DESC: "
70         if test -f $PIDFILE; then
71                 kill `cat $PIDFILE`
72                 rm -f $PIDFILE
73         fi
74         sleep 1
75         cd $DIR
76         $DAEMON -l $LOGFILE -p $PIDFILE $ARGS @:$PORT &
77         echo "$NAME."
78         ;;
79   *)
80         N=/etc/init.d/$NAME
81         # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
82         echo "Usage: $N {start|stop|restart|force-reload}" >&2
83         exit 1
84         ;;
85 esac
86
87 exit 0