#!/bin/sh
# $Id: sample-etc_rc.d_init.d_ddclient.redhat 2 2006-05-22 19:37:19Z wimpunk $
# qchatd     This shell script takes care of starting and stopping
#               qchatd.
#
# chkconfig: 2345 65 35
# description: QChat Server - server application for lan chat

. /etc/rc.d/init.d/functions

NAME=qchat-server
PIDFILE=/var/run/$NAME/$NAME.pid
LOCKFILE=/var/lock/subsys/$NAME
RUN="$NAME &"

# See how we were called.
case "$1" in
  start)
	# Start daemon.
        start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --user qchat --expect-user qchat  -- $RUN \
	&& echo `ps ax | awk '{print $1,$5}' | grep qchat-server | awk '{print $1}' | awk '{print $1}'` > $PIDFILE || failure
	;;
  stop)
	# Stop daemon.
	stop_daemon --lockfile "$LOCKFILE" --expect-user qchat -- $NAME \
	&& rm -rf "$PIDFILE" || failure
	;;
  restart)
	$0 stop
	$0 start
	;;
  condrestart)
	if [ -e "$LOCKFILE" ]; then
	$0 restart
	fi
	;;
  status)
	status --pidfile "$PIDFILE" --expect-user qchat -- $NAME
	;;
  *)
	echo "Usage: qchatd {start|stop|restart|condrestart|status}"
	exit 1
esac

exit 0
