I have to tranfer a legacy xinetd config to systemd. The requirement is to open a tcp port and listen to incoming transmissions. An application transfers one file per connection simply by netcating it to the port. When a transmission is registered, a shell script is invoked, which saves the incoming data to a file by redirecting the stdin into said file. This construct worked for years with xined. Here is what I have:
[root@localhost ~]# cat /etc/systemd/system/foo.socket
[Unit]
Description=Foo Socket
PartOf=foo.service
[Socket]
ListenStream=127.0.0.1:9999
Accept=yes
[Install]
WantedBy=sockets.target
[root@localhost ~]# cat /etc/systemd/system/foo@.service
[Unit]
Description=Foo Service
After=network.target foo.socket
Requires=foo.socket
[Service]
Type=simple
ExecStart=/usr/local/bin/foo.sh
TimeoutStopSec=5
[Install]
WantedBy=default.target
[root@localhost ~]# cat /usr/local/bin/foo.sh
#!/bin/bash
cat > /tmp/foo.$$
[root@localhost ~]# systemctl start foo.socket
[root@localhost ~]# echo "Hello World" > testfile
[root@localhost ~]# socat -u FILE:testfile TCP:127.0.0.1:9999
[root@localhost ~]# ls -al /tmp/foo.*
-rw-r--r--. 1 root root 0 Nov 7 21:20 /tmp/foo.19820
[root@localhost ~]#
The tcp port is open, the service is invoked and the shell script is executed. But the output file size is zero.
If I stop the socket and use this command:
[root@localhost system]# systemctl stop foo.socket
[root@localhost system]# /usr/lib/systemd/systemd-activate -l 127.0.0.1:9999 -a /usr/local/bin/foo.sh &
19833
[root@localhost system]# Listening on 127.0.0.1:9999 as 3.
[root@localhost ~]# socat -u FILE:testfile TCP:127.0.0.1:9999
Communication attempt on fd 3.
Connection from 127.0.0.1:39924 to 127.0.0.1:9999
Spawned /usr/local/bin/foo.sh (/usr/local/bin/foo.sh) as PID 19840
[root@localhost ~]# Child 19840 died with code 0
[root@localhost ~]# ls -al /tmp/foo*
-rw-r--r--. 1 root root 12 Nov 7 21:26 /tmp/foo.19840
[root@localhost ~]# cat /tmp/foo.19840
Hello World
[root@localhost ~]#
It works like expected. What do I miss?
Asked by baneus
(51 rep)
Nov 7, 2019, 08:32 PM
Last activity: Nov 8, 2019, 06:46 PM
Last activity: Nov 8, 2019, 06:46 PM