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