mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-08 01:05:35 +00:00

This partially (but not yet fully) migrates Windows to tailscaled's StateStore storage system. This adds a new bool Pref, ForceDaemon, defined as: // ForceDaemon specifies whether a platform that normally // operates in "client mode" (that is, requires an active user // logged in with the GUI app running) should keep running after the // GUI ends and/or the user logs out. // // The only current applicable platform is Windows. This // forced Windows to go into "server mode" where Tailscale is // running even with no users logged in. This might also be // used for macOS in the future. This setting has no effect // for Linux/etc, which always operate in daemon mode. Then, when ForceDaemon becomes true, we now write use the StateStore to track which user started it in server mode, and store their prefs under that key. The ipnserver validates the connections/identities and informs that LocalBackend which userid is currently in charge. The GUI can then enable/disable server mode at runtime, without using the CLI. But the "tailscale up" CLI was also fixed, so Windows users can use authkeys or ACL tags, etc. Updates #275
67 lines
1.2 KiB
Go
67 lines
1.2 KiB
Go
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cli
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/peterbourgon/ff/v2/ffcli"
|
|
"tailscale.com/ipn"
|
|
)
|
|
|
|
var downCmd = &ffcli.Command{
|
|
Name: "down",
|
|
ShortUsage: "down",
|
|
ShortHelp: "Disconnect from Tailscale",
|
|
|
|
Exec: runDown,
|
|
}
|
|
|
|
func runDown(ctx context.Context, args []string) error {
|
|
if len(args) > 0 {
|
|
log.Fatalf("too many non-flag arguments: %q", args)
|
|
}
|
|
|
|
c, bc, ctx, cancel := connect(ctx)
|
|
defer cancel()
|
|
|
|
timer := time.AfterFunc(5*time.Second, func() {
|
|
log.Fatalf("timeout running stop")
|
|
})
|
|
defer timer.Stop()
|
|
|
|
bc.SetNotifyCallback(func(n ipn.Notify) {
|
|
if n.ErrMessage != nil {
|
|
log.Fatal(*n.ErrMessage)
|
|
}
|
|
if n.Status != nil {
|
|
cur := n.Status.BackendState
|
|
switch cur {
|
|
case "Stopped":
|
|
log.Printf("already stopped")
|
|
cancel()
|
|
default:
|
|
log.Printf("was in state %q", cur)
|
|
}
|
|
return
|
|
}
|
|
if n.State != nil {
|
|
log.Printf("now in state %q", *n.State)
|
|
if *n.State == ipn.Stopped {
|
|
cancel()
|
|
}
|
|
return
|
|
}
|
|
})
|
|
|
|
bc.RequestStatus()
|
|
bc.SetWantRunning(false)
|
|
pump(ctx, bc, c)
|
|
|
|
return nil
|
|
}
|