7710: text updates around the -service-type argument.
[arvados.git] / services / keepproxy / keepproxy.go
index bad0d22bf1a81868799d8a437860f941d6fbe770..7b5cd2befb8f69bd25fa62674d01590214aec5ad 100644 (file)
@@ -14,7 +14,6 @@ import (
        "net/http"
        "os"
        "os/signal"
-       "reflect"
        "regexp"
        "sync"
        "syscall"
@@ -79,6 +78,19 @@ func main() {
 
        flagset.Parse(os.Args[1:])
 
+       arv, err := arvadosclient.MakeArvadosClient()
+       if err != nil {
+               log.Fatalf("Error setting up arvados client %s", err.Error())
+       }
+
+       if os.Getenv("ARVADOS_DEBUG") != "" {
+               keepclient.DebugPrintf = log.Printf
+       }
+       kc, err := keepclient.MakeKeepClient(&arv)
+       if err != nil {
+               log.Fatalf("Error setting up keep client %s", err.Error())
+       }
+
        if pidfile != "" {
                f, err := os.Create(pidfile)
                if err != nil {
@@ -89,17 +101,9 @@ func main() {
                defer os.Remove(pidfile)
        }
 
-       arv, err := arvadosclient.MakeArvadosClient()
-       if err != nil {
-               log.Fatalf("setting up arvados client: %v", err)
-       }
-       kc, err := keepclient.MakeKeepClient(&arv)
-       if err != nil {
-               log.Fatalf("setting up keep client: %v", err)
-       }
        kc.Want_replicas = default_replicas
        kc.Client.Timeout = time.Duration(timeout) * time.Second
-       go RefreshServicesList(kc, 5*time.Minute, 3*time.Second)
+       go kc.RefreshServices(5*time.Minute, 3*time.Second)
 
        listener, err = net.Listen("tcp", listen)
        if err != nil {
@@ -130,42 +134,6 @@ type ApiTokenCache struct {
        expireTime int64
 }
 
-// Refresh the keep service list on SIGHUP; when the given interval
-// has elapsed since the last refresh; and (if the last refresh
-// failed) the given errInterval has elapsed.
-func RefreshServicesList(kc *keepclient.KeepClient, interval, errInterval time.Duration) {
-       var previousRoots = []map[string]string{}
-
-       timer := time.NewTimer(interval)
-       gotHUP := make(chan os.Signal, 1)
-       signal.Notify(gotHUP, syscall.SIGHUP)
-
-       for {
-               select {
-               case <-gotHUP:
-               case <-timer.C:
-               }
-               timer.Reset(interval)
-
-               if err := kc.DiscoverKeepServers(); err != nil {
-                       log.Println("Error retrieving services list: %v (retrying in %v)", err, errInterval)
-                       timer.Reset(errInterval)
-                       continue
-               }
-               newRoots := []map[string]string{kc.LocalRoots(), kc.GatewayRoots()}
-
-               if !reflect.DeepEqual(previousRoots, newRoots) {
-                       log.Printf("Updated services list: locals %v gateways %v", newRoots[0], newRoots[1])
-                       previousRoots = newRoots
-               }
-
-               if len(newRoots[0]) == 0 {
-                       log.Printf("WARNING: No local services (retrying in %v)", errInterval)
-                       timer.Reset(errInterval)
-               }
-       }
-}
-
 // Cache the token and set an expire time.  If we already have an expire time
 // on the token, it is not updated.
 func (this *ApiTokenCache) RememberToken(token string) {