I have a headless machine running Ubuntu Server that is up 24/7 and would like to use it to run our algo trading system. If you’re reading this, then you’re probably aware that running the IB Gateway is not possible in Linux without an X server to handle the GUI. A possible workaround is to use X forwarding over SSH but if your network connection is interrupted it will kill IB Gateway and have to be restarted manually. So, what we need is a way to run IB Gateway without the GUI, the ability to start/stop it as a service and a method to monitor it’s status.
After some googling, I found the IBController project on github, which provides hands-free operation of IB Gateway. It completes the login dialog automatically with credentials from a
.ini file and allows IB Gateway to be launched from a script. The IBController userguide suggests that headless execution can be achieved by sending the display to a virtual framebuffer. For Arch Linux, a package has been created using IBController that manages headless IB Gateway instances. The source for this package is availbe in the IBController AUR repository. It also shows how to use monit to monitor the status of the IB Gateway instances.
Following the methodology of the IBController AUR project, I created an IBController init script for Ubuntu to start/stop instances of the IB Gateway. The init script should be copied to
/etc/init.d so the IBController service can be started using the
sudo service ibcontroller start command. You will need to install the virtual frame buffer, xvfb, which is available via apt. I couldn’t find a nice solution for capturing the PID of the java process that’s started using
xvfb-run so I resorted to this hacky solution for stopping the service:
You will also need a
.ini file in
/etc/ibcontroller for the login credentials. You can use the demo credentials to test everything is working. After adding your real credentials, ensure that the
.ini is only readable by
The next step is to setup monitoring of the IB Gateway instances using monit. Firstly, install monit via the apt package and add the following to
Now, restart monit and point your browser to
localhost:2812 and you should see the