Implement option to change UID (-u)
[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 # Proxy CWD is here. Should be writable by it.
16 DIR=/var/yaz-proxy
17 # Proxy Path
18 DAEMON=/usr/local/bin/yaz-proxy
19 # Proxy PIDFILE. Must be writable by it.
20 PIDFILE=$DIR/yaz-proxy.pid
21 # Log file
22 LOGFILE=/var/log/yaz-proxy.log
23 # Port
24 PORT=9000
25 # Run as this user. Set to empty to keep uid as is
26 RUNAS=nobody
27 RUNAS=
28 # Extra args . Config file _WITH_ option
29 ARGS="-c config.xml"
30
31 if test -n "RUNAS"; then
32         ARGS="-u $RUNAS $ARGS"
33 fi
34
35 # Name, Description (not essential)
36 NAME=yaz-proxy
37 DESC="YAZ proxy"
38
39 test -d $DIR || exit 0
40 test -f $DAEMON || exit 0
41
42 set -e
43
44 case "$1" in
45   start)
46         echo -n "Starting $DESC: "
47         cd $DIR
48         $DAEMON -l $LOGFILE -p $PIDFILE $ARGS @:$PORT &
49         echo "$NAME."
50         ;;
51   stop)
52         echo -n "Stopping $DESC: "
53
54         if test -f $PIDFILE; then
55                 kill `cat $PIDFILE`
56                 rm -f $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                 rm -f $PIDFILE
72         fi
73         sleep 1
74         cd $DIR
75         $DAEMON -l $LOGFILE -p $PIDFILE $ARGS @:$PORT &
76         echo "$NAME."
77         ;;
78   *)
79         N=/etc/init.d/$NAME
80         # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
81         echo "Usage: $N {start|stop|restart|force-reload}" >&2
82         exit 1
83         ;;
84 esac
85
86 exit 0