10

I'd like to have a UNIX domain socket, say /var/program/program.cmd for example, exposed via TCP, lets say on port 12345. I'd also like this to be running full time in the background.

What's the best way to do this? If its relevant the system is running Ubuntu 12.04.2.

Also with the proposed solution will it survive the domain socket being removed and recreated?

EDIT

Here is the outcome of the accepted answer in the form of an init script: https://github.com/Wirehive/haproxy-remote

15

You can use socat to export your unix socket as TCP socket. Here is the command to do so:

socat TCP-LISTEN:12345 UNIX-CONNECT:/var/program/program.cmd

This will create TCP socket listening on port 12345 which will connect to mentioned unix socket of your program.

For the deletion issue, I did not test it myself. You can verify it and tell us about it :)

Note: You may not find socat installed, you just need to type: apt-get install socat to install it.

  • 1
    Thanks that pretty much worked, although it exited after each communication. After playing around I'm having good success with: socat TCP-LISTEN:12345,reuseaddr,fork,su=haproxy UNIX-CLIENT:/var/program/program.cmd. Only question is how I get it running in the background? – SimonJGreen Jun 23 '13 at 16:58
  • @SimonJGreen: Since this is not an interactive command that requires input, you can just try appending & at the end of the command. – Khaled Jun 24 '13 at 6:57
  • OK I ran with the suggestion and wrote an init script to handle it. Here's the outcome for anyone interested! github.com/Wirehive/haproxy-remote – SimonJGreen Jun 24 '13 at 11:48
  • @alexandermensa care to elaborate? – Eduardo Bezerra Feb 22 '17 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.