Friday, 17 September 2010

Getting Calibre Server to run at Boot in Ubuntu 10.04

Calibre is a multi-platform eBook management software which supports multiple eBook reader and formats.

It also contains a simple eBook distribution server which can be accessed both via a web browser and an OPDS compatible client.

In this article I will set-up the Calibre server to start at boot time and serve books.

Even though Ubuntu 10.4 has Calibre in its repositories, I prefer to download and install the latest version as Calibre updates quite often with both compatibility fixes and new functionality.

The following procedure can be completely done over command line, on a headless system.

To do this, enter the following in a terminal:
 sudo apt-get install xdg-utils  
 sudo python -c "import urllib2; exec urllib2.urlopen('').read(); main()"  

And follow the on-screen instructions. In case something goes wrong, go here and see if the instructions have changed.

There has been a report (by Emil in the comments) that the following are also needed in Ubuntu 10.10:
 sudo apt-get install xdg-utils imagemagick python-imaging python-mechanize python-lxml python-dateutil python-cssutils python-beautifulsoup python-dnspython python-poppler libpodofo-utils libwmf-bin python-chm   

After installing Calibre, it is time to set it up for boot start up.

Enter the following:
 cd /etc/init.d  
 sudo pico calibre  

In the editor which opens up, copy and paste the following script, making changes as needed (check the top 20-30 lines). UPDATE: if you are sing Calibre 0.7.27+ you need the script from here instead.

 #! /bin/sh  
 # Provides: calibre  
 # Required-Start: network  
 # Required-Stop:  
 # Default-Start: 2 3 4 5  
 # Default-Stop: 0 1 6  
 # Short-Description: Controls the Calibre content server  
 # Description: Controls the Calibre content web server  
 # Author: Alexandrdos Schillings  
 # Please remove the "Author" lines above and replace them  
 # with your own name if you copy and modify this script.  
 # Do NOT "set -e"  
 # PATH should only include /usr/* if it runs after the script  
 DESC="Calibre Content Server"  
 # Edit the CONTENT variable below to point it to your library directory.  
 # Edit the PORT variable below to change the port the server will run on.  
 # Edit the MAX_COVER variable below to change the maximum size of a book cover image.  
 # The --develop flag refreshes the server on a database change.  
 DAEMON_ARGS="--develop --with-library=$CONTENT --pidfile=$PIDFILE --port=$PORT --max-cover=$MAX_COVER --daemonize"  
 # Exit if the package is not installed  
 [ -x "$DAEMON" ] || exit 0  
 # Read configuration variable file if it is present  
 [ -r /etc/default/$NAME ] && . /etc/default/$NAME  
 # Load the VERBOSE setting and other rcS variables  
 . /lib/init/  
 # Define LSB log_* functions.  
 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.  
 . /lib/lsb/init-functions  
 # Function that starts the daemon/service  
 # Return  
 # 0 if daemon has been started  
 # 1 if daemon was already running  
 # 2 if daemon could not be started  
 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null || return 1  
 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS || return 2  
 # Function that stops the daemon/service  
 # Return  
 # 0 if daemon has been stopped  
 # 1 if daemon was already stopped  
 # 2 if daemon could not be stopped  
 # other if a failure occurred  
 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE  
 [ "$RETVAL" = 2 ] && return 2  
 # Wait for children to finish too if this is a daemon that forks  
 # and if the daemon is only ever run from this initscript.  
 # If the above conditions are not satisfied then add some other code  
 # that waits for the process to drop all resources that could be  
 # needed by services started subsequently. A last resort is to  
 # sleep for some time.  
 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON  
 [ "$?" = 2 ] && return 2  
 # Many daemons don't delete their pidfiles when they exit.  
 rm -f $PIDFILE  
 return "$RETVAL"  
 # Function that sends a SIGHUP to the daemon/service  
 case "$1" in  
 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"  
 case "$?" in  
 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;  
 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;  
 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"  
 case "$?" in  
 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;  
 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;  
 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?  
 # If the "reload" option is implemented then remove the  
 # 'force-reload' alias  
 log_daemon_msg "Restarting $DESC" "$NAME"  
 case "$?" in  
 case "$?" in  
 0) log_end_msg 0 ;;  
 1) log_end_msg 1 ;; # Old process is still running  
 *) log_end_msg 1 ;; # Failed to start  
 # Failed to stop  
 log_end_msg 1  
 #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2  
 echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2  
 exit 3  

Save the file, and enter the following:

 sudo chown root calibre  
 sudo chgrp root calibre  
 sudo chmod 755 calibre  
 sudo insserv calibre  
 update-rc.d calibre defaults   

This will set Calibre to start at boot time, and serve books from the directory which was given in the script.

To manually start/stop the server. use the following:
 sudo /etc/init.d/calibre start  
 sudo /etc/init.d/calibre stop  

The server can now be accessed by entering the following in a web-browser:

For OPDS access, you will need to modify the URL as follows:


  1. Thanks!

    worked in Ubuntu server 10.10 base install but there were a couple of warnings when it upgraded the start script to upstart.

    To get Calibre working I had to install these packages as well:

    sudo apt-get install xdg-utils imagemagick python-imaging python-mechanize python-lxml python-dateutil python-cssutils python-beautifulsoup python-dnspython python-poppler libpodofo-utils libwmf-bin python-chm

    Also, Calibre throws a segmentation fault some times but it seems to work.

  2. Hi Emil,

    Thanks for the feedback, I'll update the article.

    Have a look to see if this update fixes the segmentation faults:

  3. nice information,

    It's work in my ubuntu server 10.10 (I used calibre-0.8.26)

  4. Thank You! This worked perfect for me.

  5. Hi, I followed the instructions and calibre-server is now opening fine in my browser. However, I'm getting any library content to show. I've checked the library path and verified that it does contain my test ebook + metadata.db files (copied from another Calibre installed on another machine.)

    Error: No books found

    Object.createException ( (

    printStackTrace (

    render_error (

    booklist (

    HTMLDocument. (

    Function.ready (

    HTMLDocument. (

  6. hi,
    I find the same as the issuer of the remark of 4 March 2012.
    Using calibre 1.1.0.

    The default folder to hold the books is /root/Calibre Library/
    The CONTENT variable has been edited to: CONTENT=/root/Calibre\ Library
    Still the above error appears in the browser when tryin to view the books.

    Any suggestions?

  7. Hello,

    On kubuntu 14.04, the line

    sudo insserv calibre

    returned an error message (insserv not found)

    So, I just skipped it and, well, it works.

    just to help.



  8. Amazing blog! I really like the way you explained such information about this post with us. And blog is really helpful for us this website


  9. I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. I hope to have many more entries or so from you.
    Very interesting blog.
    Calibre Crack