#!/bin/sh
# /etc/init.d/xfs: start or stop the X font server

set -e

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

test -x $DAEMON || exit 0

test -f /etc/X11/config || exit 0

if grep -q ^xbase-not-configured /etc/X11/config
then
  exit 0
fi

run_xfs=0
if grep -q ^start-xfs /etc/X11/config
then
  run_xfs=1
fi

case "$1" in
  start)
    if [ $run_xfs = 1 ]
    then
      echo -n "Starting X font server: xfs"
      start-stop-daemon --start --quiet --exec $DAEMON || echo -n " already running"
      echo "."
    fi
  ;;

  restart)
    $0 stop
    $0 start
  ;;

  reload)
    if [ $run_xfs = 1 ]
    then
      echo -n "Reloading X font server configuration..."
      start-stop-daemon --stop --signal 10 --quiet --pidfile $PIDFILE \
        --exec $DAEMON
      echo "done."
    fi
  ;;

  force-reload)
    $0 reload
  ;;

  stop)
    if [ $run_xfs = 1 ]
    then
      echo -n "Stopping X font server: xfs"
      start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON || echo -n " not running"
      echo "."
    fi
  ;;

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

exit 0
