scripts/runbot
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sat, 27 Feb 2010 19:00:11 +0100
changeset 51 5d9aed3948a6
parent 42 cb24a67ec3ec
permissions -rwxr-xr-x
code review, close and free all resources in config.c committer: Markus Bröker <mbroeker@largo.homelinux.org>

#!/bin/bash

### BEGIN INIT INFO
# Provides:          mcbot
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: IRC BOT mcbot
# Description:       IRC BOT mcbot
### END INIT INFO

RUNAS="mcbot"
BINARY="mcbot"
DIRECTORY="/usr/sbin/"
LANGUAGE="de_DE.UTF-8"
PARAMETER=""
LOGFILE="/var/lib/mcbot/mcbot-`date \"+%d-%m-%y\"`.log"

[[ ! -x "${DIRECTORY}/${BINARY}" ]] && exit 0

start() {
	echo -n " * Starting ${BINARY}"
	su - ${RUNAS} -c "LANG=$LANGUAGE ${DIRECTORY}/${BINARY} ${PARAMETER} &> ${LOGFILE} &"
	if [ "$?" == 0 ]; then
		echo " [started]"
	fi
}

stop() {
	echo -n " * Stopping ${BINARY}"
	pid=`pidof ${BINARY}`
	if [ "$pid" != "" ]; then
		kill -TERM `pidof ${BINARY}`
		sleep 5
	fi
	echo " [stopped]"
}

status() {
	pid="`pidof ${BINARY}`"
	if [ "$pid" != "" ]; then
		echo "${BINARY} is started as ${pid}"
	else
		echo "${BINARY} is not running"
	fi
}

case "$1" in
	start)
		start
	;;
	stop)
		stop
	;;
	status)
		status
	;;
	restart)
		echo "Restarting ${BINARY}"
		stop
		start
	;;
	force-reload)
		echo "Force reload stub"
		stop
		start
	;;

	*)
		echo "Usage: start|stop|restart|status|force-reload"
	;;
esac

exit 0