I have hacked the VNC server service script that comes with Fedora Core to start and stop xapian-tcpsrv automatically.
It's likely to work on other Linux distributions.
First, the configuration file is /etc/sysconfig/xapianservers and it looks like this :
# The XAPIANSERVERS variable is a list of num:user pairs. # # Uncomment the lines below to start xapian-tcpsrv # as my 'myusername' (adjust this to your own). # # DO NOT RUN THIS SERVICE if your local area network is # untrusted! #XAPIANSERVERS="1:myusername" #XAPIANSERVERARGS[1]="--port 7890 --quiet /var/lib/omega/data/default"
The example means that "xapian-tcpsrv --port 7890 --quiet /var/lib/omega/data/default" will be run as user "myusername".
The service script itself as as follows. Save it "/etc/init.d/xapian".
#!/bin/bash
#
# chkconfig: - 91 35
# description: Starts and stops xapian-tcpsrv.
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
unset XAPIANSERVERARGS
XAPIANSERVERS=""
[ -f /etc/sysconfig/xapianservers ] && . /etc/sysconfig/xapianservers
prog=$"xapian-tcpsrv"
start() {
echo -n $"Starting $prog: "
ulimit -S -c 0 >/dev/null 2>&1
RETVAL=0
NOSERV=1
for indexuser in ${XAPIANSERVERS}
do
NOSERV=
echo -n "${indexuser} "
unset BASH_ENV ENV
INDEXNUM="${indexuser%%:*}"
export USER="${indexuser##*:}"
export XAPIANUSERARGS="${XAPIANSERVERARGS[${INDEXNUM}]}"
runuser -l ${USER} -c "cd ~${USER} && mkdir -m 755 -p ~${USER}/.xapian-tcpsrv && xapian-tcpsrv ${XAPIANUSERARGS} >~${USER}/.xapian-tcpsrv/${INDEXNUM}.log 2>&1 &"
RETVAL=$?
[ "$RETVAL" -ne 0 ] && break
done
if test -n "$NOSERV"; then echo -n "no index configured "; fi
[ "$RETVAL" -eq 0 ] && success $"xapian-tcpsrv startup" || \
failure $"xapian-tcpsrv start"
echo
[ "$RETVAL" -eq 0 ] && touch /var/lock/subsys/xapian-tcpsrv
}
stop() {
echo -n $"Shutting down $prog: "
for indexuser in ${XAPIANSERVERS}
do
echo -n "${indexuser} "
unset BASH_ENV ENV
export USER="${indexuser##*:}"
# FIXME: this kills all xapian-tcpsrv owned by the given user,
# even those not initially started by this script
runuser ${USER} -c "killall -u ${USER} xapian-tcpsrv" >/dev/null 2>&1
done
RETVAL=$?
[ "$RETVAL" -eq 0 ] && success $"xapian-tcpsrv shutdown" || \
failure $"xapian-tcpsrv shutdown"
echo
[ "$RETVAL" -eq 0 ] && rm -f /var/lock/subsys/xapian-tcpsrv
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
sleep 3
start
;;
condrestart)
if [ -f /var/lock/subsys/xapian-tcpsrv ]; then
stop
sleep 3
start
fi
;;
status)
status xapian-tcpsrv
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac
The output of each xapian-tcpsrv process is redirected to "~myusername/.xapian-tcpsrv/indexnum.log".
Another thing to note is that "/etc/init.d/xapian stop" will indiscriminately kill all xapian-tcpsrv processed owned by the users listed in the configuration file, even those that were not initially started by the script.
