#!/bin/sh -
#
# $Id: mosix.init,v 1.4 2003/04/14 22:09:52 misi3k Exp $
# 
# chkconfig: 2345 95 5
# description: MOSIX is am extension of the operating system,
#	       supporting scalable and transparent cluster computing.
#
# mosix		Script to stop/start MOSIX
#

# Source function library.
. /etc/rc.d/init.d/functions

# Check that networking is up.
if [ ! -f /var/lock/subsys/network ]; then
	# nls "ERROR: Networking is down. %s can't be run." mosix
	msg_network_down mosix
	exit 1
fi


# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/mosix ]; then
		msg_starting mosix
		if [ -s /etc/overheads -a -f /proc/mosix/admin/overheads ]
		then
			 /bin/grep -v '^#' /etc/overheads > /proc/mosix/admin/overheads
		fi
		if [ -s /etc/mfscosts -a -f /proc/mosix/admin/mfscosts ]
		then
			 /bin/grep -v '^#' /etc/mfscosts > /proc/mosix/admin/mfscosts
		fi
		a1=
		[ -s /etc/mospe ] && a1="-p `cat /etc/mospe`"
		a2=
		[ -s /etc/mosgates ] && a2="-g `cat /etc/mosgates`"
		/sbin/setpe -W $a1 $a2 -f /etc/mosix.map
		RETVAL=$?
		if [ $RETVAL -eq 0 ] 
		then
			touch /var/lock/subsys/mosix
			deltext
			ok
		else
			deltext
			fail
		fi
	else
		msg_already_running mosix
		exit 1
	fi
	;;
  stop)
	# Stop daemons.
	# show "Stopping %s service" mosix
	if [ -f /var/lock/subsys/mosix ]; then
		msg_stopping mosix
		busy
		echo 0 > /proc/mosix/admin/mospe
		RETVAL=$?
		rm -f /var/lock/subsys/mosix
		deltext
		ok
	else
		# show "%s service is not running." mosix
		msg_not_running mosix
		deltext
		fail
		exit 1
	fi
	;;
  status)
	/sbin/setpe -r 
	;;
  restart|reload)
	$0 stop
	$0 start
        ;;

  *)
	# show "Usage: %s {start|stop|status|restart|reload|force-reload}" $0
	msg_usage "$0 {start|stop|status|restart|reload}"
	exit 1
esac

exit $RETVAL

# This must be last line !
# vi:syntax=sh:tw=78:ts=8:sw=4
