1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.arvados.org/arvados.git/lib/config"
14 "git.arvados.org/arvados.git/sdk/go/arvados"
15 "github.com/coreos/go-systemd/daemon"
16 "github.com/ghodss/yaml"
17 "github.com/sirupsen/logrus"
18 log "github.com/sirupsen/logrus"
25 // Config specifies server configuration.
29 cluster *arvados.Cluster
32 func newConfig(arvCfg *arvados.Config) *Config {
34 var cls *arvados.Cluster
36 if cls, err = arvCfg.GetCluster(""); err != nil {
40 cfg.Cache.config = &cfg.cluster.Collections.WebDAVCache
41 cfg.Cache.cluster = cls
46 // MakeArvadosClient returns an error if this env var isn't
47 // available as a default token (even if we explicitly set a
48 // different token before doing anything with the client). We
49 // set this dummy value during init so it doesn't clobber the
50 // one used by "run test servers".
51 if os.Getenv("ARVADOS_API_TOKEN") == "" {
52 os.Setenv("ARVADOS_API_TOKEN", "xxx")
55 log.SetFormatter(&log.JSONFormatter{
56 TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",
60 func configure(logger log.FieldLogger, args []string) *Config {
61 flags := flag.NewFlagSet(args[0], flag.ExitOnError)
63 loader := config.NewLoader(os.Stdin, logger)
64 loader.SetupFlags(flags)
66 dumpConfig := flags.Bool("dump-config", false,
67 "write current configuration to stdout and exit")
68 getVersion := flags.Bool("version", false,
69 "print version information and exit.")
71 args = loader.MungeLegacyConfigArgs(logger, args[1:], "-legacy-keepweb-config")
74 // Print version information if requested
76 fmt.Printf("keep-web %s\n", version)
80 arvCfg, err := loader.Load()
84 cfg := newConfig(arvCfg)
87 out, err := yaml.Marshal(cfg)
91 _, err = os.Stdout.Write(out)
103 cfg := configure(logger, os.Args)
108 log.Printf("keep-web %s started", version)
110 if ext := ".txt"; mime.TypeByExtension(ext) == "" {
111 log.Warnf("cannot look up MIME type for %q -- this probably means /etc/mime.types is missing -- clients will see incorrect content types", ext)
114 os.Setenv("ARVADOS_API_HOST", cfg.cluster.Services.Controller.ExternalURL.Host)
115 srv := &server{Config: cfg}
116 if err := srv.Start(logrus.StandardLogger()); err != nil {
119 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
120 log.Printf("Error notifying init daemon: %v", err)
122 log.Println("Listening at", srv.Addr)
123 if err := srv.Wait(); err != nil {