1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.arvados.org/arvados.git/lib/cmd"
14 "git.arvados.org/arvados.git/lib/config"
15 "git.arvados.org/arvados.git/sdk/go/ctxlog"
18 var Command cmd.Handler = bootCommand{}
20 type supervisedTask interface {
21 // Execute the task. Run should return nil when the task is
22 // done enough to satisfy a dependency relationship (e.g., the
23 // service is running and ready). If the task starts a
24 // goroutine that fails after Run returns (e.g., the service
25 // shuts down), it should call fail().
26 Run(ctx context.Context, fail func(error), super *Supervisor) error
30 type bootCommand struct{}
32 func (bootCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
35 logger: ctxlog.New(stderr, "json", "info"),
38 ctx := ctxlog.Context(context.Background(), super.logger)
39 ctx, cancel := context.WithCancel(ctx)
45 super.logger.WithError(err).Info("exiting")
49 flags := flag.NewFlagSet(prog, flag.ContinueOnError)
50 flags.SetOutput(stderr)
51 loader := config.NewLoader(stdin, super.logger)
52 loader.SetupFlags(flags)
53 versionFlag := flags.Bool("version", false, "Write version information to stdout and exit 0")
54 flags.StringVar(&super.SourcePath, "source", ".", "arvados source tree `directory`")
55 flags.StringVar(&super.ClusterType, "type", "production", "cluster `type`: development, test, or production")
56 flags.StringVar(&super.ListenHost, "listen-host", "localhost", "host name or interface address for service listeners")
57 flags.StringVar(&super.ControllerAddr, "controller-address", ":0", "desired controller address, `host:port` or `:port`")
58 flags.BoolVar(&super.OwnTemporaryDatabase, "own-temporary-database", false, "bring up a postgres server and create a temporary database")
59 err = flags.Parse(args)
60 if err == flag.ErrHelp {
63 } else if err != nil {
65 } else if *versionFlag {
66 return cmd.Version.RunCommand(prog, args, stdin, stdout, stderr)
67 } else if super.ClusterType != "development" && super.ClusterType != "test" && super.ClusterType != "production" {
68 err = fmt.Errorf("cluster type must be 'development', 'test', or 'production'")
72 loader.SkipAPICalls = true
73 cfg, err := loader.Load()
80 url, ok := super.WaitReady()
84 // Write controller URL to stdout. Nothing else goes to
85 // stdout, so this provides an easy way for a calling script
86 // to discover the controller URL when everything is ready.
87 fmt.Fprintln(stdout, url)
88 // Wait for signal/crash + orderly shutdown