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.