[systemd-devel] Stopping services started by Systemd socket

Mantas Mikulėnas grawity at gmail.com
Tue Jan 23 07:18:41 UTC 2018


On Tue, Jan 23, 2018 at 3:06 AM, Liam Kelly <liamkelly17 at gmail.com> wrote:

> How does Systemd communicate to socket activated application that the
> connection has been closed? How can I modify my application to detect this
> event if it cannot be configured to be closed automatically?
>
>
>
> We are trying to add network support to legacy code using Systemd sockets.
> Using the 0pointer tutorials, we were able to configure a listening TCP
> port and launch an instance of the application when a TCP connection came
> in. The problem is that when the connection is closed, the service is still
> running.
>
>
>
> The systemct list-units and netstat -tuapn outputs are what you would
> expect when the connection is established
>
>
>
>     systemctl list-units:
>
>     myapp at 5-192.168.0.75:10001-192.168.210.102:19983.service loaded
> active running   My App
>
>     netstat -tuapn:
>
>     tcp        0      0 192.168.0.75:10001      192.168.210.102:19983
> ESTABLISHED 1/init
>
> However, once the client closes the connection, the socket is closed and
> removed, but the application is still running as a service:
>

It is no different from any other type of networked service. Whether you
opened the socket yourself, or received it from a superserver, makes no
difference.

For example, if your program uses poll(), the kernel reports POLLHUP on a
closed socket. If the program uses read() or recv(), 0 bytes indicates that
the socket is closed. If the program uses simple stdio (inetd style), it's
enough to check for EOF on reads from stdin.

-- 
Mantas Mikulėnas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20180123/dc925399/attachment.html>


More information about the systemd-devel mailing list