#!/bin/sh
#
# gdm:		Starts the Gnome Display Manager
#
# Version:	@(#) /etc/rc.d/init.d/gdm 0.1
#
# chkconfig:	5 95 05
# description:	Starts and stops the Gnome Display Manager at startup and \
#		shutdown..
#
# config:	/etc/X11/gdm/gdm-config
# probe:	true
# hide:		true

. /etc/rc.d/init.d/functions

# Get service config
if [ -f /etc/sysconfig/gdm ]; then
	. /etc/sysconfig/gdm
fi

start() {
	# Check if the service is already running?
	if [ -f /var/lock/subsys/gdm ]; then
		msg_already_running "Gnome Display Manager"
		return
	fi

	msg_starting "Gnome Display Manager"
	start-stop-daemon --start -b --exec /usr/sbin/gdm
	ok
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/gdm
}

stop() {
	if [ ! -f /var/lock/subsys/gdm ]; then
		msg_not_running "Gnome Display Manager"
		return
	fi

	msg_stopping "Gnome Display Manager"
	killproc gdm
	rm -f /var/lock/subsys/gdm
}

condrestart() {
	if [ ! -f /var/lock/subsys/gdm ]; then
		msg_not_running "Gnome Display Manager"
		RETVAL=$1
		return
	fi

	stop
	start
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status gdm gdm-binary
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
