Hubot on Linux

The (heartwarming?) story of a Hubot moving to a new home.

Behold the power of the Hubot. It is limitless.


Like many companies before us, we have found Hubot to be a useful addition to our team. He’s made our lives easier by enabling us to use our tools more efficiently. Most people wind up launching Hubot on Heroku as it is a relatively easy and well-documented process that requires little maintenance. However, some of the tools that we’re using require extensive use of shell commands, something that Heroku is not very fond of providing for us (this is the trade-off that comes with an easy server setup - a limited and not-so-configurable server). Because of this, we’ve decided to launch our own Linux server in which Hubot would be allowed to live.

The purpose of this blog post is to share (and document) the journey of a Heroku-disliking bot changing home.


When setting up a server for Hubot, there are certain dependencies to keep in mind. Most notably, to run successfully, Hubot needs:

Setup process

Some of the following commands may require root access. So if you get any errors, you might want to preface your commands with ‘sudo’ or enter root mode with ‘sudo su’.

Enter your work directory. In my case, I decided to create Hubot’s directory in /home and call it “myhubot”

cd /home

Install dependencies. Note that you may already have some of these on your server, so they need not be installed again.

apt-get update
apt-get install nodejs npm redis-server
npm install -g Hubot coffee-script

Create Hubot’s directory and install your preferred chat client’s adapter. Slack is currently filling in that role for us.

Hubot --create myhubot # substitute myhubot for your hubot's dirname choice
cd myhubot
npm install Hubot-slack --save

The remaining steps are highly dependent on the chat client that you are using. The subsequent steps outline the process for Slack, but it’s highly likely that other clients setup is very similar.

For Slack, it’s necessary to launch a Hubot integration for you team, which then provides you with some unique identifiers that Hubot can use to identify the channels that you’re team is lurking in. You will probably have to go to and follow the onscreen instructions.

Set Hubot environment variables for your preferred chat client. There’s more than one way to set environment variables. But for initial setup, this should be fine.

export Hubot_SLACK_TOKEN={Slack integration token}
export Hubot_SLACK_TEAM={Slack team name}
export Hubot_SLACK_BOTNAME={Your bot’s name. Be creative}

The next step is an optional debugging step. Although close to all-powerful, Hubot is not immortal. It’s likely to see it crash and fall at least once while writing new scripts or doing other updates. So I’m going to keep a debugging log. To do so, enable debug mode:

export HUBOT_LOG_LEVEL=debug

Start Hubot (and make it listen to Slack)

Start Hubot and redirect the output to hubot.log file inside current working dir.

bin/hubot --adapter slack > hubot.log 2>&1 &

Verbosity of the output is going to depend on the value of the environment variable HUBOT_LOG_LEVEL.

At this point there are 2 things remaining to consider:

For updating the code, I’ve written bash script that pulls github’s code from my hubot git repo (to clarify, I set up a git repository for my bot), kills the bot and restarts it.

# Enter working directory
cd /home/myhubot

# Update Hubot's code
git pull origin master

# Kill current instance of hubot. (Note: 'hubot' is to be replaced with your bot's name)
curl -F 'text=hubot die' -X POST localhost/hubot/slack-webhook

# Set hubot environment variables. Again.
export Hubot_SLACK_TOKEN={Slack integration token}
export Hubot_SLACK_TEAM={Slack team name}
export Hubot_SLACK_BOTNAME={Your bot’s name}
export HUBOT_LOG_LEVEL=debug

# Restart Hubot (and make it listen to Slack)
PORT=80 bin/hubot --adapter slack > hubot.log 2>&1 &

There are many alternative ways of doing this, including Chef deployment and capistrano. But this is fine for a start.

The script written above is also what I’m using to restart the bot. Hubot usually only crashes if there’s a reason for that to happen. And the beauty of the above script is that it updates Hubot’s code with whatever fixes I pushed into its repo before restarting.

Is this the end?

This was the tale of my bot. I wish you the best of journeys with yours.

Comments, suggestions and similar tales are well appreciated.