Skip to content

Commit fda4476

Browse files
committed
Fix SSH server on Windows when running as service
Closes #680
1 parent 44d4863 commit fda4476

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

modules/minwinsvc/svc_windows.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ package minwinsvc
88

99
import (
1010
"os"
11+
"strconv"
1112
"sync"
1213

1314
"golang.org/x/sys/windows/svc"
1415
)
1516

1617
var (
17-
onExit func()
18-
guard sync.Mutex
18+
onExit func()
19+
guard sync.Mutex
20+
skip, _ = strconv.ParseBool(os.Getenv("SKIP_MINWINSVC"))
1921
)
2022

2123
func init() {
24+
if skip {
25+
return
26+
}
2227
interactive, err := svc.IsAnInteractiveSession()
2328
if err != nil {
2429
panic(err)

modules/setting/setting.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ import (
2222

2323
"code.gitea.io/git"
2424
"code.gitea.io/gitea/modules/log"
25+
_ "code.gitea.io/gitea/modules/minwinsvc" // import minwinsvc for windows services
2526
"code.gitea.io/gitea/modules/user"
27+
2628
"github.com/Unknwon/com"
2729
_ "github.com/go-macaron/cache/memcache" // memcache plugin for cache
2830
_ "github.com/go-macaron/cache/redis"
2931
"github.com/go-macaron/session"
3032
_ "github.com/go-macaron/session/redis" // redis plugin for store session
31-
_ "github.com/kardianos/minwinsvc" // import minwinsvc for windows services
3233
"gopkg.in/ini.v1"
3334
"strk.kbt.io/projects/go/libravatar"
3435
)

modules/ssh/ssh.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) {
6767
args := []string{"serv", "key-" + keyID, "--config=" + setting.CustomConf}
6868
log.Trace("SSH: Arguments: %v", args)
6969
cmd := exec.Command(setting.AppPath, args...)
70-
cmd.Env = append(os.Environ(), "SSH_ORIGINAL_COMMAND="+cmdName)
70+
cmd.Env = append(
71+
os.Environ(),
72+
"SSH_ORIGINAL_COMMAND="+cmdName,
73+
"SKIP_MINWINSVC=1",
74+
)
7175

7276
stdout, err := cmd.StdoutPipe()
7377
if err != nil {

0 commit comments

Comments
 (0)