Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpud: add an option to sleep before serving #248

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions cmds/cpud/main_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ var (
registerAddr = flag.String("register", "", "address and port to register with after listen on cpu server port")
registerTO = flag.Duration("registerTO", time.Duration(5*time.Second), "time.Duration for Dial address for registering")

// if we start up too quickly, mDNS won't work correctly.
// This sleep may be useful for other cases, so it is here,
// not specifically for mDNS uses.
sleepBeforeServing = flag.Duration("sleepBeforeServing", 0, "add a sleep before serving -- usually only needed if cpud runs as init with mDNS")

pid1 bool
)

Expand Down Expand Up @@ -89,9 +94,10 @@ func main() {
log.Fatal(err)
}
}
pid1 = os.Getpid() == 1
pid := os.Getpid()
pid1 = pid == 1
*runAsInit = *runAsInit || pid1
verbose("Args %v pid %d *runasinit %v *remote %v env %v", os.Args, os.Getpid(), *runAsInit, *remote, os.Environ())
verbose("Args %v pid %d *runasinit %v *remote %v env %v", os.Args, pid, *runAsInit, *remote, os.Environ())
args := flag.Args()
if *remote {
verbose("args %q, port9p %v", args, *port9p)
Expand All @@ -110,12 +116,14 @@ func main() {
log.Fatalf("CPUD(remote): %v", err)
}
} else {
log.Printf("CPUD:running as a server (a.k.a. starter of cpud's for sessions)")
log.Printf("CPUD:PID(%d):running as a server (a.k.a. starter of cpud's for sessions)", pid)
if *runAsInit {
log.Printf("CPUD:also running as init")
if err := initsetup(); err != nil {
log.Fatal(err)
}
}
time.Sleep(*sleepBeforeServing)
if err := serve(os.Args[0]); err != nil {
log.Fatal(err)
}
Expand Down
Loading