1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.arvados.org/arvados.git/lib/cmd"
16 "git.arvados.org/arvados.git/sdk/go/ctxlog"
19 var Command cmd.Handler = bootCommand{}
21 type supervisedTask interface {
22 // Execute the task. Run should return nil when the task is
23 // done enough to satisfy a dependency relationship (e.g., the
24 // service is running and ready). If the task starts a
25 // goroutine that fails after Run returns (e.g., the service
26 // shuts down), it should call fail().
27 Run(ctx context.Context, fail func(error), super *Supervisor) error
31 var errNeedConfigReload = errors.New("config changed, restart needed")
32 var errParseFlags = errors.New("error parsing command line arguments")
34 type bootCommand struct{}
36 func (bcmd bootCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
37 logger := ctxlog.New(stderr, "json", "info")
38 ctx := ctxlog.Context(context.Background(), logger)
40 err := bcmd.run(ctx, prog, args, stdin, stdout, stderr)
41 if err == errNeedConfigReload {
43 } else if err == errParseFlags {
45 } else if err != nil {
46 logger.WithError(err).Info("exiting")
54 func (bcmd bootCommand) run(ctx context.Context, prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) error {
55 ctx, cancel := context.WithCancel(ctx)
60 logger: ctxlog.FromContext(ctx),
63 flags := flag.NewFlagSet(prog, flag.ContinueOnError)
64 versionFlag := flags.Bool("version", false, "Write version information to stdout and exit 0")
65 flags.StringVar(&super.ConfigPath, "config", "/etc/arvados/config.yml", "arvados config file `path`")
66 flags.StringVar(&super.SourcePath, "source", ".", "arvados source tree `directory`")
67 flags.StringVar(&super.ClusterType, "type", "production", "cluster `type`: development, test, or production")
68 flags.StringVar(&super.ListenHost, "listen-host", "localhost", "host name or interface address for external services, and internal services whose InternalURLs are not configured")
69 flags.StringVar(&super.ControllerAddr, "controller-address", ":0", "desired controller address, `host:port` or `:port`")
70 flags.StringVar(&super.Workbench2Source, "workbench2-source", "../arvados-workbench2", "path to arvados-workbench2 source tree")
71 flags.BoolVar(&super.NoWorkbench1, "no-workbench1", false, "do not run workbench1")
72 flags.BoolVar(&super.NoWorkbench2, "no-workbench2", true, "do not run workbench2")
73 flags.BoolVar(&super.OwnTemporaryDatabase, "own-temporary-database", false, "bring up a postgres server and create a temporary database")
74 timeout := flags.Duration("timeout", 0, "maximum time to wait for cluster to be ready")
75 shutdown := flags.Bool("shutdown", false, "shut down when the cluster becomes ready")
76 if ok, code := cmd.ParseFlags(flags, prog, args, "", stderr); !ok {
82 } else if *versionFlag {
83 cmd.Version.RunCommand(prog, args, stdin, stdout, stderr)
85 } else if super.ClusterType != "development" && super.ClusterType != "test" && super.ClusterType != "production" {
86 return fmt.Errorf("cluster type must be 'development', 'test', or 'production'")
94 timer = time.AfterFunc(*timeout, super.Stop)
97 ok := super.WaitReady()
98 if timer != nil && !timer.Stop() {
99 return errors.New("boot timed out")
101 super.logger.Error("boot failed")
103 // Write each cluster's controller URL to stdout.
104 // Nothing else goes to stdout, so this allows a
105 // calling script to determine when the cluster is
106 // ready to use, and the controller's host:port (which
107 // may have been dynamically assigned depending on
109 for _, cc := range super.Clusters() {
110 fmt.Fprintln(stdout, cc.Services.Controller.ExternalURL)
114 // Wait for children to exit. Don't report the
115 // ensuing "context cancelled" error, though:
116 // return nil to indicate successful startup.
118 fmt.Fprintln(stderr, "PASS - all services booted successfully")
122 // Wait for signal/crash + orderly shutdown