HipChat is a very nice chat software by Atlassian. Hubot is an amazing XMPP chat bot that makes usage of HipChat orders of magnitude more effective and FUN.

There’s a handy HipChat Hubot adapter that brings Hubot awesomeness to HipChat. HipChat Hubot project’s README provides very well-documented installation instructions for Heroku or barebones OS-X/Debian/Ubuntu (hint: just skip the Heroku steps).

There are only two shortcomings that I ran into:

  • Current version of the adapter seems to have a nasty problem with Redis-Brain extension: https://github.com/hipchat/hubot-hipchat/issues/109. Solution: remove redis-brain.coffee from hubot-scripts.json
  • Instructions come short on providing a nice daemon script if you do decide to host Hubot yourself and skip the whole Heroku thing.

Following is what worked for me. Please note that sample code assumes you checked-out hubot under /home/yourname/hubot folder and intend to run it under yourname user. This is not an init.d script. If it were, you’d have to deal with sudoing into a user from root user, managing missing paths and a number of other things which which I had no patience dealing with.

First you need to create a config file under /home/{change user}/hubot/bin. Call it .hubotrc:

#---------------- HUBOT CONFIG -----------------------------------

export HUBOT_HIPCHAT_JID="... fill this in ... "
export HUBOT_HIPCHAT_PASSWORD="... fill this in ... "
export HUBOT_AUTH_ADMIN="... fill this in ... "

export HUBOT_ADAPTER="hipchat"
export HUBOT_PATH="/home/{change user}/hubot"

#---------------- END HUBOT CONFIG --------------------------------

npm install
export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"

Under the same folder, create a daemon.sh that looks something like following:

#!/bin/sh

USER_HOME="/home/$USER"
HUBOT_ROOT="$USER_HOME/hubot"
HUBOT_HOME="$HUBOT_ROOT/node_modules/hubot"
DAEMON="$HUBOT_HOME/bin/hubot"
PIDFILE=$HUBOT_ROOT/hubot.pid

case "$1" in
start)
        echo "Starting"
        . $HUBOT_ROOT/bin/.hubotrc
        /sbin/start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile -d $HUBOT_ROOT --exec $DAEMON
        echo "."
        ;;
debug)
        echo "Debug mode: no backgrounding"
        . $HUBOT_ROOT/bin/.hubotrc
        /sbin/start-stop-daemon --start --pidfile $PIDFILE --make-pidfile -d $HUBOT_ROOT --exec $DAEMON
        echo "."
        ;;        
stop)
        echo "Stopping"
        /sbin/start-stop-daemon --stop --pidfile $PIDFILE
        echo "."
        ;;  
restart)
        echo "Restarting"
        /sbin/start-stop-daemon --stop --pidfile $PIDFILE
        . $HUBOT_ROOT/bin/.hubotrc
        /sbin/start-stop-daemon --start --pidfile $PIDFILE --make-pidfile --background -d $HUBOT_ROOT --exec $DAEMON
        echo "."
        ;;


    *)
        echo "Usage: $0 {start|stop|restart|debug}" >&2
        exit 1
        ;;  
    esac
    exit

The daemon mode is useful when you do not want to background hubot because you are debugging some trouble and do need to actually see the output from the script.

Happy chatting and botting.