diff options
| author | Brad Fitzpatrick <bradfitz@tailscale.com> | 2025-03-27 19:31:47 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <brad@danga.com> | 2025-03-28 09:31:29 -0700 |
| commit | 4c5112eba61a6776a345fbdbcdf33f3cb7cb0883 (patch) | |
| tree | bb39e09f9cfc6a6dcb6314568a782b09a19e8012 | |
| parent | 6a9a7f35d96664110753e16b5ff6bcd29eca70ed (diff) | |
| download | tailscale-4c5112eba61a6776a345fbdbcdf33f3cb7cb0883.tar.xz tailscale-4c5112eba61a6776a345fbdbcdf33f3cb7cb0883.zip | |
cmd/tailscaled: make embedded CLI run earlier, support triggering via env
Not all platforms have hardlinks, or not easily.
This lets a "tailscale" wrapper script set an environment variable
before calling tailscaled.
Updates #2233
Change-Id: I9eccc18651e56c106f336fcbbd0fd97a661d312e
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
| -rw-r--r-- | cmd/tailscaled/tailscaled.go | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index 237cdfb55..122afe97b 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -151,10 +151,33 @@ var subCommands = map[string]*func([]string) error{ "serve-taildrive": &serveDriveFunc, } -var beCLI func() // non-nil if CLI is linked in +var beCLI func() // non-nil if CLI is linked in with the "ts_include_cli" build tag + +// shouldRunCLI reports whether we should run the Tailscale CLI (cmd/tailscale) +// instead of the daemon (cmd/tailscaled) in the case when the two are linked +// together into one binary for space savings reasons. +func shouldRunCLI() bool { + if beCLI == nil { + // Not linked in with the "ts_include_cli" build tag. + return false + } + if len(os.Args) > 0 && filepath.Base(os.Args[0]) == "tailscale" { + // The binary was named (or hardlinked) as "tailscale". + return true + } + if envknob.Bool("TS_BE_CLI") { + // The environment variable was set to force it. + return true + } + return false +} func main() { envknob.PanicIfAnyEnvCheckedInInit() + if shouldRunCLI() { + beCLI() + return + } envknob.ApplyDiskConfig() applyIntegrationTestEnvKnob() @@ -175,11 +198,6 @@ func main() { flag.BoolVar(&args.disableLogs, "no-logs-no-support", false, "disable log uploads; this also disables any technical support") flag.StringVar(&args.confFile, "config", "", "path to config file, or 'vm:user-data' to use the VM's user-data (EC2)") - if len(os.Args) > 0 && filepath.Base(os.Args[0]) == "tailscale" && beCLI != nil { - beCLI() - return - } - if len(os.Args) > 1 { sub := os.Args[1] if fp, ok := subCommands[sub]; ok { |
