Run socat only once.
I'm trying to expose docker web services via TCP. On macOS/linux these services are bound to a unix socket. The following command accomplishes the task:

socat -d TCP-LISTEN:2376,range=,reuseaddr,fork UNIX:/var/run/docker.sock

So I don't have to remember to type this all the time, I'd like it to start when the computer starts. I don't know how to accomplish that particular goal, but I have done a little bit of work with .bash_profile. So I'll settle for running socat whenever a terminal runs. However, since .bash_profile runs for every terminal instance, I'd like a mechanism that only runs the command if it's not already running. But I don't know how to check, from .bash_profile if something is already running. Can you help?

  • @NasirRiley: probably because I'm not familiar with those. – Sam Axe Aug 29 '19 at 1:34

If you want that command to start at boot then you can just use a cronjob.

As root:

crontab -e

Next, enter the following just like you would in a text editor:

@reboot /usr/bin/socat -d TCP-LISTEN:2376,range=,reuseaddr,fork UNIX:/var/run/docker.sock

That tells crontab to run your command when the system boots. Make sure that there is a new line following the command by pressing ENTER after it. Enter :wq! just like you would in vim to save it.

Reboot your system and then grep for the command to make sure that it's running.

ps aux | grep socat

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.