scripts/runbot
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 25 Dec 2008 19:55:07 +0100
changeset 31 bbcb8a3366b4
parent 27 4a2f7a1492ab
child 33 56571d34d754
permissions -rwxr-xr-x
mcbot needs a proper system account mcbot used the nobody system account and changed some properties. This collides with the default selinux policiy and the new account mcbot solves this issue. 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="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