Sample Header Ad - 728x90

How do I make systemd sockets close when service is stopped?

7 votes
4 answers
7176 views
I'm currently trying to make a systemd service with two Fifo sockets. These sockets map to stdout and stdin of the application. I'm currently using the following configuration files. *foo.service*
[Unit]
Description=foo Fifo test
After=network.target foo-in.socket foo-out.socket
Requires=foo-in.socket foo-out.socket

[Service]
Sockets=foo-out.socket
Sockets=foo-in.socket
StandardOutput=fd:foo-out.socket
StandardInput=fd:foo-in.socket
StandardError=journal
ExecStart=/path/to/foo/exec
*foo-out.socket*
[Unit]
Description=foo Task Writes to this

[Socket]
Service=foo.service
ListenFIFO=%t/foo/out
*foo-in.socket*
[Unit]
Description=foo Task reads commands from this

[Socket]
Service=foo.service
ListenFIFO=/run/user/1000/foo/in
I can start the service using the commands systemctl --user daemon-reload and systemctl --user start foo. The problem comes when I try stopping foo.service. I receive this message:
Warning: Stopping foo.service, but it can still be activated by:
  foo-in.socket
  foo-out.socket
Is there a way to stop the sockets automatically when the service is stopped?
Asked by Rene (171 rep)
Feb 5, 2019, 08:06 PM
Last activity: Oct 14, 2023, 06:02 PM