mirror of
https://github.com/lwch/natpass
synced 2025-09-27 01:55:53 +08:00
1. 修正重启时code-server配置丢失问题
2. 修正code-server的websocket连接断开时无法重连的问题
This commit is contained in:
@@ -2,7 +2,6 @@ package app
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
rt "runtime"
|
||||
|
||||
"github.com/kardianos/service"
|
||||
@@ -43,21 +42,11 @@ func (a *App) Stop(s service.Service) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) clean() {
|
||||
files, err := filepath.Glob(filepath.Join(a.cfg.TmpDir, "*"))
|
||||
runtime.Assert(err)
|
||||
for _, file := range files {
|
||||
os.RemoveAll(file)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) run() {
|
||||
// go func() {
|
||||
// http.ListenAndServe(":9000", nil)
|
||||
// }()
|
||||
|
||||
a.clean()
|
||||
|
||||
stdout := true
|
||||
if rt.GOOS == "windows" {
|
||||
stdout = false
|
||||
|
@@ -88,7 +88,7 @@ func (a *App) codeCreate(confDir string, mgr *rule.Mgr, conn *conn.Conn, msg *ne
|
||||
logging.Info("create link %s for code-server rule [%s] from %s to %s",
|
||||
msg.GetLinkId(), create.GetName(),
|
||||
msg.GetFrom(), a.cfg.ID)
|
||||
err := workspace.Exec(a.cfg.TmpDir)
|
||||
err := workspace.Exec(a.cfg.CodeDir)
|
||||
if err != nil {
|
||||
logging.Error("create vnc failed: %v", err)
|
||||
conn.SendConnectError(msg.GetFrom(), msg.GetLinkId(), err.Error())
|
||||
|
@@ -42,7 +42,7 @@ type Configure struct {
|
||||
DashboardListen string
|
||||
DashboardPort uint16
|
||||
Rules []Rule
|
||||
TmpDir string
|
||||
CodeDir string
|
||||
}
|
||||
|
||||
// LoadConf load configure file
|
||||
@@ -66,8 +66,8 @@ func LoadConf(dir string) *Configure {
|
||||
Listen string `yaml:"listen"`
|
||||
Port uint16 `yaml:"port"`
|
||||
} `yaml:"dashboard"`
|
||||
Rules []Rule `yaml:"rules"`
|
||||
TmpDir string `yaml:"tmpdir"`
|
||||
Rules []Rule `yaml:"rules"`
|
||||
CodeDir string `yaml:"codedir"`
|
||||
}
|
||||
runtime.Assert(yaml.Decode(dir, &cfg))
|
||||
for i, t := range cfg.Rules {
|
||||
@@ -89,10 +89,10 @@ func LoadConf(dir string) *Configure {
|
||||
runtime.Assert(err)
|
||||
cfg.Log.Dir = filepath.Join(filepath.Dir(dir), cfg.Log.Dir)
|
||||
}
|
||||
if !filepath.IsAbs(cfg.TmpDir) {
|
||||
if !filepath.IsAbs(cfg.CodeDir) {
|
||||
dir, err := os.Executable()
|
||||
runtime.Assert(err)
|
||||
cfg.TmpDir = filepath.Join(filepath.Dir(dir), cfg.TmpDir)
|
||||
cfg.CodeDir = filepath.Join(filepath.Dir(dir), cfg.CodeDir)
|
||||
}
|
||||
return &Configure{
|
||||
ID: cfg.ID,
|
||||
@@ -108,6 +108,6 @@ func LoadConf(dir string) *Configure {
|
||||
DashboardListen: cfg.Dashboard.Listen,
|
||||
DashboardPort: cfg.Dashboard.Port,
|
||||
Rules: cfg.Rules,
|
||||
TmpDir: cfg.TmpDir,
|
||||
CodeDir: cfg.CodeDir,
|
||||
}
|
||||
}
|
||||
|
@@ -105,7 +105,7 @@ func main() {
|
||||
case "install":
|
||||
runtime.Assert(sv.Install())
|
||||
utils.BuildDir(cfg.LogDir, *user)
|
||||
utils.BuildDir(cfg.TmpDir, *user)
|
||||
utils.BuildDir(cfg.CodeDir, *user)
|
||||
case "uninstall":
|
||||
runtime.Assert(sv.Uninstall())
|
||||
default:
|
||||
|
@@ -14,7 +14,6 @@ var upgrader = websocket.Upgrader{
|
||||
}
|
||||
|
||||
func (code *Code) handleWebsocket(workspace *Workspace, w http.ResponseWriter, r *http.Request) {
|
||||
defer workspace.Close(true)
|
||||
reqID, err := workspace.SendConnect(r)
|
||||
if err != nil {
|
||||
logging.Error("send_connect: %v", err)
|
||||
|
@@ -81,11 +81,13 @@ func (ws *Workspace) Exec(dir string) error {
|
||||
return err
|
||||
}
|
||||
sockDir := filepath.Join(workdir, ws.id+".sock")
|
||||
ws.exec = exec.Command("code-server", "--disable-update-check",
|
||||
ws.exec = exec.Command("code-server",
|
||||
"--auth", "none",
|
||||
"--socket", sockDir,
|
||||
"--user-data-dir", filepath.Join(workdir, "data"),
|
||||
"--extensions-dir", filepath.Join(workdir, "extensions"))
|
||||
"--extensions-dir", filepath.Join(workdir, "extensions"),
|
||||
"--config", filepath.Join(workdir, "conf"))
|
||||
ws.exec.Env = os.Environ()
|
||||
stdout, err := ws.exec.StdoutPipe()
|
||||
if err != nil {
|
||||
logging.Error("can not get stdout pipe for link [%s] name [%s]", ws.id, ws.name)
|
||||
|
@@ -6,4 +6,4 @@ log:
|
||||
dir: ./logs # 路径,相对于可执行文件所在目录的相对路径
|
||||
size: 50M # 单个文件大小
|
||||
rotate: 7 # 保留数量
|
||||
tmpdir: ./tmp # 临时文件路径
|
||||
codedir: ./code # code-server配置保存路径
|
Reference in New Issue
Block a user