phdoerfler
phdoerfler

Reputation: 479

How to turn any program reading from standard input into a server using systemd?

According to https://www.launchd.info/ (the cookbook section):

launchd makes it very easy to create servers. In fact, launchd can turn any program reading from standard input into a server.

Since systemd is more or less a clone of / heavily inspired by launchd, I suspect that the same functionality might be present there as well. However, a brief look through the docs and an equally brief google-ing later I came up empty handed. Is this possible and if yes: how so?

Alternatives considered

There is of course good old (x)inetd which does exactly this. There is also websocketd which I found during this research, which seems handy. However, I'd rather not have to learn yet another config language for this.

Upvotes: 0

Views: 461

Answers (1)

phdoerfler
phdoerfler

Reputation: 479

Of course shortly after posting this question I googled some more and with inetd in the search terms I discovered this nicely written blog post, according to which you need a .socket file for everything socket related and the usual .service file, albeit with a twist (see the note at the end). Without further ado, here's the example from the blog post:

sshd.socket

[Unit]
Description=SSH Socket for Per-Connection Servers

[Socket]
ListenStream=22
Accept=yes

[Install]
WantedBy=sockets.target

[email protected]

[Unit]
Description=SSH Per-Connection Server

[Service]
ExecStart=-/usr/sbin/sshd -i
StandardInput=socket

Worthy of note is the @ which I assume turns this into an instantiated service.

I haven't yet tried this, so buyer beware.

Upvotes: 1

Related Questions