Skip to content

Fix SSH server on Windows when running as service #736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a zlib-style
// license that can be found in the LICENSE file.package service

// Minimal non-invasive windows only service stub.
// Package minwinsvc is a minimal non-invasive windows only service stub.
//
// Import to allow running as a windows service.
// import _ "github.com/kardianos/minwinsvc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
6 changes: 5 additions & 1 deletion modules/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,6 @@
"revision": "b2c7a7da5b2995941048f60146e67702a292e468",
"revisionTime": "2016-02-12T04:00:40Z"
},
{
"checksumSHA1": "/dBJ2h8Jo359deiC5GQ8ZYzX8M8=",
"path": "github.com/kardianos/minwinsvc",
"revision": "cad6b2b879b0970e4245a20ebf1a81a756e2bb70",
"revisionTime": "2015-11-22T16:33:09Z"
},
{
"checksumSHA1": "fh+CcgeUUsnuwSORHYWg0ycbp+4=",
"path": "github.com/klauspost/compress/flate",
Expand Down