This commit is contained in:
Liang Ding 2022-10-25 10:06:15 +08:00
parent fc4db17217
commit a20a19182b
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 7 additions and 76 deletions

View file

@ -34,7 +34,6 @@ var (
)
const (
ServerPort = "0" // HTTP/WebSocket 端口
AliyunServer = "https://siyuan-sync.b3logfile.com" // 云端服务地址,阿里云负载均衡,用于接口,数据同步文件上传、下载会走七牛云 OSS http://siyuan-data.b3logfile.com
BazaarStatServer = "http://bazaar.b3logfile.com" // 集市包统计服务地址,直接对接 Bucket 没有 CDN 缓存
BazaarOSSServer = "https://oss.b3logfile.com" // 云端对象存储地址,七牛云,仅用于读取集市包

View file

@ -24,7 +24,6 @@ import (
"github.com/88250/gulu"
"github.com/gin-gonic/gin"
"github.com/olahol/melody"
"github.com/siyuan-note/logging"
)
func GetRemoteAddr(session *melody.Session) string {
@ -64,22 +63,3 @@ func isPortOpen(port string) bool {
}
return false
}
func tryToListenPort() bool {
listener, err := net.Listen("tcp", "127.0.0.1:"+ServerPort)
if nil != err {
time.Sleep(time.Second * 3)
listener, err = net.Listen("tcp", "127.0.0.1:"+ServerPort)
if nil != err {
logging.LogErrorf("try to listen port [%s] failed: %s", ServerPort, err)
return false
}
}
if err = listener.Close(); nil != err {
time.Sleep(time.Second * 1)
if err = listener.Close(); nil != err {
logging.LogErrorf("close listen port [%s] failed: %s", ServerPort, err)
}
}
return true
}

View file

@ -60,6 +60,7 @@ func Boot() {
wdPath := flag.String("wd", WorkingDir, "working directory of SiYuan")
servePath := flag.String("servePath", "", "obsoleted https://github.com/siyuan-note/siyuan/issues/4647")
_ = servePath
port := flag.String("port", "0", "port of the HTTP server")
resident := flag.Bool("resident", true, "resident memory even if no active session")
readOnly := flag.Bool("readonly", false, "read-only mode")
accessAuthCode := flag.String("accessAuthCode", "", "access auth code")
@ -76,6 +77,10 @@ func Boot() {
}
Mode = *mode
Resident = *resident
ServerPort = *port
if isRunningInDockerContainer() {
ServerPort = "6806"
}
ReadOnly = *readOnly
AccessAuthCode = *accessAuthCode
Container = ContainerStd
@ -104,7 +109,6 @@ func Boot() {
}
initPathDir()
checkPort()
go initPandoc()
bootBanner := figure.NewColorFigure("SiYuan", "isometric3", "green", true)
@ -272,6 +276,7 @@ func initWorkspaceDir(workspaceArg string) {
}
var (
ServerPort = "0" // HTTP/WebSocket 端口0 为使用随机端口
Resident bool
ReadOnly bool
AccessAuthCode string
@ -320,60 +325,6 @@ func initPathDir() {
}
}
func checkPort() {
portOpened := isPortOpen(ServerPort)
if !portOpened {
return
}
logging.LogInfof("port [%s] is opened, try to check version of running kernel", ServerPort)
result := NewResult()
_, err := httpclient.NewBrowserRequest().
SetResult(result).
SetHeader("User-Agent", UserAgent).
Get("http://127.0.0.1:" + ServerPort + "/api/system/version")
if nil != err || 0 != result.Code {
logging.LogErrorf("connect to port [%s] for checking running kernel failed", ServerPort)
KillByPort(ServerPort)
return
}
if nil == result.Data {
logging.LogErrorf("connect ot port [%s] for checking running kernel failed", ServerPort)
os.Exit(ExitCodeUnavailablePort)
}
runningVer := result.Data.(string)
if runningVer == Ver {
logging.LogInfof("version of the running kernel is the same as this boot [%s], exit this boot", runningVer)
os.Exit(ExitCodeOk)
}
logging.LogInfof("found kernel [%s] is running, try to exit it", runningVer)
processes, err := goPS.Processes()
if nil != err {
logging.LogErrorf("close kernel [%s] failed: %s", runningVer, err)
os.Exit(ExitCodeUnavailablePort)
}
currentPid := os.Getpid()
for _, p := range processes {
name := p.Executable()
if strings.Contains(strings.ToLower(name), "siyuan-kernel") || strings.Contains(strings.ToLower(name), "siyuan kernel") {
kernelPid := p.Pid()
if currentPid != kernelPid {
pid := strconv.Itoa(kernelPid)
Kill(pid)
logging.LogInfof("killed kernel [name=%s, pid=%s, ver=%s], continue to boot", name, pid, runningVer)
}
}
}
if !tryToListenPort() {
os.Exit(ExitCodeUnavailablePort)
}
}
func initMime() {
// 在某版本的 Windows 10 操作系统上界面样式异常问题
// https://github.com/siyuan-note/siyuan/issues/247

View file

@ -61,6 +61,7 @@ func BootMobile(container, appDir, workspaceDir, nativeLibDir, privateDataDir, l
ThemesPath = filepath.Join(AppearancePath, "themes")
IconsPath = filepath.Join(AppearancePath, "icons")
Resident = true
ServerPort = "6806"
Container = container
UserAgent = UserAgent + " " + Container
httpclient.SetUserAgent(UserAgent)