#! /bin/sh

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/fubot/bin/hubot
NAME=fubot
DESC="Jabber Bot"

CONF="-a xmpp --name $NAME"
BOT_USER=fubot
BOT_GROUP=fubot
PIDFILE=/var/run/fubot/pid.fubot
RUN_DIR=/opt/fubot

USERNAME=fubot@freelancersunion.org\/fubot
PASSWORD=oyk:Cz5\/Zo\>H3M\$\{
ROOMS=it@conference.freelancersunion.org

ERROR_LOG=/var/log/fubot/error.log

set -e

function start_bot(){
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec /usr/bin/env \
        --make-pidfile --chuid $BOT_USER --group $BOT_GROUP -- \
        PATH=$PATH:/opt/node/bin PWD=$RUN_DIR HUBOT_XMPP_ROOMS=$ROOMS \
        HUBOT_XMPP_USERNAME=$USERNAME HUBOT_XMPP_PASSWORD=$PASSWORD \
        $DAEMON $CONF 2>&1 | ( while read line; do echo "$(date): ${line}"; done ) > $ERROR_LOG &
}

function stop_bot(){
    start-stop-daemon --stop --quiet --pidfile $PIDFILE
}

case "$1" in
  start)
        echo -n "Starting $DESC: $NAME"
        start_bot
        echo "."
        ;;
  stop)
        echo -n "Stopping $DESC: $NAME"
        stop_bot
        echo "."
        ;;
  restart)
        echo -n "Restarting $DESC: $NAME"
        stop_bot
        sleep 1
        start_bot
        echo "."
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}" >&2

        exit 1
        ;;
esac

exit 0

fubot-init.sh hosted by GitHub