4015: update FUSE mount tests (again)
[arvados.git] / services / keepproxy / keepproxy.go
index 2f36fd299e2fa8d36eee0253544ebe42c48fbd91..de4ccafc28dd90f6ddbab4690bcc02976dcfa4af 100644 (file)
@@ -80,12 +80,12 @@ func main() {
 
        if pidfile != "" {
                f, err := os.Create(pidfile)
-               if err == nil {
-                       fmt.Fprint(f, os.Getpid())
-                       f.Close()
-               } else {
-                       log.Printf("Error writing pid file (%s): %s", pidfile, err.Error())
+               if err != nil {
+                       log.Fatalf("Error writing pid file (%s): %s", pidfile, err.Error())
                }
+               fmt.Fprint(f, os.Getpid())
+               f.Close()
+               defer os.Remove(pidfile)
        }
 
        kc.Want_replicas = default_replicas
@@ -104,6 +104,7 @@ func main() {
                s := <-sig
                log.Println("caught signal:", s)
                listener.Close()
+               listener = nil
        }(term)
        signal.Notify(term, syscall.SIGTERM)
        signal.Notify(term, syscall.SIGINT)
@@ -114,10 +115,6 @@ func main() {
        http.Serve(listener, MakeRESTRouter(!no_get, !no_put, &kc))
 
        log.Println("shutting down")
-
-       if pidfile != "" {
-               os.Remove(pidfile)
-       }
 }
 
 type ApiTokenCache struct {