Skip to content

Commit c83c493

Browse files
author
Star
committed
fix workPath bug
1 parent 056e3b1 commit c83c493

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

Server.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,7 @@ func AsyncStart() *AsyncServer {
587587

588588
func Init() {
589589
inited = true
590-
if workPath != "" {
591-
_ = os.Chdir(workPath)
592-
}
590+
initStarter()
593591

594592
config.LoadConfig("service", &Config)
595593

Starter.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package s
22

33
import (
44
"fmt"
5-
"github.com/ssgo/u"
65
"os"
76
"os/exec"
87
"path"
@@ -11,6 +10,8 @@ import (
1110
"strings"
1211
"time"
1312

13+
"github.com/ssgo/u"
14+
1415
"github.com/ssgo/httpclient"
1516
)
1617

@@ -122,29 +123,31 @@ func tryStartPath(testFile string) string {
122123

123124
var shellFile = ""
124125

125-
func init() {
126+
func initStarter() {
126127
shellFile, _ = filepath.Abs(os.Args[0])
127128

128-
startPath := ""
129-
if startPath == "" && len(os.Args) > 1 && strings.ContainsRune(os.Args[1], '.') {
130-
startPath = tryStartPath(os.Args[1])
131-
}
132-
if startPath == "" && len(os.Args) > 2 && strings.ContainsRune(os.Args[2], '.') {
133-
startPath = tryStartPath(os.Args[2])
134-
}
135-
if startPath == "" {
136-
startPath = tryStartPath("env.yml")
137-
}
138-
if startPath == "" {
139-
startPath = tryStartPath("env.json")
140-
}
129+
if workPath == "" {
130+
if workPath == "" && len(os.Args) > 1 && strings.ContainsRune(os.Args[1], '.') {
131+
workPath = tryStartPath(os.Args[1])
132+
}
133+
if workPath == "" && len(os.Args) > 2 && strings.ContainsRune(os.Args[2], '.') {
134+
workPath = tryStartPath(os.Args[2])
135+
}
136+
if workPath == "" {
137+
workPath = tryStartPath("env.yml")
138+
}
139+
if workPath == "" {
140+
workPath = tryStartPath("env.json")
141+
}
141142

142-
if startPath != "" {
143-
_ = os.Chdir(startPath)
144-
} else if !strings.Contains(shellFile, "/go-build") {
145-
_ = os.Chdir(path.Dir(shellFile))
143+
if workPath == "" && !strings.Contains(shellFile, "/go-build") {
144+
workPath = path.Dir(shellFile)
145+
}
146+
}
147+
if workPath != "" {
148+
_ = os.Chdir(workPath)
146149
}
147-
serviceInfo = serviceInfoType{pidFile: filepath.Join(startPath, ".pid")}
150+
serviceInfo = serviceInfoType{pidFile: filepath.Join(workPath, ".pid")}
148151
serviceInfo.load()
149152

150153
//if len(os.Args) > 1 {

0 commit comments

Comments
 (0)