Sign inSign up

dshap/calibre

By dshap

Updated 12 days ago

Docker image for book management web server

Image
Web servers
Content management system
0

1.0K

dshap/calibre repository overview

Calibre web server

Docker image for book management web server.

Container runs as non-root user. This user owns calibre process and owns calibre files.

To run container next volumes should be mapped:

  • folder for calibre files
  • logs folder
  • backups folder

Installation

Installation from docker image
  1. Pull docker image
  2. Create user and group to own calibre files and to run docker container:
    sudo groupadd -g 1195 calibre
    
    useradd -u 1195 -g 1195 -M calibre
    
  3. Proceed to configuration
Installation from source
  1. Pull project sources from version control system
  2. Create user and group to own calibre files and to run docker container:
    sudo useradd -r calibre
    
    sudo groupmod -g 1195 calibre
    
    sudo usermod -u 1195 calibre
    
  3. Make build executable:
    sudo chmod u+x ./build
    
  4. Execute build:
    sudo ./build calibre
    
  5. Proceed to configuration
Configuration
  1. Obtain configuration files and scripts from the container:
    cd ~
    
    mkdir conf
    
    sudo chown calibre:calibre ~/conf
    
    sudo docker run \
        --rm \
        -v ~/conf:/export \
        dshap/calibre:9.11.0 export-assets
    
  2. Create folders for calibre files:
    sudo mkdir /calibre
    
    sudo mkdir /calibre/data
    
    sudo chown -R calibre:calibre /calibre
    
  3. Create a folder for logs:
    sudo mkdir /var/log/calibre
    
    sudo chown -R calibre:calibre /var/log/calibre
    
  4. Create a folder for backups:
    sudo mkdir /var/backups/calibre
    
    sudo chown -R calibre:calibre /var/backups/calibre
    
  5. Copy service configuration file:
    sudo cp ~/conf/etc/init.d/calibre /etc/init.d
    
    sudo chmod a+x /etc/init.d/calibre
    
  6. Copy docker run script:
    sudo cp ~/conf/usr/sbin/calibre /usr/sbin
    
    sudo chmod a+x /usr/sbin/calibre
    
  7. Copy util script:
    sudo cp ~/conf/usr/bin/clutil /usr/bin
    
    sudo chmod a+x /usr/bin/clutil
    
  8. Remove temporary config folder:
    sudo rm -rf ~/conf
    
  9. Register service:
    sudo update-rc.d calibre defaults
    
  10. Specify library name in /usr/sbin/calibre file:
    docker run ... -e LIBRARIES="<library_name>" ...
    
  11. Start calibre service:
    sudo service calibre start
    
  12. Create user account:
    sudo clutil manageusers
    
  13. Restart calibre service:
    sudo service calibre restart
    

Management

Service management
sudo service calibre (start|stop|status|restart)
User management
sudo clutil manage-users
Database management
sudo clutil calibredb command [options] [arguments]

calibredb command is passed to the running docker container with clutil utility.

If calibredb command requires library path to be specified, then library name (as specified in the LIBRARIES environment variable) should be used. The clutil utility translates library name to the library path. For example, to list the specified book fields in the library <library_name>, next command can be used:

sudo clutil calibredb list --library-path <library_name> -f id,authors,author_sort,title,series,series_index,publisher,tags
Create backup
sudo clutil backup <filename>

Backup file /var/backups/calibre/<filename>.tar.gz will be created.

Restore backup
sudo clutil restore <filename>
Command line (bash)
sudo clutil bash

Apache mod_proxy configuration

Calibre web server can be located with another web applications. For example, mercurial, bugzilla, wiki etc can be run as docker containers on the same host. In this case apache server can be used to redirect requests to different docker containers.

  1. Enable apache mod_proxy:
    sudo a2enmod deflate headers proxy proxy_ajp proxy_balancer proxy_connect proxy_html proxy_http rewrite
    
  2. Configure proxy:
    <VirtualHost *:80>
        ...
        ProxyPreserveHost On
        <Proxy *>
            Order allow,deny
            Allow from all
        </Proxy>
        ...
    </VirtualHost>
    
  3. Copy site configuration file:
    sudo cp ~/conf/etc/apache2/sites-available/calibre.conf /etc/apache2/sites-available
    
  4. Enable apache sites:
    sudo a2ensite calibre
    
  5. Restart apache service:
    sudo service apache2 restart
    

HOW TO

How to use multiple libraries
  1. Stop calibre service:
    sudo service calibre stop
    
  2. Specify libraries names (with colon as a delimiter) in /usr/sbin/calibre file:
    docker run ... -e LIBRARIES="library-1:library-2:library-3" ...
    
  3. Start calibre service:
    sudo service calibre start
    
How to provide anonymous access to the libraries
  1. Stop calibre service:
    sudo service calibre stop
    
  2. Specify container environment variable WITH_AUTH in /usr/sbin/calibre file:
    docker run ... -e WITH_AUTH="false" ...
    
  3. Start calibre service:
    sudo service calibre start
    

Everyone can access the libraries, but no one can make changes. To upload new books, or to change the book metadata, the container environment variable WITH_AUTH should be true. After the changes are made, the container environment variable WITH_AUTH can be changed to false again.

How to clear book metadata
sudo clutil clear-metadata <library> <column_name>

This command will clean the specified <column_name> for all books in the specified <library>.

The valid column names are:

  • identifiers
  • languages
  • pubdate
  • publisher
  • timestamp
  • rating
How to remove books

To remove the book with id <id> from the library <library_name>, the next command can be used:

sudo clutil calibredb --library-path <library_name> remove <id>

Multiple book ids can be specified (with comma separator, or with range):

sudo clutil calibredb --library-path <library_name> remove <id1>,<id2>,<id3>
sudo clutil calibredb --library-path <library_name> remove <id1>-<id3>
How to remove excessive permissions

Calibre gives 777 permit to all folders in the libraries. Calibre also gives execute permission to the log files. To remove excessive permissions, just restart calibre service:

sudo service calibre restart
How to create cron job for backups
sudo crontab -l | { cat; echo "minute hour * * * /usr/bin/clutil backup <filename>"; echo ""; } | sudo crontab -

Tag summary

Content type

Image

Digest

Size

424.6 MB

Last updated

about 5 years ago

docker pull dshap/calibre