#!/bin/sh 
###############################################################################
# Copyright 1997-2000 by mental images GmbH & Co.KG, Fasanenstr. 81, D-10623
# Berlin, Germany. All rights reserved.
#
# start and stop SPM daemon
#
# $Id: rcspm,v 1.10 2001/11/21 10:30:36 runa Exp $
#
SPMDIR=/var/spm
SPMD=spmd
PATH=/bin:/usr/bin:/sbin
if [ `uname` = 'Linux' ] ; then
	KERN=`uname -r | awk -F. '{print($2)}'`
	SMP=`uname -v | awk '{print($2)}'`
	[ x$SMP = 'xSMP' ] && smp='.smp'
	[ x$KERN = 'x4' ] && kern='.24'
fi

killproc() {            # kill the named process(es)
        pid=`ps -e |
             grep $1 |
             sed -e 's/^  *//' -e 's/ .*//'`
        [ "$pid" != "" ] && kill $signal $pid
}

case "$1" in
  'start')
	if [ `uname` = 'Linux' ] ; then
		cd ${SPMDIR}
		${SPMDIR}/spm_insmod spmkmod$smp$kern.o 
		if [ $? = 0 ] ;then 
			echo "... spmkmod loaded ..."
		fi
		lsmod | grep spmkmod$smp$kern 1>/dev/null 2>&1
		[ $? = 1 ]  && {
			echo "... spmkmod not loaded ..."
			exit -1 
			}
	fi

	if test -x ${SPMDIR}/${SPMD}; then
		${SPMDIR}/${SPMD}
		[ $? = 0 ] && echo "... ${SPMD} started ..."
	fi
	;;

  'stop')
	signal='-9'
	killproc ${SPMD}
	if [ `uname` = 'Linux' ] ; then
		rmmod spmkmod$smp$kern 1>/dev/null 2>&1
		[ $? = 0 ] && echo "... spmkmod removed ..."
	fi
	;;

  'restart')
#	signal='-HUP'
 	killproc ${SPMD}
	${SPMDIR}/${SPMD}
	[ $? = 0 ] && echo "... ${SPMD} restarted ..."
	;;

  *)
	echo "usage: $0 {start|stop}"
	;;
esac
