Mobileread
Calibre-server systemd socket unit example
#1  davidreads 01-06-2020, 08:40 PM
The calibre documentation mentions that it supports socket activation. Does anyone have a working socket unit and service unit pair that will start the server on first connection then stop the server after some timeout? Thanks in advance.

David
Reply 

#2  davidreads 01-10-2020, 04:38 PM
Answering my own question for future readers.

I created the following systemd unit files:

calibre-server@.socket:
Code
[Unit]
Description=Calibre Server socket
[Socket]
ListenStream=33154
[Install]
WantedBy=sockets.target
calibre-server@.service
Code
[Unit]
Description=Calibre content server
After=network.target
[Service]
Type=simple
User=%i
Group=%i
ExecStart=/usr/bin/calibre-server --enable-allow-socket-preallocation "/home/%i/Media/Books/Calibre Library"
RuntimeMaxSec=300
Restart=no
[Install]
WantedBy=multi-user.target
I can then start them with:
Code
systemctl start calibre-server@user1.socket
This will start the socket service for user1 to listen for connections. On connection, it will run calibre-server as user1 and serve the books out of that users's calibre library. The instance of calibre-server will stop after 5 minutes to minimize use of system resources but will start again on the next connection.

I can also add another socket unit named calibre-server@user2.socket with a different ListenStream to serve user2's library on a different port.
Reply 

Today's Posts | Search this Thread | Login | Register