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)
| 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 |
| 252 | func (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() { |
no test coverage detected