rc_status relays exit code
[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                 r=$?
31                 echo ""
32                 return $r
33         }
34 fi
35
36 # functions exist on RedHat. Provide tiny subset if unavailable
37 if test -f /etc/rc.d/init.d/functions; then
38         . /etc/rc.d/init.d/functions
39 else
40         daemon() {
41                 pid_file=""
42                 while test $# -gt 0; do
43                         case $1 in
44                                 --pidfile)
45                                         pid_file=$2
46                                         shift 2
47                                         ;;
48                                 *)
49                                         break;
50                                         ;;
51                         esac
52                 done
53                 startproc -p $pid_file $*
54         }
55
56         killproc() {
57                 pid_file=""
58                 delay=10
59                 while test $# -gt 0; do
60                         case $1 in
61                                 -p)
62                                         pid_file=$2
63                                         shift 2
64                                         ;;
65                                 -d)
66                                         delay=$2
67                                         shift 2
68                                         ;;
69                                 *)
70                                         break;
71                                         ;;
72                         esac
73                 done
74                 /sbin/killproc -p $pid_file $*
75         }
76         status() {
77                 pid_file=""
78                 while test $# -gt 0; do
79                         case $1 in
80                                 -p)
81                                         pid_file=$2
82                                         shift 2
83                                         ;;
84                                 *)
85                                         break;
86                                         ;;
87                         esac
88                 done
89                 if test -f $pid_file && kill -0 `cat $pid_file`; then
90                         echo "$DAEMON `cat $pid_file` is running"
91                         return 0
92                 fi
93                 echo "$DAEMON is not running"
94                 return 1
95         }
96 fi
97 # end of compatibility layer for RedHat/SuSE
98
99 OPTIONS="-u nobody -l /var/log/metaproxy.log -c /etc/metaproxy/metaproxy.xml"
100
101 if [ -f /etc/sysconfig/metaproxy ]; then
102         . /etc/sysconfig/metaproxy
103 fi
104
105 DAEMON=${DAEMON-/usr/bin/metaproxy}
106 prog=metaproxy
107 pidfile=${PIDFILE-/var/run/metaproxy.pid}
108 lockfile=${LOCKFILE-/var/lock/subsys/metaproxy}
109 RETVAL=0
110
111 start() {
112         echo -n $"Starting $prog: "
113         daemon --pidfile ${pidfile} $DAEMON $OPTIONS -D -p ${pidfile}
114         rc_status -v
115         RETVAL=$?
116         [ $RETVAL = 0 ] && touch ${lockfile}
117         return $RETVAL
118 }
119
120 stop() {
121         echo -n $"Stopping $prog: "
122         killproc -p ${pidfile} -d 10 $DAEMON
123         rc_status -v
124         RETVAL=$?
125         [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
126 }
127 reload() {
128         stop
129         start
130 }
131
132 # See how we were called.
133 case "$1" in
134         start)
135                 start
136                 ;;
137         stop)
138                 stop
139                 ;;
140         status)
141                 status -p ${pidfile} $DAEMON
142                 RETVAL=$?
143                 ;;
144         restart)
145                 stop
146                 start
147                 ;;
148         condrestart)
149                 if [ -f ${pidfile} ] ; then
150                         stop
151                         start
152                 fi
153                 ;;
154         reload)
155                 reload
156                 ;;
157         configtest)
158                 $DAEMON $OPTIONS -t
159                 RETVAL=$?
160                 ;;
161         *)
162                 echo $"Usage: $prog {start|stop|restart|help|configtest}"
163                 exit 1
164 esac
165
166 exit $RETVAL
167 # Local Variables:
168 # mode:shell-script
169 # sh-indentation: 8
170 # sh-basic-offset: 8
171 # End: