#!/bin/sh
#
# Script to check whether IRC Services is running, and restart it if not.
# Usage: ircservices-chk [-q] [ircservices-options]
#        -q: don't write any output
#        ircservices-options: options to pass to ircservices executable
# If you change PIDFile in ircservices.conf, also change PIDFILE below.
#
# IRC Services is copyright (c) 1996-2009 Andrew Church.
#     E-mail: <achurch@achurch.org>
# Parts written by Andrew Kempe and others.
# This program is free but copyrighted software; see the file COPYING for
# details.

PIDFILE=ircservices.pid

if [ "X$1" = "X-q" ] ; then
	exec 1>/dev/null
	exec 2>/dev/null
	shift
fi

ok=
if [ -f "@DATDEST@/$PIDFILE" ] ; then
	pid=`cat "@DATDEST@/$PIDFILE"`
	if echo "0$pid" | grep -q '[^0-9]' ; then
		rm -f "@DATDEST@/$PIDFILE"
	elif kill -0 $pid ; then
		ok=1
	fi
fi

if [ ! "$ok" ] ; then
	"@BINDEST@/ircservices" "$@"
fi
