scripts/runbot
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sat, 13 Dec 2008 15:42:19 +0100
changeset 29 08ec6ddd6eea
parent 27 4a2f7a1492ab
child 31 bbcb8a3366b4
permissions -rwxr-xr-x
command must be freed - makes valgrind happy trivial changes to the debian build process committer: Markus Bröker <mbroeker@largo.homelinux.org>

#!/bin/sh

### 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="nobody"
BINARY="mcbot"
DIRECTORY="/usr/sbin/"
LANGUAGE="de_DE.UTF-8"
PARAMETER=""
LOGFILE="/var/lib/nobody/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