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
45 // MakeArvadosClient returns an error if this env var isn't
46 // available as a default token (even if we explicitly set a
47 // different token before doing anything with the client). We
48 // set this dummy value during init so it doesn't clobber the
49 // one used by "run test servers".
50 if os.Getenv("ARVADOS_API_TOKEN") == "" {
51 os.Setenv("ARVADOS_API_TOKEN", "xxx")
54 log.SetFormatter(&log.JSONFormatter{
55 TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",
59 func configure(logger log.FieldLogger, args []string) *Config {
60 flags := flag.NewFlagSet(args[0], flag.ExitOnError)
62 loader := config.NewLoader(os.Stdin, logger)
63 loader.SetupFlags(flags)
65 dumpConfig := flags.Bool("dump-config", false,
66 "write current configuration to stdout and exit")
67 getVersion := flags.Bool("version", false,
68 "print version information and exit.")
70 args = loader.MungeLegacyConfigArgs(logger, args[1:], "-legacy-keepweb-config")
73 // Print version information if requested
75 fmt.Printf("keep-web %s\n", version)
79 arvCfg, err := loader.Load()
83 cfg := newConfig(arvCfg)
86 out, err := yaml.Marshal(cfg)
90 _, err = os.Stdout.Write(out)
102 cfg := configure(logger, os.Args)
107 log.Printf("keep-web %s started", version)
109 if ext := ".txt"; mime.TypeByExtension(ext) == "" {
110 log.Warnf("cannot look up MIME type for %q -- this probably means /etc/mime.types is missing -- clients will see incorrect content types", ext)
113 os.Setenv("ARVADOS_API_HOST", cfg.cluster.Services.Controller.ExternalURL.Host)
114 srv := &server{Config: cfg}
115 if err := srv.Start(logrus.StandardLogger()); err != nil {
118 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
119 log.Printf("Error notifying init daemon: %v", err)
121 log.Println("Listening at", srv.Addr)
122 if err := srv.Wait(); err != nil {