How to run gitbook on a headless server (make Calibre run in headless server)?

When use gitbook to generate ebook, Calibre reports this:

RuntimeError: X server required. If you are running on a headless machine, use xvfb

After xvfb is installed, it does not work either.

How to make gitbook/Calibre work on a headless server?

You need to wrap the command ebook-convert with xvfb-run. However, in gitbook (lib/generate/ebook/index.js), ebook-convert is called directly.

You may change gitbook to call xvfb-run ebook-convert. However, when you upgrade gitbook, you lost the change.

My solution is to add this wrapper so that calling ebook-convert is actually invoking this wrapper:

Saved to /usr/local/bin/ebook-convert (since /usr/local/bin/ is before /usr/bin/ in my $PATH):


echo "Run xvfb-run /usr/bin/ebook-convert $@"

xvfb-run /usr/bin/ebook-convert "$@"

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *