Nov 20, 2024 3 min read

Doukan library: A Complete Checklist for Self-Hosting Success

Doukan library: A Complete Checklist for Self-Hosting Success
Table of Contents

Doukan library is an open-source, self-hosted application designed for cataloging, managing, and sharing digital libraries with complete control over your data. Its modular architecture and extensive customization options make it a great choice for developers and tech enthusiasts looking to host a private library system. This guide will walk you through installing, configuring, and managing Doukan library, ensuring a seamless experience while leveraging its powerful features.

Installing Doukan library

πŸ“¦ Docker/Docker Compose Setup

Doukan library can be deployed easily using Docker. Below is a sample docker-compose.yml tailored to Doukan library, including persistent storage and environment variables.


version: '3.9'

services:

doukan:

image: doukanlibrary/doukan:latest

container_name: doukan

ports:

- "8080:8080"

volumes:

- ./data:/app/data

- ./config:/app/config

environment:

- APP_ENV=production

- DATABASE_URL=sqlite:///app/data/doukan.db

restart: unless-stopped

To deploy the app using this setup, run the following commands:


mkdir -p doukan && cd doukan

wget -O docker-compose.yml https://example.com/doukan-docker-compose.yml

docker-compose up -d

This configuration sets up Doukan library on port 8080 with persistent storage for your data and configuration files.

πŸš€ Manual Installation

For a more manual approach, install Doukan library directly on your Linux server:


sudo apt update && sudo apt install -y python3 python3-venv sqlite3 git

## Clone the Doukan library repository

git clone https://github.com/doukanlibrary/doukan.git

cd doukan

## Set up a virtual environment and install dependencies

python3 -m venv venv

source venv/bin/activate

pip install -r requirements.txt

## Initialize the database and run the app

python manage.py migrate

python manage.py runserver 0.0.0.0:8080

This starts Doukan library on port 8080. You can customize settings in the config directory.

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

To serve Doukan library via Nginx, create the following server block in /etc/nginx/sites-available/doukan:


server {

listen 80;

server_name yourdomain.com;

location / {

proxy_pass http://127.0.0.1:8080;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

Enable the configuration and restart Nginx:


sudo ln -s /etc/nginx/sites-available/doukan /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl restart nginx

πŸ”’ SSL/TLS Setup

To secure your installation with SSL, use Certbot to obtain a free Let's Encrypt certificate:


sudo apt install -y certbot python3-certbot-nginx

sudo certbot --nginx -d yourdomain.com

## Test auto-renewal

sudo certbot renew --dry-run

πŸ› οΈ Testing and Reloading Nginx

After making changes, always test the configuration and reload Nginx:


sudo nginx -t

sudo systemctl reload nginx

Logging and Debugging Doukan library

πŸ—ƒοΈ Enabling Debug Logs

To enable debug-level logging, modify the config/settings.py file in Doukan library:


LOGGING = {

'version': 1,

'handlers': {

'file': {

'level': 'DEBUG',

'class': 'logging.FileHandler',

'filename': '/app/data/doukan_debug.log',

},

},

'root': {

'handlers': ['file'],

'level': 'DEBUG',

},

}

Restart the app to apply changes.

πŸ“„ Viewing Logs

For Docker setups, view logs using:


docker logs doukan

For manual installations, check the log file at /app/data/doukan_debug.log.

πŸ› οΈ Troubleshooting Common Issues

  • Database Errors: Ensure the SQLite database file is writable and located in the correct directory (/app/data/doukan.db).

  • Port Conflicts: Verify that no other service is using port 8080 with sudo netstat -tulpn.

πŸ“€ Exporting Logs

To export logs to an ELK Stack, configure Filebeat on your server and point it to the log location (/app/data/doukan_debug.log).

Backup and Restore

πŸ—‚οΈ File-Based Backups

Backup Doukan library’s configuration and data with:


tar -czvf doukan_backup_$(date +%F).tar.gz ./data ./config

πŸ”„ Database Backups

Export the SQLite database:


sqlite3 /app/data/doukan.db ".backup doukan_backup.db"

To restore the database:


sqlite3 /app/data/doukan.db ".restore doukan_backup.db"

πŸ“… Automated Backup Scripts

Create a cron job to automate backups:


echo "0 2 * * * tar -czvf /backups/doukan_backup_$(date +\%F).tar.gz /path/to/data /path/to/config" | crontab -

Updating and Upgrading Doukan library

⬆️ Updating Docker Images

Update the Docker image and redeploy the container:


docker-compose pull

docker-compose down

docker-compose up -d

πŸ› οΈ Manual Updates

For manual installations, pull the latest code and reinstall dependencies:


cd doukan

git pull origin main

source venv/bin/activate

pip install -r requirements.txt

python manage.py migrate

πŸ” Checking for Updates

Check for new releases on Doukan library’s GitHub repository and subscribe to notifications.

Leveraging Doukan library’s Unique Features

πŸ”§ Enabling APIs

Doukan library offers RESTful APIs for automation. Enable the API feature in config/settings.py:


ENABLE_API = True

Access the API with tools like curl:


curl -X GET http://yourdomain.com/api/books/ -H "Authorization: Bearer YOUR_API_KEY"

🌟 Advanced Configurations

Customize library themes by editing /app/config/theme.css. For example:


body {

background-color: #f4f4f4;

font-family: "Open Sans", sans-serif;

}

Reload the app after applying changes.

Wrapping Up

By following this guide, you’ve deployed, configured, and secured Doukan library, setting the stage for effective library management. Whether you’re using it for personal archives or team collaboration, the flexibility of self-hosting ensures complete control over your data and infrastructure. Start exploring Doukan library’s advanced features and integrations to unlock its full potential!

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.