Closed mh166 closed 4 months ago
Apparently, I just found a workaround. Kind of...
When running websocat with the following command line options, it even works as a systemd service:
/usr/local/bin/websocat -t - autoreconnect:wss://example.net/websocket -H 'Cookie: X-Authorization=MyVeryLongAndSecureToken'
Notice that the important part is -t - autoreconnect:
as a whole. When using it like that, the service keeps running in the background as it should. As soon as I leave out the autoreconnect:
part and just use -t - wss://...
, it fails just as before.
While this seems like a happy accident (and indeed, it kind of is), I would prefer to handle reconnects on my own, as I might have to renew the auth token.
Therefore, I'll leave this issue open, as any input or suggestions are still very much welcome to get this sorted out properly.
Sorry, I have missed the issue when if was originally posted.
I don't know why usage or non-usage of stdin is mapped to read-write or read-only modes, but all mentioned command lines (including the adjusted one) do attempt to read from stdin.
If shell closes stdin, I except Rust standard library to re-open it as /dev/null
, so reading it would immediately produce EOF, which sends typically WebSocket close message (maybe autoreconnect:
blocks it), which causes server to also close the connection.
Maybe you want -u
/-U
(unidirectional, in one direction or the other) mode and/or -n
(do not send WebSocket close message) options.
autoreconnect:
may or may not be appropriate. I'd left it out, making Websocat exit in case of broken connections, but also making Systemd restart it more controllably.
Sorry, completely missed to respond: using the -u/-U worked perfectly. Thanks so much for the help! :)
Hi,
before anything, I want to say thanks for this amazing tool! It really helped me accomplish so much with it! š
TL;DR: How can I use
websockat
as a "read only" service for use with systemd, that does not need an activeSTDIN
?At the moment I'm having a slight problem, but maybe I'm just overlooking something: I have a working script, that connects to a
wss://
endpoint and reads log messages from there. I don't need or want to send anything towards that direction, it should only listen!For now, I'm using a shellscript to work with the messages and let it sit in a
screen
instance, so I can safely detach from the terminal and have it running in the background.websocat
's command line in this script is nothing but standard:Ultimately, I would like to have it running as a daemon. Therefore I created the following little
systemd
unit:But instead of enjoying a nice little service running in the background, it always fails on me and results in the following state:
It soon occured to me, that the problem is probably with
websocat
not having a validSTDIN
available. After a bit of debugging, I was able to reproduce the same error also in a normal shell by closingfd 0
like so (note the0>&-
at the end of the command line):As you can see, the "BrokenPipe" leads to the termination of the session. If I run it like that without closing
STDIN
, everything works just fine (in the shell).How could I make this work as a read only service?