Assuming a minimal example like in this question, except for another shell script.
[Unit]
Description=Foo Service
After=network.target systemfoo.socket
Requires=systemfoo.socket
[Service]
Type=oneshot
ExecStart=/bin/bash /opt/foo/foo.sh
TimeoutStopSec=5
[Install]
WantedBy=multi-user.target
systemfoo.socket
[Unit]
Description=Foo Socket
[email protected]
[Socket]
ListenStream=127.0.0.1:7780
Accept=Yes
[Install]
WantedBy=sockets.target
/opt/foo/foo.sh
#!/bin/bash
while true; do
logger -t FOO "Connection received: $REMOTE_ADDR $REMOTE_PORT"
done
When I connect via
nc 127.0.0.1 7780
the script is invoked correctly. But when I quit nc with CTRL-C, the script runs forever.
Is there a mechanism to send a SIGTERM to the script process, when closing the socket (I assume nc does that when quitting)?