#!/bin/bash
#
# $Id: xfs.init,v 1.9 2009/04/13 18:59:00 ajax Exp $
#
# xfs:       Starts the X Font Server
#
# Version:      @(#) /etc/init.d/xfs 2.0
#
# chkconfig: - 90 10
# description: Starts and stops the X Font Server at boot time and shutdown. \
#              It also takes care of (re-)generating font lists.
#
# processname: xfs
# config: /etc/X11/fs/config
# hide: true

# Source function library.
export LANG=C
. /etc/init.d/functions
# Set umask to ensure fonts.dir and similar files get created mode 0644
umask 133

prog=xfs

start() {
   FONT_UNIX_DIR=/tmp/.font-unix
   echo -n $"Starting $prog: "
   # Make sure .font-unix dir, exists.
   if [ ! -d $FONT_UNIX_DIR ]
   then
       mkdir -m 1777 $FONT_UNIX_DIR || :
       restorecon $FONT_UNIX_DIR 2>/dev/null || :
   fi
   # Fix needed for SELinux for bug (#130421,130969)
   [ -x /sbin/restorecon ] && /sbin/restorecon $FONT_UNIX_DIR

   daemon xfs -droppriv -daemon
   ret=$?
   [ $ret -eq 0 ] && touch /var/lock/subsys/xfs
   echo
   return $ret
}	

stop() {
   echo -n $"Shutting down $prog: "
   killproc xfs
   ret=$?
   [ $ret -eq 0 ] && rm -f /var/lock/subsys/xfs
   echo
   return $ret
}	

rhstatus() {
   status xfs
}	

reload() {
   if [ -f /var/lock/subsys/xfs ]; then
      echo -n $"Reloading $prog: "
      killproc xfs -USR1
      ret=$?
      echo
      return $ret
   else
      stop
      start
   fi
}

restart() {
   echo $"Restarting $prog:"
   stop
   start
}

condrestart() {
   # NOTE: We reload normally, to ensure the xfs<->Xserver connection does
   # not get broken on xfs upgrades, however we must force a restart on
   # upgrades that are migrating from monolithic Xorg (6.8.x or older) to
   # modular X, to avoid bug #173271.  The modular xfs %preun script will
   # now check for the old config file to determine if migration should be
   # done, and touch the following migration file if necessary.
   if [ -e /etc/X11/fs/xfs-migrate ] ; then
      restart
      rm -f /etc/X11/fs/xfs-migrate || : &> /dev/null
   else
      reload
   fi
}

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
    restart
    ;;
  reload)
  	reload
	;;
  condrestart)
  	[ -f /var/lock/subsys/xfs ] && condrestart || :
	;;
  status)
  	rhstatus
	;;
  *)
	echo $"Usage: $prog {start|stop|status|restart|reload|condrestart}"
	exit 1
esac

exit $?
