Skip to content

Instantly share code, notes, and snippets.

@mayli
Created July 15, 2016 00:43
Show Gist options
  • Save mayli/c6b23439142f4ad3ed0d3d4c67516242 to your computer and use it in GitHub Desktop.
Save mayli/c6b23439142f4ad3ed0d3d4c67516242 to your computer and use it in GitHub Desktop.
/etc/init.d/socat
#!/bin/bash
### BEGIN INIT INFO
# Provides: socat
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: socat service
### END INIT INFO
USER=nobody
GROUP=nogroup
TARGET=10.0.0.29
INPORT=22
DSTPORT=22
PIDFILE=/var/run/socat-$INPORT.pid
LOGFILE=/var/log/socat-$INPORT.log
SOCAT=/usr/bin/socat
start() {
$SOCAT TCP4-LISTEN:$INPORT,fork,reuseaddr TCP4:$TARGET:$DSTPORT </dev/null > $LOGFILE &
echo $! >$PIDFILE
}
stop() {
/bin/kill $(/bin/cat $PIDFILE)
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Use this options $0 {start|stop|restart}"
exit 1
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment