You are not logged in.

#1 2013-08-05 22:33:42

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,535
Website

Auto-start calibre server with systemd?

I'm attempting to write a systemd service/socket that would automatically start calibre-server when the port (8888) is accessed by navigating to that web page. I could very well be misunderstanding what systemd is capable of, but it seems like cups manages this. When I create the .socket file, edit the .service file to include the socket file and then enable the service, I can watch the server repeatedly being started and killed until I disable the service. This is the same whether or not I include the StopWhenUnneeded directive in the [Unit] section.

/etc/systemd/system/calibre-server.service:

[Unit]
Description=Calibre Server
After=network.target
Requires=calibre-server.socket

[Service]
Type=forking
PIDFile=/run/calibre-server.pid
ExecStart=/usr/bin/calibre-server \
    --daemonize \
    --port=8888 \
    --pidfile=/run/calibre-server.pid \
    --with-library=/mnt/media/ebooks/calibre/ \
    --url-prefix /calibre

[Install]
WantedBy=multi-user.target
Also=calibre-server.socket

/etc/systemd/system/calibre-server.socket:

[Unit]
Description=Calibre-server Socket

[Socket]
ListenStream=8888
Accept=false

[Install]
WantedBy=sockets.target

Just for reference, I have calibre-server starting just fine normally with this systemd unit file:

[Unit]
Description=Calibre Server
After=network.target

[Service]
Type=forking
PIDFile=/run/calibre-server.pid
ExecStart=/usr/bin/calibre-server \
	--daemonize \
        --port=8888 \
	--pidfile=/run/calibre-server.pid \
        --with-library=/mnt/media/ebooks/calibre/ \
	--url-prefix /calibre
Restart=on-abort

[Install]
WantedBy=multi-user.target

Any ideas?

tl;dr - trying to auto-start/stop calibre-server with systemd on an on-demand basis

Any ideas, or am I out of luck on this?

Thanks!
Scott

Edit:

I don't know if this is relevant, but I still still see the 8888 port in netstat even when the service is stopped.

$ netstat -tlnp
....
tcp        0      0 0.0.0.0:8888            0.0.0.0:*               LISTEN      3572/python2
.......

Last edited by firecat53 (2013-08-05 22:37:10)

Offline

Board footer

Powered by FluxBB