19

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

1 Answer 1

26

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.

4
  • 4
    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? Jun 23, 2013 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, 2013 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 Jun 24, 2013 at 11:48
  • @alexandermensa care to elaborate? Feb 22, 2017 at 8:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .