scripts/runbot
author Markus Bröker <mbroeker@largo.dyndns.tv>
Fri, 26 Feb 2010 01:42:46 +0100
changeset 49 59b09b0aeb96
parent 42 cb24a67ec3ec
permissions -rwxr-xr-x
safe_strncpy replaces the insecure strncpy function strncpy copies up to n bytes and does not terminate it, except the null byte is in the first n bytes... 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