MCPcopy
hub / github.com/wavetermdev/waveterm / StartConnServer

Method StartConnServer

pkg/wslconn/wslconn.go:252–349  ·  view source on GitHub ↗

returns (needsInstall, clientVersion, osArchStr, error) if wsh is not installed, the clientVersion will be "not-installed", and it will also return an osArchStr if clientVersion is set, then no osArchStr will be returned

(ctx context.Context, afterUpdate bool)

Source from the content-addressed store, hash-verified

250// if wsh is not installed, the clientVersion will be "not-installed", and it will also return an osArchStr
251// if clientVersion is set, then no osArchStr will be returned
252func (conn *WslConn) StartConnServer(ctx context.Context, afterUpdate bool) (bool, string, string, error) {
253 conn.Infof(ctx, "running StartConnServer...\n")
254 allowed := WithLockRtn(conn, func() bool {
255 return conn.Status == Status_Connecting
256 })
257 if !allowed {
258 return false, "", "", fmt.Errorf("cannot start conn server for %q when status is %q", conn.GetName(), conn.GetStatus())
259 }
260 client := conn.GetClient()
261 wshPath := conn.getWshPath()
262 conn.Infof(ctx, "WSL-NEWSESSION (StartConnServer)\n")
263 connServerCtx, cancelFn := context.WithCancel(context.Background())
264 conn.WithLock(func() {
265 if conn.cancelFn != nil {
266 conn.cancelFn()
267 }
268 conn.cancelFn = cancelFn
269 })
270 devFlag := ""
271 if wavebase.IsDevMode() {
272 devFlag = "--dev"
273 }
274 cmdStr := fmt.Sprintf(ConnServerCmdTemplate, wshPath, wshPath, shellutil.HardQuote(conn.GetName()), devFlag)
275 shWrappedCmdStr := fmt.Sprintf("sh -c %s", shellutil.HardQuote(cmdStr))
276 cmd := client.WslCommand(connServerCtx, shWrappedCmdStr)
277 pipeRead, pipeWrite := io.Pipe()
278 inputPipeRead, inputPipeWrite := io.Pipe()
279 cmd.SetStdout(pipeWrite)
280 cmd.SetStderr(pipeWrite)
281 cmd.SetStdin(inputPipeRead)
282 log.Printf("starting conn controller: %q\n", cmdStr)
283 blocklogger.Debugf(ctx, "[conndebug] wrapped command:\n%s\n", shWrappedCmdStr)
284 err := cmd.Start()
285 if err != nil {
286 return false, "", "", fmt.Errorf("unable to start conn controller cmd: %w", err)
287 }
288 linesChan := utilfn.StreamToLinesChan(pipeRead)
289 versionLine, err := utilfn.ReadLineWithTimeout(linesChan, 30*time.Second)
290 if err != nil {
291 cancelFn()
292 return false, "", "", fmt.Errorf("error reading wsh version: %w", err)
293 }
294 conn.Infof(ctx, "got connserver version: %s\n", strings.TrimSpace(versionLine))
295 isUpToDate, clientVersion, osArchStr, err := conncontroller.IsWshVersionUpToDate(ctx, versionLine)
296 if err != nil {
297 cancelFn()
298 return false, "", "", fmt.Errorf("error checking wsh version: %w", err)
299 }
300 if isUpToDate && !afterUpdate && os.Getenv(wavebase.WaveWshForceUpdateVarName) != "" {
301 isUpToDate = false
302 conn.Infof(ctx, "%s set, forcing wsh update\n", wavebase.WaveWshForceUpdateVarName)
303 }
304 conn.Infof(ctx, "connserver up-to-date: %v\n", isUpToDate)
305 if !isUpToDate {
306 cancelFn()
307 return true, clientVersion, osArchStr, nil
308 }
309 conn.WithLock(func() {

Callers 1

tryEnableWshMethod · 0.95

Calls 15

InfofMethod · 0.95
GetNameMethod · 0.95
GetStatusMethod · 0.95
GetClientMethod · 0.95
getWshPathMethod · 0.95
WithLockMethod · 0.95
IsDevModeFunction · 0.92
HardQuoteFunction · 0.92
DebugfFunction · 0.92
StreamToLinesChanFunction · 0.92
ReadLineWithTimeoutFunction · 0.92
IsWshVersionUpToDateFunction · 0.92

Tested by

no test coverage detected