1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.curoverse.com/arvados.git/lib/config"
13 "git.curoverse.com/arvados.git/sdk/go/arvados"
14 "github.com/coreos/go-systemd/daemon"
15 "github.com/ghodss/yaml"
16 log "github.com/sirupsen/logrus"
23 // Config specifies server configuration.
27 cluster *arvados.Cluster
30 func newConfig(arvCfg *arvados.Config) *Config {
32 var cls *arvados.Cluster
34 if cls, err = arvCfg.GetCluster(""); err != nil {
38 cfg.Cache.config = &cfg.cluster.Collections.WebDAVCache
43 // MakeArvadosClient returns an error if this env var isn't
44 // available as a default token (even if we explicitly set a
45 // different token before doing anything with the client). We
46 // set this dummy value during init so it doesn't clobber the
47 // one used by "run test servers".
48 if os.Getenv("ARVADOS_API_TOKEN") == "" {
49 os.Setenv("ARVADOS_API_TOKEN", "xxx")
52 log.SetFormatter(&log.JSONFormatter{
53 TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",
57 func configure(logger log.FieldLogger, args []string) *Config {
58 flags := flag.NewFlagSet(args[0], flag.ExitOnError)
60 loader := config.NewLoader(os.Stdin, logger)
61 loader.SetupFlags(flags)
63 dumpConfig := flags.Bool("dump-config", false,
64 "write current configuration to stdout and exit")
65 getVersion := flags.Bool("version", false,
66 "print version information and exit.")
68 args = loader.MungeLegacyConfigArgs(logger, args[1:], "-legacy-keepweb-config")
71 // Print version information if requested
73 fmt.Printf("keep-web %s\n", version)
77 arvCfg, err := loader.Load()
81 cfg := newConfig(arvCfg)
84 out, err := yaml.Marshal(cfg)
88 _, err = os.Stdout.Write(out)
100 cfg := configure(logger, os.Args)
105 log.Printf("keep-web %s started", version)
107 os.Setenv("ARVADOS_API_HOST", cfg.cluster.Services.Controller.ExternalURL.Host)
108 srv := &server{Config: cfg}
109 if err := srv.Start(); err != nil {
112 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
113 log.Printf("Error notifying init daemon: %v", err)
115 log.Println("Listening at", srv.Addr)
116 if err := srv.Wait(); err != nil {