I'm thinking of switching to Digital Ocean for my hosting, so this seemed like a good first project to try there. My plan was to set up a Calibre server on a droplet and use rsync to keep the library there up-to-date with the one on my laptop. That way, I can add more books and metadata in one place and access them everywhere.
There's already a tutorial for this on the Digital Ocean site, but it uses Ubuntu 14.04. The default Ubuntu version on DO now is 18.04 and a few things have changed. Here's how I got things running.
I created my DO account and added a new droplet, the smallest size, with 1GB memory and 25GB disk space. Then I followed their tutorial for initial server setup on Ubuntu 18.04. Note that the tutorial includes setting up a firewall (UFW) to deny all connections except SSH. The Calibre server listens for HTTP traffic on port 8080, so you'll have to allow that:
sudo ufw allow 8080
My sudo user is called
rae. If you see that name in commands on this page, you should replace it with your own user.
Installing and running Calibre
The Digital Ocean tutorial mentions that you should check the official Calibre page to see if the installation command has changed. It has, and currently it's:
sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin
I found that I had to install one more dependency than mentioned in the tutorial to get Calibre working. (Thanks, snesbitt!)
sudo apt-get install libfontconfig
When I got to running the server, I also saw this error:
No write acces to /home/rae/.config/calibre using a temporary dir instead
This was solved by changing the
/home/rae/.config directory to be owned by my user instead of
sudo chown rae:rae ~/.config
Uploading my library
The tutorial tells you to upload your library without explaining how. I used
scp, in a terminal on my laptop:
scp -r ~/Calibre\ Library/ email@example.com:calibre_library
~/Calibre\ Library/ is my local library folder. Replace my username,
rae, with yours and
xxx.xxx.xxx.xxx with the IP address of your droplet.
calibre_library is the name I picked for the new library folder on the droplet.
I could now run Calibre from the droplet using the following command, and access it by going to
xxx.xxx.xxx.xxx:8080 in the browser. Hooray!
Adding a server user
The information in the tutorial on running Calibre in the background, including adding password security, is all outdated. Luckily, the official Calibre docs are up-to-date. The currently recommended way to manage users is to create a database, which also allows you to have multiple different users.
I followed the instructions in the Calibre docs, using the following command to create a Sqlite user database and add a user for myself:
calibre-server --userdb /srv/calibre/users.sqlite --manage-users
Then I ran Calibre again, with authentication enabled:
calibre-server --userdb /srv/calibre/users.sqlite --enable-auth
Now, when you visit your server in the browser, you will be prompted to login.
Running Calibre in the background
Again, the Calibre docs are the way to go here. They use systemd, instead of the outdated Upstart service described in the Digital Ocean docs.
To keep using the auth you just set up when running the Calibre server automatically, make sure to change the
ExecStart line of the service config in the docs. It should look like this:
ExecStart=/opt/calibre/calibre-server "/home/rae/calibre_library" --userdb "/srv/calibre/users.sqlite" --enable-auth
At this point, I noticed an error saying that Calibre was trying to write to a non-writeable database. The user that systemd was running the command with did not have write access to the user database. To allow this, I ran this command, which gives write access to my user plus all users in my group:
chmod +w /srv/calibre/users.sqlite
Updating the Calibre library automatically
The Digital Ocean tutorial suggests a way to update the server's library by adding books to a folder on the droplet. This wasn't what I wanted: I want to be able to mess with my library locally and see the changes reflected on the server. I decided to use
rsync to update the server library.
I ran this command to add a new cron on my laptop:
This is what I added:
*/10 * * * * rsync -r ~/Calibre\ Library/ firstname.lastname@example.org:calibre_library
Every ten minutes, this will run
rsync between my local Calibre library and the one on the server. (Remember to use your own username and droplet IP address.) This will only upload the necessary data when something has actually changed, instead of copying everything over like
The endnotes of the Digital Ocean tutorial, regarding copyrights, updates and security, are worth reading.
In Switzerland, where I live, filesharing is legal so long as you're only downloading the files. Uploading copyrighted files for sharing is illegal. That's why it was important to me to password-protect my server, as it contains copyrighted books I've bought new, out-of-copyright books from Project Gutenberg and similar sources, and all manner of other junk. Incidentally, although I disapprove of pirating books, I also prefer to strip DRM from files I've legally bought. Apprentice Alf's DeDRM plugin for Calibre is a wonderful tool for this and I recommend it.
I hope you get your own Calibre servers up and running easily. Enjoy reading your ebooks from anywhere you have a browser!