# gdm - GNOME Display Manager
#
# The display manager service manages the X servers running on the
# system, providing login and auto-login services
#
# ::do_not_edit::
# ::maintainer::
#
# patched to check if ldap subsystem has started properly, if not
#	logins will not works properly
#
# patched to include /etc/default/gdm for environment (eg: to
#	setup languages, that can BE DIFFERENT from system langs)
#
description     "GNOME Display Manager"
author          "William Jon McCann <mccann@jhu.edu>"

start on ((filesystem
	   and ldap-checked
           and runlevel [!06]
           and started dbus
           and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
                or stopped udev-fallback-graphics))
          or runlevel PREVLEVEL=S)

stop on runlevel [016]

emits login-session-start
emits desktop-session-start
emits desktop-shutdown

env XORGCONFIG=/etc/X11/xorg.conf

script
    if [ -n "$UPSTART_EVENTS" ]
    then
    	if [ -f /etc/X11/default-display-manager ]; then
	    [ "$(cat /etc/X11/default-display-manager 2>/dev/null)" = "/usr/sbin/gdm" ] || { stop; exit 0; }
	else
	    type lightdm >/dev/null 2>&1 && { stop; exit 0; } || true
	fi

        if [ "$RUNLEVEL" = S -o "$RUNLEVEL" = 1 ]
        then
            # Single-user mode
            plymouth quit || :
            exit 0
        fi
    fi

    if [ -r /etc/default/locale ]; then
        . /etc/default/locale
        export LANG LANGUAGE
    elif [ -r /etc/environment ]; then
        . /etc/environment
        export LANG LANGUAGE
    fi

    #[ku]
    if [ -r /etc/default/gdm ]
    then
    	. /etc/default/gdm
    fi

    export XORGCONFIG

    exec gdm-binary $CONFIG_FILE
end script

post-stop script
	if [ "$UPSTART_STOP_EVENTS" = runlevel ]; then
		initctl emit desktop-shutdown
	fi
end script
