Howto install Calibre Content Server


(Marc) #1

A Work In Progress howto to install Calibre Server in NethServer, as requested in this thread: Education applications wishlist

WARNING: Not yet ready to use on a production server

The calibre Content server allows you to access your calibre libraries and read books directly in a browser by downloading the book in an off-line cache.

Install Calibre Server:

sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin

By default Calibre Content Server will be installed under /opt/calibre path. To use a different location check the installation options.

Create a directory to store a library. If you want to use more than one library a better naming would be /var/lib/nethserver/calibre/libraries/default and so on. For simplicity here we will use a single library.

mkdir -p /var/lib/nethserver/calibre/library

Add books to the library. You can upload some e-books to your server, or download them form Project Gutenberg, for example. Calibre identifies file types by its extension, make sure the uploaded e-books have the appropriate file extension. For simplicity here we create an empty book:

calibredb add --empty "test.epub" --title "Test" --with-library "/var/lib/nethserver/calibre/library"

Calibre can be set to work in read-only mode and open access, or work with user credentials. You can add users and set permissions using:

#add users and set permissions (interactive)
calibre-server --userdb "/var/lib/nethserver/calibre/users.sqlite" --manage-users

To auto-start calibre-server you can create a service unit:

cat << EOF > /etc/systemd/system/calibre-server.service
[Unit]
Description=calibre content server
After=network.target

[Service]
Type=simple
User=calibre
Group=calibre
ExecStart=/opt/calibre/calibre-server \
	--access-log=/var/log/calibre-server-access.log \
	--ban-after=3 \
	--ban-for=10 \
	--enable-auth \
	--log=/var/log/calibre-server.log \
	--port=8008 \
	--url-prefix=/calibre \
	--userdb=/var/lib/nethserver/calibre/users.sqlite \
	"/var/lib/nethserver/calibre/library"

[Install]
WantedBy=multi-user.target
EOF

Not all the options are required for the service. More options for calibre-server command are described in the manual. Some interesting ones are:

--daemonize \
--listen-on=127.0.0.1 \
--max-log-size=20 \
--max-request-body-size=30 \
--num-per-page=20 \
--pid-file=/var/run/calibre-server.pid \
--shutdown-timeout=25 \
--ssl-certfile=/path to cert \
--ssl-keyfile=/path to keyfile \
--worker-count=30 \

As we have set the service to run as calibre user, we create that user:

useradd -r -s /sbin/nologin -d /var/lib/nethserver/calibre -c "Calibre User" calibre

Enable access to the calibre web page through apache web server:

cat << EOF > /etc/httpd/conf.d/zz_calibre.conf
AllowEncodedSlashes On
RewriteEngine on
RewriteRule ^/calibre/(.*) http://127.0.0.1:8008/calibre/$1 [proxy]
RedirectMatch permanent ^/calibre$ /calibre/
EOF

Reload/Restart web server to apply the changes:

systemctl reload httpd

Before we forget, set permissions for calibre’s database, libraries and e-books:

chown -R calibre:calibre /var/lib/nethserver/calibre

Prepare log files:

touch /var/log/calibre-server.log /var/log/calibre-server-access.log
chown calibre:calibre /var/log/calibre-server*.log

Enable a port for calibre-server:

config set fw_calibreserver service status enabled TCPPort 8008 access green
signal-event firewall-adjust

Enable and start calibre-server service:

systemctl enable --now calibre-server

Access calibre server from a web browser going to http://SERVER_IP:8008/ or http://SERVER_IP:8008/calibre and login with any user created through calibredb command. (You can try to access http://SERVER_IP-or-FQDN/calibre but at some point reading books containing graphics might throw an error).

You can browse the library, upload e-books (if user have no restrictive permissions), read/convert/download them.

To log out you have to either clean session and cookies or close the browser.


To consider:

  • Not exposing another port
  • Use a Reverse Proxy
  • Use a Virtual Host
  • https access
  • logrotate
  • No AD/LDAP integration. Consider an import script or, IF it’s even possible, append some action to user create/modify events (only for local accounts provider, won’t work with remote providers).
  • Security
  • Consider other e-book management options.

Community SPRINT
Education applications wishlist
(Markus Neuberger) #2

Very nice! Working as expected. :sunglasses:

You didn’t restart httpd after creating the zz_calibre.conf file but it’s working without it, at least in my first tests.

grafik


(Rob Bosch) #3

I have been asking around on the calibre forums about LDAP/AD authentication. https://www.mobileread.com/forums/showthread.php?t=309507
The answer to my question:

Use a reverse proxy, then you can use whatever authentication scheme you like in the proxy server. The calibre server uses http auth set it to use basic http uath instead of digest and pass the Authorization header from the proxy server to the calibre server.

Would this be an option/possible to implement in NS? And would this be an option for other NON LDAP/AD applications to configure authentication? (like Gibbon for instance)


(Mark Verlinde) #4

I saw fedora has a package for calibre and tried to rebuild it for centos without succes:

Error: No Package found for python-cssutils >= 0.9.9
Error: No Package found for python-html5-parser
Error: No Package found for python-mechanize
Error: No Package found for python-qt5
Error: No Package found for python-qt5-devel
Error: No Package found for python-qt5-webkit

Stopped my experiment here, if this thread evolves further:
here my promise to have a go to build it for centos/nethserver.
(someone succeeded two years ago why shouldn’t we?
https://copr.fedorainfracloud.org/coprs/seuvitor/calibre/packages/)