Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systemd/inetd socket activation #126

Open
jkhsjdhjs opened this issue Apr 22, 2022 · 3 comments
Open

systemd/inetd socket activation #126

jkhsjdhjs opened this issue Apr 22, 2022 · 3 comments

Comments

@jkhsjdhjs
Copy link

It would be cool if pantalaimon supported systemd or inetd socket activation, so that it can be started on demand, when a matrix client is trying to connect.
For this, pantalaimon would need to be able to accept sockets passed from systemd/inetd, either via systemd's native socket passing interface or via standard input/output (inetd).
See the second to last paragraph of this section: https://www.freedesktop.org/software/systemd/man/systemd.socket.html#Description

@Stebalien
Copy link

FYI, systemd-socket-proxyd works pretty well for this kind of thing.

@jkhsjdhjs
Copy link
Author

Thanks for letting me know, systemd really has a solution for everything!

@jkhsjdhjs
Copy link
Author

jkhsjdhjs commented Aug 1, 2023

I finally got to try the solution via systemd-socket-proxyd and defined the units as follows:

pantalaimon-proxy.socket

[Socket]
ListenStream=127.0.0.1:8009

[Install]
WantedBy=sockets.target

pantalaimon-proxy.service

[Unit]
Requires=pantalaimon.service pantalaimon-proxy.socket
After=pantalaimon.service pantalaimon-proxy.socket

[Service]
# wait 5 seconds to ensure pantalaimon.service is up and can accept connections
ExecStartPre=/usr/bin/sleep 5
ExecStart=/usr/lib/systemd/systemd-socket-proxyd --exit-idle-time=5m 127.0.0.1:8010

This allows pantalaimon to be started on demand. Furthermore, when extending pantalaimon by StopWhenUnneeded=yes, it is stopped 5 minutes after pantalaimon-proxy.service isn't proxying any connections anymore, as defined by --exit-idle-time=5m. pantalaimon has been configured to listen on localhost on port 8010.
I added ExecStartPre as sleep 5 seconds to the pantalaimon-proxy.service, because pantalaimon doesn't immediately accept connections after it is started. It usually takes 2 seconds on my machine. A better solution would be Type=notify support for pantalaimon, but at least it works for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants