From d28a4af924660c39b32596208149c03e36d17ca8 Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Tue, 13 Nov 2018 23:59:34 -0800 Subject: [PATCH] Added example openrc init script Signed-off-by: Russ Magee --- hkexsh/hkexsh.go | 6 +++++- hkexshd.initrc | 39 +++++++++++++++++++++++++++++++++++++++ hkexshd/hkexshd.go | 2 +- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100755 hkexshd.initrc diff --git a/hkexsh/hkexsh.go b/hkexsh/hkexsh.go index 96fa048..0ee7c9d 100755 --- a/hkexsh/hkexsh.go +++ b/hkexsh/hkexsh.go @@ -358,8 +358,12 @@ func parseNonSwitchArgs(a []string) (user, host, path string, isDest bool, other func launchTuns(conn *hkexnet.Conn, remoteHost string, tuns string) { remAddrs, _ := net.LookupHost(remoteHost) + if tuns == "" { + return + } + tunSpecs := strings.Split(tuns, ",") - for _,tunItem := range tunSpecs { + for _, tunItem := range tunSpecs { var lPort, rPort uint16 _, _ = fmt.Sscanf(tunItem, "%d:%d", &lPort, &rPort) reqTunnel(conn, lPort, remAddrs[0], rPort) diff --git a/hkexshd.initrc b/hkexshd.initrc new file mode 100755 index 0000000..80b8bed --- /dev/null +++ b/hkexshd.initrc @@ -0,0 +1,39 @@ +#!/sbin/openrc-run + +SVCNAME=hkexshd +HKEXSHD_PIDFILE=/var/run/hkexshd.pid +HKEXSHD_USER=root +HKEXSHD_HOME=/var/run +INST_PREFIX=/usr/local +COMMAND=$INST_PREFIX/sbin/hkexshd +ARGS="" + +depend() { + need net + use dns logger +} + +checkconfig() { + if [ ! -f "$COMMAND" ] ; then + eerror "$COMMAND not installed" || return 1 + fi + return 0 +} + +start() { + checkconfig || return 1 + + ebegin "Starting ${SVCNAME}" + start-stop-daemon \ + -d ${HKEXSHD_HOME} \ + --make-pidfile --pidfile ${HKEXSHD_PIDFILE} \ + --start --quiet --background \ + --exec "${COMMAND}" "${ARGS}" + eend $? +} + +stop() { + ebegin "Stopping ${SVCNAME}" + start-stop-daemon --stop --quiet --pidfile $HKEXSHD_PIDFILE + eend $? +} diff --git a/hkexshd/hkexshd.go b/hkexshd/hkexshd.go index 0337919..8cb10f2 100755 --- a/hkexshd/hkexshd.go +++ b/hkexshd/hkexshd.go @@ -26,9 +26,9 @@ import ( "syscall" "blitter.com/go/goutmp" - "blitter.com/go/hkexsh/logger" hkexsh "blitter.com/go/hkexsh" "blitter.com/go/hkexsh/hkexnet" + "blitter.com/go/hkexsh/logger" "github.com/kr/pty" )