#!/bin/sh

### BEGIN INIT INFO
# Provides:          nodm
# Required-Start:    $syslog $remote_fs
# Should-Start:      $time ypbind smtp
# Required-Stop:     $syslog $remote_fs
# Should-Stop:       ypbind smtp
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Start nodm display manager
# Description:       Start nodm display manager without requiring user intercation
### END INIT INFO
NODM_BIN=/usr/sbin/nodm
test -x $NODM_BIN || { echo "$NODM_BIN not installed"; 
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }

# Check for existence of needed config file and read it
NODM_CONFIG=/etc/sysconfig/nodm
test -r $NODM_CONFIG || { echo "$NODM_CONFIG not existing";
	if [ "$1" = "stop" ]; then exit 0;
	else exit 6; fi; }

# Read config	
. $NODM_CONFIG
export NODM_USER NODM_X_OPTIONS NODM_MIN_SESSION_TIME NODM_XINIT NODM_XSESSION

# Source LSB init functions
. /etc/rc.status

# Reset status of this service
rc_reset

case "$1" in
    start)
	echo -n "Starting nodm "
	## Start daemon with startproc(8). If this fails
	## the return value is set appropriately by startproc.
	/sbin/startproc $NODM_BIN

	# Remember status and be verbose
	rc_status -v
	;;
    stop)
	echo -n "Shutting down nodm "
	## Stop daemon with killproc(8) and if this fails
	## killproc sets the return value according to LSB.

	/sbin/killproc -TERM $NODM_BIN

	# Remember status and be verbose
	rc_status -v
	;;
    restart)
	## Stop the service and regardless of whether it was
	## running or not, start it again.
	$0 stop
	$0 start

	# Remember status and be quiet
	rc_status
	;;
    reload)
    	## Nothing to reload really only restart possible
    	$0 restart
    	rc_status -v
    	;;
    status)
	echo -n "Checking for service nodm "
	/sbin/checkproc $NODM_BIN
	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart}"
	exit 1
	;;
esac
rc_exit
