summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus32015-05-27 04:32:24 +0200
committerHorus32015-05-27 04:32:24 +0200
commit51dd553c0669aa35b12bd9abbf8a8b8d445837dd (patch)
tree4b0daac27b6650991a81f2d9e3e1386a88bc138d
parent3b8ad8daaebee435b482bcd7867a22a51f29ead0 (diff)
downloadgo-tcp-proxy-master.tar.gz
add init.d scriptHEADmaster
-rwxr-xr-xinit.d/tcp-proxy.sh52
-rw-r--r--main.go2
2 files changed, 53 insertions, 1 deletions
diff --git a/init.d/tcp-proxy.sh b/init.d/tcp-proxy.sh
new file mode 100755
index 0000000..d3326f4
--- /dev/null
+++ b/init.d/tcp-proxy.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+
+### BEGIN INIT INFO
+# Provides: go-tcp-proxy
+# Required-Start: $local_fs $network
+# Required-Stop: $local_fs
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Starts proxy to access mariadb from kvm guests.
+# Description: Starts proxy to access mariadb from kvm guests.
+### END INIT INFO
+
+NAME="go-tcp-proxy"
+PIDFILE="/var/run/${NAME}.pid"
+DAEMON="/usr/local/bin/go-tcp-proxy"
+START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --chuid nobody --exec $DAEMON -- -l -r"
+END_OPTS="--stop --pidfile ${PIDFILE}"
+
+case "$1" in
+ start)
+ echo "Starting $DAEMON"
+ start-stop-daemon $START_OPTS
+
+ ;;
+ stop)
+ echo "Stopping $NAME"
+ start-stop-daemon $END_OPTS
+ rm -f "${PIDFILE}"
+
+ ;;
+ restart)
+ echo "Restarting $NAME"
+ "$0" stop
+ sleep 1
+ "$0" start
+
+ ;;
+ status)
+ if cat $PIDFILE 1>/dev/null 2>/dev/null; then
+ echo "$NAME is running."
+ else
+ echo "$NAME does not run."
+ fi
+
+ ;;
+ *)
+ echo "Usage: /etc/init.d/tcp-proxy.sh {start|stop|restart|status}"
+ exit 1
+ ;;
+esac
+
+exit 0
diff --git a/main.go b/main.go
index 5ce452d..378ef8c 100644
--- a/main.go
+++ b/main.go
@@ -10,7 +10,7 @@ import (
func main() {
- localAddr := flag.String("l", "192.168.122.110:3306", "local address we listen on")
+ localAddr := flag.String("l", "192.168.122.1:3306", "local address we listen on")
remoteAddr := flag.String("r", "127.0.0.1:3306", "remote address we proxy to")
verbose := flag.Bool("v", false, "log connection")