Can you make websocketd execute the program before any client connecting
First of all, thank you for building this ;)
I have a program i would like to be running before any clients connect to the websocket. Is that possible?
../websocketd --port=8080 --address=$(hostname -I) sudo someprogram
I'd say you should be careful with hostname -I; at least I assume you've read:
--address=ADDRESS Address to bind to (multiple options allowed)
Use square brackets to specify IPv6 address.
Default: "" (all)
If your SUDO is passwordless it'll work. Otherwise, since the env is always new it'll be asking for password into websocketd's input/output stream which will not quite work as expected. You can use program's STDIN/OUT and enter password from the browser using "sudo -S" but it just feels not right from security standpoint :))) You also will not see password prompt unless you catch stderr.
Thanks for the answer, but I don´t think i was clear enough, sorry.
The script actually works, but the problem is that, it first executes when I connect to the websocket. So what I want to achieve, is the script is executed when i start the websocketd, and then after you connect to it with clients. Or if the websocketd could send and receive stdout/stdin to a running process.
thanks :)
wouldn't ./script && websocketd [OPTS] ./script work for your usecase?