From fda44760612aad10e556f65cd201e94ed568fbb3 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Mon, 23 Jan 2017 20:44:23 -0200 Subject: [PATCH] Fix SSH server on Windows when running as service Closes #680 --- modules/minwinsvc/svc_windows.go | 9 +++++++-- modules/setting/setting.go | 3 ++- modules/ssh/ssh.go | 6 +++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/minwinsvc/svc_windows.go b/modules/minwinsvc/svc_windows.go index 91e2b6a4d..c6e87e29d 100644 --- a/modules/minwinsvc/svc_windows.go +++ b/modules/minwinsvc/svc_windows.go @@ -8,17 +8,22 @@ package minwinsvc import ( "os" + "strconv" "sync" "golang.org/x/sys/windows/svc" ) var ( - onExit func() - guard sync.Mutex + onExit func() + guard sync.Mutex + skip, _ = strconv.ParseBool(os.Getenv("SKIP_MINWINSVC")) ) func init() { + if skip { + return + } interactive, err := svc.IsAnInteractiveSession() if err != nil { panic(err) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 910ec9302..61eac4fb3 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -22,13 +22,14 @@ import ( "code.gitea.io/git" "code.gitea.io/gitea/modules/log" + _ "code.gitea.io/gitea/modules/minwinsvc" // import minwinsvc for windows services "code.gitea.io/gitea/modules/user" + "github.com/Unknwon/com" _ "github.com/go-macaron/cache/memcache" // memcache plugin for cache _ "github.com/go-macaron/cache/redis" "github.com/go-macaron/session" _ "github.com/go-macaron/session/redis" // redis plugin for store session - _ "github.com/kardianos/minwinsvc" // import minwinsvc for windows services "gopkg.in/ini.v1" "strk.kbt.io/projects/go/libravatar" ) diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go index 056ef084e..18bac8dbf 100644 --- a/modules/ssh/ssh.go +++ b/modules/ssh/ssh.go @@ -67,7 +67,11 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) { args := []string{"serv", "key-" + keyID, "--config=" + setting.CustomConf} log.Trace("SSH: Arguments: %v", args) cmd := exec.Command(setting.AppPath, args...) - cmd.Env = append(os.Environ(), "SSH_ORIGINAL_COMMAND="+cmdName) + cmd.Env = append( + os.Environ(), + "SSH_ORIGINAL_COMMAND="+cmdName, + "SKIP_MINWINSVC=1", + ) stdout, err := cmd.StdoutPipe() if err != nil {