[systemd-devel] Interactive socket activated service?

Mantas Mikulėnas grawity at gmail.com
Thu Oct 11 06:46:11 PDT 2012


On Thu, Oct 11, 2012 at 4:18 PM, Dmitry Golubovsky <golubovsky at gmail.com> wrote:
> Hi,
>
> I am trying to implement a systemd service which provides a sort of
> REPL (read-evall-print loop) to local clients connecting to its
> control socket; at the simplest it would be "socat readline
> /path/to/socket").
> A socket is preferred because the service may obtain credentials from
> the caller to implement some access control.
>
> The .socket file looks like this:
>
> 1 [Unit]
> 2 Description=some interactive service socket
> 3
> 4 [Socket]
> 5 ListenStream=/path/to/socket
> 6 Accept=false
> 7 PassCredentials=true
> [...]
> It does not work. The socket is being created when systemd starts it,
> and upon the first connection to the socket the service script is
> started. But when the script tries to write a reply to its stdout it
> gets ENOTCONN  (transport endpoint is not connected). and I see no
> output coming from the script.
> [...]
> Inspection of /proc/XXX/fd shows that in both socat and systemd cases
> the service process' handles 0 and 1 are connected to the same socket,
> so no wrapper there.

When you have "Accept=false", systemd only passes your program the
listener socket, which is not connected to any client – systemd
expects the program to call accept() itself for every client.

If you want inetd-style socket activation, with the program's
stdin/stdout being connected to the client directly, use
"Accept=true".

-- 
Mantas Mikulėnas


More information about the systemd-devel mailing list