#! /bin/sh
### BEGIN INIT INFO
# Provides: kgb-bot
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Collaborative IRC helper
# Description: KGB is an IRC bot, helping people work together by
# notifying an IRC channel when a commit occures.
### END INIT INFO
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Collaborative IRC helper"
NAME=kgb-bot
DAEMON=/usr/sbin/$NAME
DAEMON_ARGS="--config /etc/kgb-bot/kgb.conf"
PIDFILE=/var/run/kgb-bot/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
LOCKFILE=/var/lock/subsys/$NAME
# source function library
. /etc/init.d/functions
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
RUN_AS='Fedora-kgb'
# Read configuration variable file if it is present
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
#
# create /var/run/kgb-bot and ensure right permissions
#
init_run_dir()
{
RUN_DIR="/var/run/$NAME"
[ -d "$RUN_DIR" ] || mkdir "$RUN_DIR" || return 1
chown "$RUN_AS":root "$RUN_DIR"
chmod 0775 "$RUN_DIR"
return 0
}
#
# create /var/log/kgb-bot.log and ensure right permissions
#
init_log_file() {
LOG=/var/log/kgb-bot.log
if ! test -e $LOG; then
touch $LOG
chown "$RUN_AS":root $LOG
chmod 0644 $LOG
fi
}
RETVAL=0
#
# Function that starts the daemon/service
#
start()
{
init_run_dir || return 2
init_log_file || return 2
echo -n $"Starting KGB-Bot: "
$DAEMON $DAEMON_ARGS
echo
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $LOCKFILE
}
stop()
{
echo -n $"Stopping KGB-Bot: "
killproc -p $PIDFILE $NAME
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
rm -f /var/lock/subsys/$NAME
rm -f $pidfile
fi
}
reload()
{
echo -n $"Reloading $NAME: "
killproc -p $PIDFILE $DAEMON -HUP
RETVAL=$?
echo
}
rh_status() {
status -p $PIDFILE kgb-bot
}
case "$1" in
start)
[ "$BOT_ENABLED" != "1" ] && echo $DAEMON disabled in /etc/sysconfig/$NAME>&2 && exit 0
[ "$VERBOSE" != no ] && echo "Starting $DESC" "$NAME"
start
;;
stop)
[ "$VERBOSE" != no ] && echo "Stopping $DESC" "$NAME"
stop
;;
reload)
echo "Reloading $DESC" "$NAME"
reload
;;
status)
rh_status
RETVAL=$?
if [ $RETVAL -eq 3 -a -f $LOCKFILE ] ; then
RETVAL=2
fi
;;
restart)
echo "Restarting $DESC" "$NAME"
stop
start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|status|reload}" >&2
exit 3
;;
esac
: