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):
#!/bin/bash
echo "Run xvfb-run /usr/bin/ebook-convert $@"
xvfb-run /usr/bin/ebook-convert "$@"