On 05/09/2024 15:52, Mantas Mikulėnas wrote:

FIFOs aren't sockets – they do not have an equivalent to accept() and there is no multiplexing of inputs; all writes to the FIFO immediately go to the "listening" file descriptor. So it's almost more like a datagram socket than a stream one, in a sense.

If you want a true socket that's filesystem-based, create a Unix socket by specifying the path via ListenStream, then connect to it using nc -U.



Yes writing the socket at:

# emailoutput.socket
[Unit]
Description=Send email

[Socket]
ListenStream=%t/emailoutput.socket
Accept=yes

Then things like

echo "Hi There"  | nc -U /run/emailout.socket

work great and an instance of emailoutput@.service is created.

Then the final thing I was trying to do was use that created ListenStream that from another unit. e.g.

[Unit]
Description=Simple command

[Service]
ExecStart=/usr/bin/ls /etc/passwd /etc/notexisting
StandardOutput=file:/run/emailoutput.socket
StandardError=file:/run/emailoutput.socket

A single email of Output and Error is generated - that's great - thanks.

No more questions.

Steve.


On Thu, Sep 5, 2024, 13:38 Steve Traylen <steve.tray...@cern.ch> wrote:

    Was trying to set up a trivial socket and service to process multiple
    inputs:

    # Socket emailoutput.socket
    [Unit]
    Description=Send email via a socket.

    [Socket]
    Accept=yes
    ListenFIFO=/run/emailoutput.socket

    # Service emailoutput@.service
    [Unit]
    Description=email

    [Service]
    ExecStart=/usr/bin/mailx -s 'Testing from socket' st...@example.ch
    StandardInput=socket


    Starting the socket always produces: "Unit configured for accepting
    sockets, but sockets are non-accepting. Refusing"

    Switching the socket to  "ListenStream=127.0.0.1:9999
    <http://127.0.0.1:9999>" then everything
    works I can netcat files into the network socket.
    Is it impossible to to Accept=yes with ListenFIFO?


    Motivation for was this i wanted to do perform a systemd-run of a
    command outputting to that socket to pipe it into mailx.

Reply via email to