Systemd socket service failing with error when having different names for socket and service

Viewed 986

I am creating a simple echo socket service with different service and socket names. May I know where I am making a mistake? I tried having foo@.service which did not work and so I renamed the service to foo.service. I see the similar code works with socket and service named identically as echo.socket and echo@.service

$ systemctl cat bar.socket

# /etc/systemd/system/bar.socket
#bar socket
[Unit]
Description=bar socket

[Socket]
ListenStream=22223
Accept=yes

$ systemctl cat foo.service

#Foo service
[Unit]
Description=foo service

[Service]
ExecStart=-/bin/cat
StandardInput=socket
Sockets=bar.socket

After starting socket with the command systemctl start bar.socket, The status show socket

$ systemctl status bar.socket

ā— bar.socket - bar socket
   Loaded: loaded (/etc/systemd/system/bar.socket; static; vendor preset: enabled)
   Active: active (listening) since Thu 2020-03-19 20:20:00 PDT; 17s ago
   Listen: [::]:22223 (Stream)
 Accepted: 7; Connected: 0
    Tasks: 0 (limit: 2318)
   CGroup: /system.slice/bar.socket
Mar 19 20:20:00 ubuntu systemd[1]: Listening on bar socket.

Once I run the command

socat - TCP:127.0.0.1:22223

The socket crashes and I see the error below when I check the status.

* Error - $ systemctl status bar.socket *

ā— bar.socket - bar socket
   Loaded: loaded (/etc/systemd/system/bar.socket; static; vendor preset: enabled)
   Active: failed (Result: resources) since Thu 2020-03-19 20:17:59 PDT; 1min 19s ago
   Listen: [::]:22223 (Stream)
 Accepted: 7; Connected: 0

Mar 19 20:17:12 ubuntu systemd[1]: Listening on bar socket.
Mar 19 20:17:59 ubuntu systemd[1]: bar.socket: Failed to queue service startup job (Maybe the service file is missing or not a template unit?): Invalid argument
Mar 19 20:17:59 ubuntu systemd[1]: bar.socket: Failed with result 'resources'.

$ systemctl cat echo.socket

# /etc/systemd/system/echo.socket
#echo socket
[Unit]
Description=echo socket

[Socket]
ListenStream=22222
Accept=yes

$ systemctl cat echo@.service

# /etc/systemd/system/echo@.service
#Echo service
[Unit]
Description=echo service

[Service]
ExecStart=-/bin/cat
StandardInput=socket 
0 Answers
Related