1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.curoverse.com/arvados.git/sdk/go/arvados"
15 "git.curoverse.com/arvados.git/sdk/go/config"
16 "github.com/coreos/go-systemd/daemon"
19 // Server configuration
28 var theConfig = defaultConfig()
30 func defaultConfig() *Config {
33 GitCommand: "/usr/bin/git",
34 RepoRoot: "/var/lib/arvados/git/repositories",
39 const defaultCfgPath = "/etc/arvados/git-httpd/git-httpd.yml"
40 const deprecated = " (DEPRECATED -- use config file instead)"
41 flag.StringVar(&theConfig.Listen, "address", theConfig.Listen,
42 "Address to listen on, \"host:port\" or \":port\"."+deprecated)
43 flag.StringVar(&theConfig.GitCommand, "git-command", theConfig.GitCommand,
44 "Path to git or gitolite-shell executable. Each authenticated request will execute this program with a single argument, \"http-backend\"."+deprecated)
45 flag.StringVar(&theConfig.RepoRoot, "repo-root", theConfig.RepoRoot,
46 "Path to git repositories."+deprecated)
47 flag.StringVar(&theConfig.GitoliteHome, "gitolite-home", theConfig.GitoliteHome,
48 "Value for GITOLITE_HTTP_HOME environment variable. If not empty, GL_BYPASS_ACCESS_CHECKS=1 will also be set."+deprecated)
50 cfgPath := flag.String("config", defaultCfgPath, "Configuration file `path`.")
51 dumpConfig := flag.Bool("dump-config", false, "write current configuration to stdout and exit (useful for migrating from command line flags to config file)")
55 err := config.LoadFile(theConfig, *cfgPath)
57 h := os.Getenv("ARVADOS_API_HOST")
58 if h == "" || !os.IsNotExist(err) || *cfgPath != defaultCfgPath {
61 log.Print("DEPRECATED: No config file found, but ARVADOS_API_HOST environment variable is set. Please use a config file instead.")
62 theConfig.Client.APIHost = h
63 if regexp.MustCompile("^(?i:1|yes|true)$").MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE")) {
64 theConfig.Client.Insecure = true
66 if j, err := json.MarshalIndent(theConfig, "", " "); err == nil {
67 log.Print("Current configuration:\n", string(j))
72 log.Fatal(config.DumpAndExit(theConfig))
76 if err := srv.Start(); err != nil {
79 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
80 log.Printf("Error notifying init daemon: %v", err)
82 log.Println("Listening at", srv.Addr)
83 log.Println("Repository root", theConfig.RepoRoot)
84 if err := srv.Wait(); err != nil {