diff --git a/code/client/app/app.go b/code/client/app/app.go index 4f2e47f..d827254 100644 --- a/code/client/app/app.go +++ b/code/client/app/app.go @@ -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 diff --git a/code/client/app/callback.go b/code/client/app/callback.go index a451647..8fc2f18 100644 --- a/code/client/app/callback.go +++ b/code/client/app/callback.go @@ -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()) diff --git a/code/client/global/conf.go b/code/client/global/conf.go index 1e16df8..9e08933 100644 --- a/code/client/global/conf.go +++ b/code/client/global/conf.go @@ -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, } } diff --git a/code/client/main.go b/code/client/main.go index 059d3f0..caffffc 100644 --- a/code/client/main.go +++ b/code/client/main.go @@ -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: diff --git a/code/client/rule/code/h_forward_websocket.go b/code/client/rule/code/h_forward_websocket.go index 46867dd..6f0a534 100644 --- a/code/client/rule/code/h_forward_websocket.go +++ b/code/client/rule/code/h_forward_websocket.go @@ -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) diff --git a/code/client/rule/code/workspace.go b/code/client/rule/code/workspace.go index e91768a..4602f12 100644 --- a/code/client/rule/code/workspace.go +++ b/code/client/rule/code/workspace.go @@ -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) diff --git a/conf/common.yaml b/conf/common.yaml index b8c5d6e..f93c3d3 100644 --- a/conf/common.yaml +++ b/conf/common.yaml @@ -6,4 +6,4 @@ log: dir: ./logs # 路径,相对于可执行文件所在目录的相对路径 size: 50M # 单个文件大小 rotate: 7 # 保留数量 -tmpdir: ./tmp # 临时文件路径 \ No newline at end of file +codedir: ./code # code-server配置保存路径 \ No newline at end of file