1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.curoverse.com/arvados.git/sdk/go/arvados"
16 "git.curoverse.com/arvados.git/sdk/go/config"
17 "github.com/coreos/go-systemd/daemon"
22 // Server configuration
29 ManagementToken string
32 var theConfig = defaultConfig()
34 func defaultConfig() *Config {
37 GitCommand: "/usr/bin/git",
38 RepoRoot: "/var/lib/arvados/git/repositories",
43 const defaultCfgPath = "/etc/arvados/git-httpd/git-httpd.yml"
44 const deprecated = " (DEPRECATED -- use config file instead)"
45 flag.StringVar(&theConfig.Listen, "address", theConfig.Listen,
46 "Address to listen on, \"host:port\" or \":port\"."+deprecated)
47 flag.StringVar(&theConfig.GitCommand, "git-command", theConfig.GitCommand,
48 "Path to git or gitolite-shell executable. Each authenticated request will execute this program with a single argument, \"http-backend\"."+deprecated)
49 flag.StringVar(&theConfig.RepoRoot, "repo-root", theConfig.RepoRoot,
50 "Path to git repositories."+deprecated)
51 flag.StringVar(&theConfig.GitoliteHome, "gitolite-home", theConfig.GitoliteHome,
52 "Value for GITOLITE_HTTP_HOME environment variable. If not empty, GL_BYPASS_ACCESS_CHECKS=1 will also be set."+deprecated)
54 cfgPath := flag.String("config", defaultCfgPath, "Configuration file `path`.")
55 dumpConfig := flag.Bool("dump-config", false, "write current configuration to stdout and exit (useful for migrating from command line flags to config file)")
56 getVersion := flag.Bool("version", false, "print version information and exit.")
58 flag.StringVar(&theConfig.ManagementToken, "management-token", theConfig.ManagementToken,
59 "Authorization token to be included in all health check requests.")
64 // Print version information if requested
66 fmt.Printf("arv-git-httpd %s\n", version)
70 err := config.LoadFile(theConfig, *cfgPath)
72 h := os.Getenv("ARVADOS_API_HOST")
73 if h == "" || !os.IsNotExist(err) || *cfgPath != defaultCfgPath {
76 log.Print("DEPRECATED: No config file found, but ARVADOS_API_HOST environment variable is set. Please use a config file instead.")
77 theConfig.Client.APIHost = h
78 if regexp.MustCompile("^(?i:1|yes|true)$").MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE")) {
79 theConfig.Client.Insecure = true
81 if j, err := json.MarshalIndent(theConfig, "", " "); err == nil {
82 log.Print("Current configuration:\n", string(j))
87 log.Fatal(config.DumpAndExit(theConfig))
91 if err := srv.Start(); err != nil {
94 if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
95 log.Printf("Error notifying init daemon: %v", err)
97 log.Printf("arv-git-httpd %s started", version)
98 log.Println("Listening at", srv.Addr)
99 log.Println("Repository root", theConfig.RepoRoot)
100 if err := srv.Wait(); err != nil {