#!/bin/sh
#
#	/etc/rc.d/init.d
#
# Automatic start of the Dell VNC X server in a running Linux system
#
# chkconfig: 2345 21 79
# description: Activates the Dell X VNC server which \
#              allows redirection of the console output.
# processname: racvnc
# config: /etc/sysconfig/racvnc

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

# Source RAC configuration with all necessary variables.
if [ -f /etc/sysconfig/racvnc ]; then
	. /etc/sysconfig/racvnc
fi

# Check that rac is up.
#[ ${RAC} = "no" ] && exit 0

BECOME=racvnc
RETVAL=0

# See how we were called.
case "$1" in
  start)
	echo -n "Starting racvnc (RAC) services: "

	CheckDisplayNumber $displayNumber
	if [ $? -ne 0 ]; then
	echo  "A RAC server is already running as :$displayNumber"
		exit 3
	fi

	CheckBecomeUser $BECOME
	rm -f $desktopLog

	su $BECOME -c "xauth -f $xauthorityFile \
			add $host:$displayNumber . $cookie" >/dev/null 2>&1
	su $BECOME -c "xauth -f $xauthorityFile \
			add $host/unix:$displayNumber . $cookie" >/dev/null 2>&1

	# Now start the X VNC Server, as the $BECOME user
	daemon --user $BECOME /usr/sbin/racserver $args

	RETVAL=$?
	if [ $RETVAL -ne 0 ]; then
		echo "daemon racserver command failed on $host:$displayNumber"
		echo "  $cmd"
		exit 4
	fi
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/racvnc
	;;
  stop)
	echo -n "Stopping racvnc (RAC) services: "
	killproc racXvnc
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/racvnc
	;;
  status)
	status racXvnc
	RETVAL=$?
	;;
  restart|reload)
	$0 stop
	$0 start
	RETVAL=$?
	;;
  *)
	echo "Usage: racvnc {start|stop|status|restart|reload}"
	exit 1
esac

exit $RETVAL
