From 51dd553c0669aa35b12bd9abbf8a8b8d445837dd Mon Sep 17 00:00:00 2001 From: Horus3 Date: Wed, 27 May 2015 04:32:24 +0200 Subject: add init.d script --- init.d/tcp-proxy.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 init.d/tcp-proxy.sh 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") -- cgit v1.2.3