View Single Post
Old 09-08-2016, 11:59 AM   #8
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Happy to help.

FWIW, I use the following systemd service unit:
Code:
[eschwartz@arch ~]$ cat ~/.config/systemd/user/calibre-server@.service
[Unit]
Description=Main calibre server
After=network.target

[Service]
EnvironmentFile=/%h/.config/calibre/servers/%i.conf
ExecStart=/usr/bin/calibre-server \
    --port="${port}" \
    --with-library "${path}" \
    --restriction "${restriction}" \
    --user "${user}" \
    --pass "${pass}"

[Install]
WantedBy=default.target
It is enabled as a user unit, so it runs using your systemd user session at login -- although you could easily modify it to run as root and declare the right "User=".

It also makes use of systemd variables (see `man systemd.unit` under SPECIFIERS), and is written as a template in order to make use of server configuration files to run multiple instances using the same unit file.

PIDFile is NOT needed, except for services that MUST run as a "forking"-type service -- the PIDFile lets it track the lifetime of the program, but calibre does not require running as a forking service... this (avoiding a PIDFile in some cases) is one of the improvements of systemd. --daemonize and --pidfile exist for other init systems that need to fork.
But if you were to use a PIDFile, you would of course want to use the systemd specifier that lets you choose the right runtime directory instead of struggling with inane permissions issues like that guide described.

The server config file looks like this:
Code:
[eschwartz@vostro ~]$ cat ~/.config/calibre/servers/servername.conf
port="8080"
path="/path/to/Calibre Library"
restriction="some restriction"
user="server username"
pass="server password"
eschwartz is offline   Reply With Quote