cba4ed916e2788cbbd08c559477def3587640993
[metaproxy-moved-to-github.git] / rpm / metaproxy.init
1 #!/bin/bash
2 #
3 # metaproxy    Startup script for Metaproxy
4 #
5 # chkconfig: 2345 85 15
6 # description: Metaproxy SRU/Z39.50 router
7 # processname: metaproxy
8 # config: /etc/metaproxy/metaproxy.xml
9 # config: /etc/sysconfig/metaproxy
10 # pidfile: /var/run/metaproxy.pid
11
12 ### BEGIN INIT INFO
13 # Provides:            metaproxy
14 # Required-Start:      $local_fs $remote_fs $network
15 # Required-Stop:       $local_fs $remote_fs
16 # Default-Start:       3 5
17 # Default-Stop:        0 1 2 6
18 # Short-Description:   Controls the metaproxy daemon
19 # Description:         Controls the Metaproxy Z39.50/SRU router.
20 ### END INIT INFO
21
22
23 # start of compatibility layer for RedHat/SuSE init.d
24 #
25 # rc_status exist on SuSE. Provide dummy if unavailable
26 if test -f /etc/rc.status; then
27         . /etc/rc.status
28 else
29         rc_status() {
30                 echo ""
31         }
32 fi
33
34 # functions exist on RedHat. Provide tiny subset if unavailable
35 if test -f /etc/rc.d/init.d/functions; then
36         . /etc/rc.d/init.d/functions
37 else
38         daemon() {
39                 pid_file=""
40                 while test $# -gt 0; do
41                         case $1 in
42                                 --pidfile)
43                                         pid_file=$2
44                                         shift 2
45                                         ;;
46                                 *)
47                                         break;
48                                         ;;
49                         esac
50                 done
51                 startproc -p $pid_file $*
52         }
53
54         killproc() {
55                 pid_file=""
56                 delay=10
57                 while test $# -gt 0; do
58                         case $1 in
59                                 -p)
60                                         pid_file=$2
61                                         shift 2
62                                         ;;
63                                 -d)
64                                         delay=$2
65                                         shift 2
66                                         ;;
67                                 *)
68                                         break;
69                                         ;;
70                         esac
71                 done
72                 /sbin/killproc -p $pid_file $*
73         }
74         status() {
75                 pid_file=""
76                 while test $# -gt 0; do
77                         case $1 in
78                                 -p)
79                                         pid_file=$2
80                                         shift 2
81                                         ;;
82                                 *)
83                                         break;
84                                         ;;
85                         esac
86                 done
87                 if test -f $pid_file && kill -0 `cat $pid_file`; then
88                         echo "$DAEMON `cat $pid_file` is running"
89                         return 0
90                 fi
91                 echo "$DAEMON is not running"
92                 return 1
93         }
94 fi
95 # end of compatibility layer for RedHat/SuSE
96
97 OPTIONS="-u nobody -l /var/log/metaproxy.log -c /etc/metaproxy/metaproxy.xml"
98
99 if [ -f /etc/sysconfig/metaproxy ]; then
100         . /etc/sysconfig/metaproxy
101 fi
102
103 DAEMON=${DAEMON-/usr/bin/metaproxy}
104 prog=metaproxy
105 pidfile=${PIDFILE-/var/run/metaproxy.pid}
106 lockfile=${LOCKFILE-/var/lock/subsys/metaproxy}
107 RETVAL=0
108
109 start() {
110         echo -n $"Starting $prog: "
111         daemon --pidfile ${pidfile} $DAEMON $OPTIONS -D -p ${pidfile}
112         rc_status -v
113         RETVAL=$?
114         [ $RETVAL = 0 ] && touch ${lockfile}
115         return $RETVAL
116 }
117
118 stop() {
119         echo -n $"Stopping $prog: "
120         killproc -p ${pidfile} -d 10 $DAEMON
121         rc_status -v
122         RETVAL=$?
123         [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
124 }
125 reload() {
126         stop
127         start
128 }
129
130 # See how we were called.
131 case "$1" in
132         start)
133                 start
134                 ;;
135         stop)
136                 stop
137                 ;;
138         status)
139                 status -p ${pidfile} $DAEMON
140                 RETVAL=$?
141                 ;;
142         restart)
143                 stop
144                 start
145                 ;;
146         condrestart)
147                 if [ -f ${pidfile} ] ; then
148                         stop
149                         start
150                 fi
151                 ;;
152         reload)
153                 reload
154                 ;;
155         configtest)
156                 $DAEMON $OPTIONS -t
157                 RETVAL=$?
158                 ;;
159         *)
160                 echo $"Usage: $prog {start|stop|restart|help|configtest}"
161                 exit 1
162 esac
163
164 exit $RETVAL
165 # Local Variables:
166 # mode:shell-script
167 # sh-indentation: 8
168 # sh-basic-offset: 8
169 # End: