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!