envknob: generalize Windows tailscaled-env.txt support

ipnserver previously had support for a Windows-only environment
variable mechanism that further only worked when Windows was running
as a service, not from a console.

But we want it to work from tailscaed too, and we want it to work on
macOS and Synology. So move it to envknob, now that envknob can change
values at runtime post-init.

A future change will wire this up for more platforms, and do something
more for CLI flags like --port, which the bug was originally about.

Updates #5114

Change-Id: I9fd69a9a91bb0f308fc264d4a6c33e0cbe352d71
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2022-09-15 21:47:31 -07:00
committed by Brad Fitzpatrick
parent 4bda41e701
commit 65c24b6334
5 changed files with 88 additions and 43 deletions

View File

@@ -131,8 +131,12 @@ var subCommands = map[string]*func([]string) error{
var beCLI func() // non-nil if CLI is linked in
var diskConfigErr error
func main() {
envknob.PanicIfAnyEnvCheckedInInit()
diskConfigErr = envknob.ApplyDiskConfig()
printVersion := false
flag.IntVar(&args.verbose, "verbose", 0, "log verbosity level; 0 is default, 1 or higher are increasingly verbose")
flag.BoolVar(&args.cleanup, "cleanup", false, "clean up system state and exit")
@@ -309,6 +313,10 @@ func run() error {
pol.Shutdown(ctx)
}()
if diskConfigErr != nil {
log.Printf("Error reading environment config: %v", diskConfigErr)
}
if isWindowsService() {
// Run the IPN server from the Windows service manager.
log.Printf("Running service...")

View File

@@ -197,6 +197,9 @@ func beWindowsSubprocess() bool {
log.Printf("Program starting: v%v: %#v", version.Long, os.Args)
log.Printf("subproc mode: logid=%v", logid)
if diskConfigErr != nil {
log.Printf("Error reading environment config: %v", diskConfigErr)
}
go func() {
b := make([]byte, 16)