Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika@curoverse.com>
[arvados.git] / services / arv-git-httpd / main.go
index dd281366b29ac886365056ad8c2c4e2250a0d739..bee02693ae62745be83a0ac80a3430cfb3cf804e 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package main
 
 import (
@@ -14,27 +18,24 @@ import (
 
 // Server configuration
 type Config struct {
-       Client     arvados.Client
-       Listen     string
-       GitCommand string
-       RepoRoot   string
+       Client       arvados.Client
+       Listen       string
+       GitCommand   string
+       RepoRoot     string
+       GitoliteHome string
 }
 
 var theConfig = defaultConfig()
 
 func defaultConfig() *Config {
-       cwd, err := os.Getwd()
-       if err != nil {
-               log.Fatalln("Getwd():", err)
-       }
        return &Config{
                Listen:     ":80",
                GitCommand: "/usr/bin/git",
-               RepoRoot:   cwd,
+               RepoRoot:   "/var/lib/arvados/git/repositories",
        }
 }
 
-func init() {
+func main() {
        const defaultCfgPath = "/etc/arvados/git-httpd/git-httpd.yml"
        const deprecated = " (DEPRECATED -- use config file instead)"
        flag.StringVar(&theConfig.Listen, "address", theConfig.Listen,
@@ -43,8 +44,11 @@ func init() {
                "Path to git or gitolite-shell executable. Each authenticated request will execute this program with a single argument, \"http-backend\"."+deprecated)
        flag.StringVar(&theConfig.RepoRoot, "repo-root", theConfig.RepoRoot,
                "Path to git repositories."+deprecated)
+       flag.StringVar(&theConfig.GitoliteHome, "gitolite-home", theConfig.GitoliteHome,
+               "Value for GITOLITE_HTTP_HOME environment variable. If not empty, GL_BYPASS_ACCESS_CHECKS=1 will also be set."+deprecated)
 
        cfgPath := flag.String("config", defaultCfgPath, "Configuration file `path`.")
+       dumpConfig := flag.Bool("dump-config", false, "write current configuration to stdout and exit (useful for migrating from command line flags to config file)")
        flag.Usage = usage
        flag.Parse()
 
@@ -63,14 +67,16 @@ func init() {
                        log.Print("Current configuration:\n", string(j))
                }
        }
-}
 
-func main() {
+       if *dumpConfig {
+               log.Fatal(config.DumpAndExit(theConfig))
+       }
+
        srv := &server{}
        if err := srv.Start(); err != nil {
                log.Fatal(err)
        }
-       if _, err := daemon.SdNotify("READY=1"); err != nil {
+       if _, err := daemon.SdNotify(false, "READY=1"); err != nil {
                log.Printf("Error notifying init daemon: %v", err)
        }
        log.Println("Listening at", srv.Addr)