#!/bin/sh
# This is the LCDd init-script for RPM based (Red Hat, Mandrake) systems
#
# Copyright (C) 2001  Rene Wagner <reenoo@gmx.de>
#               2001  Guillaume Filion <gfk@logidac.com>
#
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this file; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
#
#
# chkconfig: - 70 21
# description: LCDd(8) is the LCDproc server used for displaying text and other data to LCDs. \
#	Apart from the main client lcdproc(1) there are various clients. \
#	See http://lcdproc.omnipotent.net for details.
# processname: LCDd
# pidfile: /var/run/LCDd.pid
# config: /etc/sysconfig/lcdproc/LCDd.conf
#
### BEGIN INIT INFO
# Provides:          LCDd
# Required-Start:    $syslog $local_fs $network $remote_fs
# Required-Stop:     $syslog $local_fs $network $remote_fs
# Should-Start:      udev
# Default-Start:
# Default-Stop:      S 0 1 6
# Short-Description: LCDproc Server Daemon
# Description:       init script for LCDd, the display
#                    server daemon in the LCDproc suite
### END INIT INFO

prog=LCDd
lockfile=/var/lock/subsys/$prog
configfile=/etc/sysconfig/lcdproc/$prog.conf

# load LSB 3.x init functions
if [ -e /lib/lsb/init-functions ]; then
  . /lib/lsb/init-functions
fi

# Source function library.
if [ -e /etc/rc.d/init.d/functions ]; then
  . /etc/rc.d/init.d/functions
fi

# Source networking configuration.
if [ -e /etc/sysconfig/network ]; then
  . /etc/sysconfig/network
fi

# Check that networking is up.
if [ ${NETWORKING} = "no" ]; then
        exit 0
fi

# check that non-default config file exists.
[ -f $configfile ] || exit 6

RETVAL=0

prefix=/usr
exec_prefix=/usr
bindir=/usr/bin
sbindir=/usr/sbin
etc=/etc/sysconfig/lcdproc

[ -x ${sbindir}/${prog} ] || exit 0

start() {
	echo -n "Starting ${prog} service: "
	daemon ${prog} -c ${configfile}
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch ${lockfile} || \
	   RETVAL=1
	return $RETVAL
}

stop() {
	echo -n "Shutting down ${prog} service: "
	killproc ${prog}
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f ${lockfile}
	return $RETVAL
}

reload() {
	echo -n $"Reloading ${prog} conig file: "
	killproc ${prog} -HUP
	RETVAL=$?
	echo
	return $RETVAL
}

dostatus() {
	status ${prog}
	return $?
}

restart() {
	stop
	start
	return $?
}

condrestart() {
	[ -f ${lockfile} ] && restart || :
	return $?
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	dostatus
	;;
  restart|force-reload)
	restart
	;;
  try-restart|condrestart)
	condrestart
	;;
  reload)
	reload
	;;
  *)
	echo "Usage: $0 {start|stop|status|restart|condrestart|reload}"
	exit 2
esac

exit $RETVAL
