#!/bin/sh
# /etc/init.d/wdm: start or stop the X display manager

set -e

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/bin/X11/wdm
PIDFILE=/var/run/wdm.pid

test -x $DAEMON || exit 0

case "$1" in
  start)
    echo -n "Starting X display manager: wdm"
    start-stop-daemon --start --quiet --exec $DAEMON || echo -n " already running"
    echo "."
  ;;

  restart)
    /etc/init.d/wdm stop
    /etc/init.d/wdm start
  ;;

  reload)
    echo -n "Reloading X display manager configuration..."
    if start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE; then
      echo "done."
    else
      echo "wdm not running."
    fi
  ;;

  force-reload)
    /etc/init.d/wdm reload
  ;;

  stop)
    echo -n "Stopping X display manager: wdm"
    if [ "$(pidof $DAEMON)" ] ; then
      killall -q $DAEMON || true
      sleep 1
      if [ "$(pidof $DAEMON)" ] ; then
        killall -q -KILL $DAEMON || true
      fi
    else
      echo -n " not running"
    fi
    echo "."
  ;;

  *)
    echo "Usage: /etc/init.d/wdm {start|stop|restart|reload|force-reload}"
    exit 1
    ;;
esac

exit 0
