Bobcares

How To Create a calibre Ebook Server on Ubuntu 14.04

by | Oct 9, 2020

Wondering how to create calibre ebook server on Ubuntu? Here’s how we do it.

Here at Bobcares, we have seen several such Ubuntu related installations as part of our Server Management Services for web hosts and online service providers.

Today we’ll see how to create calibre ebook server on Ubuntu.

 

Know more about calibre ebook

Calibre is a free, open-source ebook reader that is available for Windows, Mac, and Linux. It is one of the most powerful servers that allows you to access your ebooks from any part of the world. So keeping your ebooks on a server is a great idea as you need not rely on having the same reading device.

The server comprises a simple and elegant browser front-end that allows you to search for and download books from your library. Moreover, it has a mobile-friendly site built-in, making it easy to download books straight to an e-reader.

 

How to create a calibre Ebook Server on Ubuntu 14.04

Now let’s take a look at how our Support Engineers create the calibre Ebook.

 

1. Install Calibre on Ubuntu

Calibre is available from the APT software repositories. But it is recommended to install from the binaries provided on the official website. Since the calibre updation is done frequently, the creators have made the installation simpler. You can just run the below python command for installing calibre.

sudo -v && wget -nv -O- https://raw.githubusercontent.com/kovidgoyal/calibre/master/setup/linux-installer.py | sudo python -c "import sys; main=lambda:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main()"

You can ignore the warnings that appear after running the above command.

 

2. Install Dependencies on Ubuntu

Next, we need to install the dependencies as the Calibre command-line tool calibredb is used for various operations on your Calibre library. For now, we shall install only two dependencies, i.e. ImageMagick and xvfb.

First, update the package list.

sudo apt-get update

Then run the below commands to install them.

sudo apt-get install imagemagick
sudo apt-get install xvfb

 

3. Creating Library

Now its time to create your own ebook library. Here are the two ways to do it.

  • Add ebook files directly.
  • Import an existing Calibre library.

 

Getting Books

First, create a directory for the Calibre library.

mkdir ~/calibre-library
mkdir ~/calibre-library/toadd

In ~/calibre-library directory, Calibre will organize automatically, while we’ll add books manually to the toadd sub-directory.

Now we shall download some books. For that we change to the toadd directory.

cd ~/calibre-library/toadd

Download two ebooks:

wget http://www.gutenberg.org/ebooks/1342.kindle.noimages -O pride.mobi
wget http://www.gutenberg.org/ebooks/46.kindle.noimages -O christmascarol.mobi

 

Adding the EBook to Calibre’s Database

Now its time to add these books to the Calibre database using the calibredb command. For that, run the below command.

xvfb-run calibredb add ~/calibre-library/toadd/* --library-path ~/calibre-library

The asterisk means that Calibre will add all books found in the toadd directory to the library. You must see confirmation that the books were added to the Calibre database.

Now we can test the server. For that run the below command.

calibre-server --with-library ~/calibre-library

This command will not display any output, instead, it just hangs in the terminal. It’s all fine, we can daemonize it later. Now open a web browser and navigate to:

http://your_server_ip:8080

In the above line, replace your_server_ip with your Droplet’s IP address. Now you must see the main page of your library.

 

Uploading an Existing Calibre Library

If you already have the desktop version of Calibre running and library set up, you can import it to your server easily.

Double-check your current library folder for a file called metadata.db. If this file exists, then everything should just work without any additional configuration.

Now upload your entire library folder to your server. Then run the below command.

calibre-server --with-library /path/to/calibre-library

This will add your existing library to the server.

 

4. Making Calibre a Background Service

Now let’s see how to make calibre-server into a service so that it will automatically start on system reboot. This way we can very easily start, stop, or restart the process.

If the server is running then hit CTRL + C in your terminal to stop it.

Then create a new configuration file:

sudo nano /etc/init/calibre-server.conf

Add the below code in it. Make sure to replace variables like myusername, mypassword, user

description "Calibre (ebook manager) content server"

start on runlevel [2345]
stop on runlevel [^2345]

respawn

env USER='myusername'
env PASSWORD='mypassword'
env LIBRARY_PATH='/home/user/calibre-library'
env MAX_COVER='300x400'
env PORT='80'

script
exec /usr/bin/calibre-server --with-library $LIBRARY_PATH --auto-reload \
--max-cover $MAX_COVER --port $PORT \
--username $USER --password $PASSWORD
end script

Paste this into your text editor and save it. (CTRL + X, then Y, then ENTER).

After saving the script and closing the editor, start up the server:

sudo start calibre-server

You should see this output, but with a different process number:

calibre-server start/running, process 7811

Now use a browser to navigate to your server’s IP address or domain name.

Then you must see a popup form asking for the username and password. It must be the ones you added to the Upstart script. Enter these and you’ll be taken to your ebook library as before.

The server can now easily be stopped, started, and restarted using the following commands:

sudo service calibre-server stop
sudo service calibre-server start
sudo service calibre-server restart

 

5. Creating a Cron Job to Add EBook Automatically

To watch our toadd directory for new books, we can write a simple cron job. Every 10 minutes it will look for files in the /home/user/calibre-library/toadd/ directory. It will add any files in there to our Calibre database and then remove the original files.

Run the below command to create a cron job.

crontab -e

At the end of the file add the line.

*/10 * * * * xvfb-run calibredb add /home/user/calibre-library/toadd/ -r --with-library /home/user/calibre-library && rm /home/user/calibre-server/toadd/*

That’s that. You can now access your ebooks from anywhere in the world.

[Need any further assistance with calibre queries? – We are here to help you.]

 

Conclusion

In today’s writeup, we saw how to create calibre ebook server on Ubuntu 14.04.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.