Reputation: 21
I am trying to invoke a command (mysql CLI) when I connect to a certain port. This works just fine, except that every time I connect, a new instance of the command is invoked. Tried to use the end-close option but mysql CLI is killed when I close the connection, and a new one is fired when I reconnect. Command line used is below. Any way to have socat launching the mysql command once, and just reuse that process when new connections arrive? Thanks in advance!
socat TCP4-LISTEN:$port,reuseaddr,fork,bind=127.0.0.1,linger=3600 EXEC:"mysql -ANnvvf -u $user -h $host $passstr $portstr $socketstr",end-close
Upvotes: 2
Views: 659
Reputation: 430
You can do this in 2 steps, first invoke your mysql command and connect it to a named pipe
socat PIPE:/tmp/mysql_pipe EXEC:"mysql"
Then connect tcp clients to that named pipe
socat TCP4-LISTEN:31337,fork PIPE:/tmp/mysql_pipe
Upvotes: 0