proxy.sh start/stop script
[yazpp-moved-to-github.git] / src / proxy.sh
1 #! /bin/sh
2 #
3 # skeleton      example file to build /etc/init.d/ scripts.
4 #               This file should be used to construct scripts for /etc/init.d.
5 #
6 #               Written by Miquel van Smoorenburg <miquels@cistron.nl>.
7 #               Modified for Debian GNU/Linux
8 #               by Ian Murdock <imurdock@gnu.ai.mit.edu>.
9 #
10 # Version:      @(#)skeleton  1.8  03-Mar-1998  miquels@cistron.nl
11 #
12 PATH=/usr/local/bin:/bin:/usr/bin
13 export PATH
14
15 RUNAS=nobody
16 LOGFILE=/var/log/proxy.log
17
18 if test `whoami` != $RUNAS; then
19         touch $LOGFILE
20         chown $RUNAS $LOGFILE
21         su -c "$0 $*" $RUNAS
22         exit 0
23 fi
24
25 # Proxy CWD is here. Should be writable by it.
26 DIR=/var/proxy
27 # Proxy Path
28 DAEMON=/usr/local/bin/yaz-proxy
29 # Proxy PIDFILE. Must be writable by it.
30 PIDFILE=$DIR/proxy.pid
31 # Port
32 PORT=9000
33 # Extra args . Config file _WITH_ option
34 ARGS="-c config.xml"
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         echo -n "Starting $DESC: "
48         cd $DIR
49         $DAEMON -l $LOGFILE -p $PIDFILE $ARGS @:$PORT &
50         echo "$NAME."
51         ;;
52   stop)
53         echo -n "Stopping $DESC: "
54
55         if test -f $PIDFILE; then
56                 kill `cat $PIDFILE`
57                 echo "$NAME."
58         else
59                 echo "No PID $PIDFILE"
60         fi
61         ;;
62   reload)
63         if test -f $PIDFILE; then
64                 kill -INT `cat $PIDFILE`
65         fi
66   ;;
67   restart|force-reload)
68         echo -n "Restarting $DESC: "
69         if test -f $PIDFILE; then
70                 kill `cat $PIDFILE`
71         fi
72         sleep 1
73         cd $DIR
74         $DAEMON -l $LOGFILE -p $PIDFILE $ARGS @:$PORT &
75         echo "$NAME."
76         ;;
77   *)
78         N=/etc/init.d/$NAME
79         # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
80         echo "Usage: $N {start|stop|restart|force-reload}" >&2
81         exit 1
82         ;;
83 esac
84
85 exit 0