Skip to content

Commit 6562f4c

Browse files
joneskoobradfitz
authored andcommitted
cmd/tailscale: allow use of flags in gokrazy
Enable use of command line arguments with tailscale cli on gokrazy. Before this change using arguments like "up" would cause tailscale cli to be repeatedly restarted by gokrazy process supervisor. We never want to have gokrazy restart tailscale cli, even if user would manually start the process. Expected usage is that user creates files: flags/tailscale.com/cmd/tailscale/flags.txt: up flags/tailscale.com/cmd/tailscaled/flags.txt: --statedir=/perm/tailscaled/ --tun=userspace-networking Then tailscale prints URL for user to log in with browser. Alternatively it should be possible to use up with auth key to allow unattended gokrazy installs. Signed-off-by: Joonas Kuorilehto <joneskoo@derbian.fi> (cherry picked from commit c1b3500)
1 parent 9fd9abf commit 6562f4c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

cmd/tailscale/cli/cli.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,21 @@ func CleanUpArgs(args []string) []string {
125125
}
126126

127127
// Run runs the CLI. The args do not include the binary name.
128-
func Run(args []string) error {
128+
func Run(args []string) (err error) {
129129
if len(args) == 1 && (args[0] == "-V" || args[0] == "--version") {
130130
args = []string{"version"}
131131
}
132-
if runtime.GOOS == "linux" && distro.Get() == distro.Gokrazy && len(args) == 0 &&
132+
if runtime.GOOS == "linux" && distro.Get() == distro.Gokrazy &&
133133
os.Getenv("GOKRAZY_FIRST_START") == "1" {
134-
// Exit with 125 otherwise the CLI binary is restarted
135-
// forever in a loop by the Gokrazy process supervisor.
136-
// See https://gokrazy.org/userguide/process-interface/
137-
os.Exit(125)
134+
defer func() {
135+
// Exit with 125 otherwise the CLI binary is restarted
136+
// forever in a loop by the Gokrazy process supervisor.
137+
// See https://gokrazy.org/userguide/process-interface/
138+
if err != nil {
139+
log.Println(err)
140+
}
141+
os.Exit(125)
142+
}()
138143
}
139144

140145
var warnOnce sync.Once
@@ -201,7 +206,7 @@ change in the future.
201206
}
202207
})
203208

204-
err := rootCmd.Run(context.Background())
209+
err = rootCmd.Run(context.Background())
205210
if tailscale.IsAccessDeniedError(err) && os.Getuid() != 0 && runtime.GOOS != "windows" {
206211
return fmt.Errorf("%v\n\nUse 'sudo tailscale %s' or 'tailscale up --operator=$USER' to not require root.", err, strings.Join(args, " "))
207212
}

0 commit comments

Comments
 (0)