0

I need to run this command on Mac OS X El Capitan. I found it on this guide about Eclipse Che. However, when I try to do that, socat keeps waiting for input from stdin.

$ socat -d TCP-LISTEN:2376,range=127.0.0.1/32,reuseaddr,fork UNIX:/var/run/docker.sock
I'm writing here, and I don't know why socat let me do this

^C$

I need to press Ctrl + C to return to the prompt. What am I doing wrong?

1

The author probably never tried it. The manual says this about the fork option:

After establishing a connection, handles its channel in a child process and keeps the parent process attempting to produce more connections, either by listening or by connecting in a loop (example).

That means socat will not fork before starting the main listen loop.

The -d option just increases verbosity (as in debug).

tl;dr: socat can’t do that.

The source tree contains this helper script to launch socat in the background. You can adapt it to your purposes. I did not write this script!

#! /bin/sh
# source: daemon.sh
# Copyright Gerhard Rieger 2001
# Published under the GNU General Public License V.2, see file COPYING

# This script assumes that you create group daemon1 and user daemon1 before.
# they need only the right to exist (no login etc.)

# Note: this pid file mechanism is not robust!

# You will adapt these variables
USER=daemon1
GROUP=daemon1
INIF=fwnonsec.domain.org
OUTIF=fwsec.domain.org
TARGET=w3.intra.domain.org
INPORT=80
DSTPORT=80
#
INOPTS="fork,setgid=$GROUP,setuid=$USER"
OUTOPTS=
PIDFILE=/var/run/socat-$INPORT.pid
OPTS="-d -d -lm"    # notice to stderr, then to syslog
SOCAT=/usr/local/bin/socat

if [ "$1" = "start" -o -z "$1" ]; then

    $SOCAT $OPTS tcp-l:$INPORT,bind=$INIF,$INOPTS tcp:$TARGET:$DSTPORT,bind=$OUTIF,$OUTOPTS </dev/null &
    echo $! >$PIDFILE

elif [ "$1" = "stop" ]; then

    /bin/kill $(/bin/cat $PIDFILE)
fi

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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