2 # Start and stop toolkit lite administered idzebra script for Debian.
3 # change runlevels using update-rc.d
5 test -x /usr/bin/zebrasrv || exit 0
6 test -x /usr/bin/zebraidx || exit 0
7 test -f /etc/default/zebra || exit 0
8 source /etc/default/zebra
10 # Now sourced from /etc/default/zebra
14 #ZEBRA_CONF_FILE=/etc/zebra.conf
15 #ZEBRA_LOG_DIR=/var/log/zebra
16 #ZEBRA_PID_DIR=/var/run/zebra
17 #ZEBRA_TMP_DIR=/var/tmp/zebra
19 ZEBRA_DIRS="/home/marc/projects/alvis"
20 ZEBRA_INDEX_DIRS="data"
22 # set socket connection method
23 #ZEBRA_SOCKET="tcp:@:210"
24 ZEBRA_SOCKET="unix:db/socket"
27 # define display message
28 display_ZEBRA_message(){
31 echo -n " /etc/init.d/zebra {start|stop|reload|force-reload|restart}"
32 echo " [/path/to/root/dir]"
33 echo " As root or $ZEBRA_USER:"
34 echo " /etc/init.d/zebra {index|reindex} [/path/to/root/dir [sub/dir] ]"
37 # make sure we are root or $ZEBRA_USER
38 ZEBRA_CURR_USER=`whoami`;
39 if [ $ZEBRA_CURR_USER != $ZEBRA_USER -a $ZEBRA_CURR_USER != "root" ] ; then
40 display_ZEBRA_message ;
41 echo " Error: you are not root or $ZEBRA_USER";
46 # perform usual init.d daemon services
49 # make sure we are root
50 if [ `whoami` != root ]; then
51 display_ZEBRA_message ;
52 echo " Error: you are not root";
56 # read zebra dir from command line
61 # loop through all entries defined in /etc/zebra.conf
62 for d in $ZEBRA_DIRS; do
63 echo -n "Starting zebra: "
66 if [ ! -f $d/db/zebra.cfg ] ; then
68 echo " Error: config file $d/db/zebra.cfg not found";
72 if [ ! -f $d/db/lock/zebrasrv.pid ] ; then
73 start-stop-daemon --start --quiet --background --pidfile $d/db/lock/zebrasrv.pid --exec /usr/bin/zebrasrv -- -w $d -u $ZEBRA_USER -c db/zebra.cfg -l db/server.log $ZEBRA_SOCKET ;
75 # check for running zebra not performed
77 #if [ -f $d/db/lock/zebrasrv.pid ] ; then
79 #cat $d/db/lock/zebrasrv.pid
85 echo -n "already running "
89 #ps -C zebrasrv | grep `cat $d/db/lock/zebrasrv.pid`
93 # make sure we are root
94 if [ `whoami` != root ]; then
95 display_ZEBRA_message ;
96 echo " Error: you are not root";
100 # read zebra dir from command line
105 # loop through all entries defined in /etc/zebra.conf
106 for d in $ZEBRA_DIRS; do
107 echo -n "Stopping zebra: "
110 if [ ! -f $d/db/zebra.cfg ] ; then
112 echo " Error: config file $d/db/zebra.cfg not found";
116 if [ -f $d/db/lock/zebrasrv.pid ] ; then
117 start-stop-daemon --stop --quiet --oknodo --pidfile $d/db/lock/zebrasrv.pid ;
119 #if ps -C zebrasrv | grep `cat $d/db/lock/zebrasrv.pid` ; then
120 # kill -9 `cat $d/db/lock/zebrasrv.pid`
123 #if [ -f $d/db/lock/zebrasrv.pid ] && ps -C zebrasrv | grep `cat $d/db/lock/zebrasrv.pid` ; then
128 #if [ -f $d/db/lock/zebrasrv.pid ] ; then
129 #rm -f $d/db/lock/zebrasrv.pid
130 #echo -n "removed PID file"
133 echo -n "already dead "
137 #ps -C zebrasrv | grep `cat $d/db/lock/zebrasrv.pid`
140 restart|reload|force-reload)
141 # make sure we are root
142 if [ `whoami` != root ]; then
143 display_ZEBRA_message ;
144 echo " Error: you are not root";
154 # make sure that indexing is done as user $ZEBRA_USER
155 if test `whoami` != $ZEBRA_USER; then
156 su -s /bin/sh -c "$0 $*" $ZEBRA_USER
160 # read zebra dir from command line
165 for d in $ZEBRA_DIRS; do
166 # allow all scripts to be called with one specific entrie
167 # directory as third argument
169 if [ ! -f $d/db/zebra.cfg ] ; then
170 echo -n "Indexing zebra: "
172 echo " Error: config file $d/db/zebra.cfg not found";
177 # only indexing one additionally directory
179 if [ ! -d $d/$ZEBRA_INDEX_DIRS ] ; then
180 #$0 ; # trigger user info
181 echo " Error: there is no directory $3";
182 echo " in zebra dir $d";
183 echo " Can not index $d/$ZEBRA_INDEX_DIRS";
186 if ( echo $ZEBRA_INDEX_DIRS | grep "^/" ) ; then
187 #$0 ; # trigger user info
188 echo " Error: third argument $3";
189 echo " must not contain leading slash";
193 echo -n "Indexing zebra: "
197 # initalization and commiting db to get a fresh slate
198 for DIR in $ZEBRA_INDEX_DIRS ; do
200 zebraidx -L -l db/index.log -c db/zebra.cfg update $DIR ;
202 zebraidx -l db/index.log -c db/zebra.cfg commit ;
206 # indexing a whole entrie - findZEBRA_INDEX_DIRD makes the work
207 # findZEBRA_INDEX_DIRS "$d" ;
208 echo -n "Indexing zebra: "
211 # initalization and commiting db to get a fresh slate
212 zebraidx -l db/index.log -c db/zebra.cfg init ;
213 for DIR in $ZEBRA_INDEX_DIRS ; do
215 zebraidx -L -l db/index.log -c db/zebra.cfg update $DIR ;
217 zebraidx -l db/index.log -c db/zebra.cfg commit ;
225 display_ZEBRA_message ;