8d70997a585cff26f787d0d91831cc757fe53d59
[idzebra-moved-to-github.git] / etc / init.d / idzebra-init-script
1 #! /bin/sh
2
3 # $Id: idzebra-init-script,v 1.1 2007-01-31 12:26:50 mike Exp $
4 #
5 # This is a startup/shutdown script for Index Data's Zebra server,
6 # suitable for use in a SysV-style init directory such as /etc/init.d
7 # (on Debian systems) and /etc/rc.d/init.d (on Red Hat systems), like
8 # this:
9 #
10 #       sudo cp idzebra-init-script /etc/init.d/idzebra
11 #       sudo /etc/init.d/idzebra start
12 #
13 # You may need to tweak it to suit your system's paths.
14
15 # zebrasrv-2.0 may be in /usr/local/bin, hence this slight security hole
16 PATH=/bin:/usr/bin:/usr/local/bin/
17 catfile=/usr/local/src/cvs/zebra/etc/init.d/catalogue
18
19 case "$1" in
20     start)
21         while read line; do
22             line=`echo "$line" | sed 's/#.*//'`
23             line=`echo "$line" | sed 's/[ \t]*$//'`
24             if [ "x$line" != x ]; then
25                 set $line; tag=$1; dir=$2; file=$3
26                 #echo "tag='$tag', dir='$dir', file='$file'"
27
28                 logfile=/var/log/zebra-$tag
29                 pidfile=/var/run/zebra-$tag.pid
30                 if [ -f $pidfile ]; then
31                         echo "Zebra service '$tag' seems to be already running"
32                         continue
33                 fi
34                 echo "Starting Zebra service '$tag'"
35                 test -f $logfile && mv $logfile $logfile.old
36                 case "$file" in
37                   *.xml) opt=-f;;
38                   *.cfg) opt=-c;;
39                   *) echo "Unrecognised Zebra config-file type: '$file'";;
40                 esac
41
42                 (
43                     cd $dir
44                     echo === $dir zebrasrv-2.0 $opt $file === < /dev/null > $logfile 2>&1
45                     ( zebrasrv-2.0 $opt $file < /dev/null >> $logfile 2>&1 & )
46                     echo $! > $pidfile
47                 )
48             fi
49         done < $catfile
50         ;;
51
52     stop)
53         # Unfortunate partial duplication of parsing code here
54         while read line; do
55             line=`echo "$line" | sed 's/#.*//'`
56             line=`echo "$line" | sed 's/[ \t]*$//'`
57             if [ "x$line" != x ]; then
58                 set $line; tag=$1
59
60                 pidfile=/var/run/zebra-$tag.pid
61                 if [ ! -f $pidfile ]; then
62                         echo "Zebra service '$tag' does not seem to be running"
63                         continue
64                 fi
65
66                 echo "Stopping Zebra service '$tag'"
67                 kill `cat $pidfile`
68                 rm $pidfile
69             fi
70         done < $catfile
71         ;;
72
73     restart)
74         $0 stop && $0 start
75         ;;
76     *)
77         echo "Usage: $0 start|stop|restart" >&2
78         ;;
79 esac