How to expose a UNIX domain socket directly over TCP

18,915

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.

Share:
18,915

Related videos on Youtube

SimonJGreen
Author by

SimonJGreen

Technical Director @ Wirehive. I spend most of my day sysadmining Linux servers. Twitter: @SimonJGreen

Updated on September 18, 2022

Comments

  • SimonJGreen
    SimonJGreen over 1 year

    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

  • SimonJGreen
    SimonJGreen almost 11 years
    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
    SimonJGreen almost 11 years
    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
  • Eduardo Bezerra
    Eduardo Bezerra about 7 years
    @alexandermensa care to elaborate?