Pārlūkot izejas kodu

Merge pull request #7467 from gyuho/sd-notify

etcdmain: SdNotify when gateway, grpc-proxy are ready
Gyu-Ho Lee 8 gadi atpakaļ
vecāks
revīzija
5351953425
4 mainītis faili ar 29 papildinājumiem un 16 dzēšanām
  1. 6 16
      etcdmain/etcd.go
  2. 4 0
      etcdmain/gateway.go
  3. 3 0
      etcdmain/grpc_proxy.go
  4. 16 0
      etcdmain/main.go

+ 6 - 16
etcdmain/etcd.go

@@ -39,8 +39,6 @@ import (
 	"github.com/coreos/etcd/pkg/types"
 	"github.com/coreos/etcd/pkg/types"
 	"github.com/coreos/etcd/proxy/httpproxy"
 	"github.com/coreos/etcd/proxy/httpproxy"
 	"github.com/coreos/etcd/version"
 	"github.com/coreos/etcd/version"
-	"github.com/coreos/go-systemd/daemon"
-	systemdutil "github.com/coreos/go-systemd/util"
 	"github.com/coreos/pkg/capnslog"
 	"github.com/coreos/pkg/capnslog"
 	"github.com/grpc-ecosystem/go-grpc-prometheus"
 	"github.com/grpc-ecosystem/go-grpc-prometheus"
 	"github.com/prometheus/client_golang/prometheus"
 	"github.com/prometheus/client_golang/prometheus"
@@ -163,20 +161,12 @@ func startEtcdOrProxyV2() {
 
 
 	osutil.HandleInterrupts()
 	osutil.HandleInterrupts()
 
 
-	if systemdutil.IsRunningSystemd() {
-		// At this point, the initialization of etcd is done.
-		// The listeners are listening on the TCP ports and ready
-		// for accepting connections. The etcd instance should be
-		// joined with the cluster and ready to serve incoming
-		// connections.
-		sent, err := daemon.SdNotify(false, "READY=1")
-		if err != nil {
-			plog.Errorf("failed to notify systemd for readiness: %v", err)
-		}
-		if !sent {
-			plog.Errorf("forgot to set Type=notify in systemd service file?")
-		}
-	}
+	// At this point, the initialization of etcd is done.
+	// The listeners are listening on the TCP ports and ready
+	// for accepting connections. The etcd instance should be
+	// joined with the cluster and ready to serve incoming
+	// connections.
+	notifySystemd()
 
 
 	select {
 	select {
 	case lerr := <-errc:
 	case lerr := <-errc:

+ 4 - 0
etcdmain/gateway.go

@@ -24,6 +24,7 @@ import (
 	"github.com/coreos/etcd/client"
 	"github.com/coreos/etcd/client"
 	"github.com/coreos/etcd/pkg/transport"
 	"github.com/coreos/etcd/pkg/transport"
 	"github.com/coreos/etcd/proxy/tcpproxy"
 	"github.com/coreos/etcd/proxy/tcpproxy"
+
 	"github.com/spf13/cobra"
 	"github.com/spf13/cobra"
 )
 )
 
 
@@ -135,5 +136,8 @@ func startGateway(cmd *cobra.Command, args []string) {
 		MonitorInterval: getewayRetryDelay,
 		MonitorInterval: getewayRetryDelay,
 	}
 	}
 
 
+	// At this point, etcd gateway listener is initialized
+	notifySystemd()
+
 	tp.Run()
 	tp.Run()
 }
 }

+ 3 - 0
etcdmain/grpc_proxy.go

@@ -165,6 +165,9 @@ func startGRPCProxy(cmd *cobra.Command, args []string) {
 
 
 	go func() { errc <- m.Serve() }()
 	go func() { errc <- m.Serve() }()
 
 
+	// grpc-proxy is initialized, ready to serve
+	notifySystemd()
+
 	fmt.Fprintln(os.Stderr, <-errc)
 	fmt.Fprintln(os.Stderr, <-errc)
 	os.Exit(1)
 	os.Exit(1)
 }
 }

+ 16 - 0
etcdmain/main.go

@@ -17,6 +17,9 @@ package etcdmain
 import (
 import (
 	"fmt"
 	"fmt"
 	"os"
 	"os"
+
+	"github.com/coreos/go-systemd/daemon"
+	systemdutil "github.com/coreos/go-systemd/util"
 )
 )
 
 
 func Main() {
 func Main() {
@@ -35,3 +38,16 @@ func Main() {
 
 
 	startEtcdOrProxyV2()
 	startEtcdOrProxyV2()
 }
 }
+
+func notifySystemd() {
+	if !systemdutil.IsRunningSystemd() {
+		return
+	}
+	sent, err := daemon.SdNotify(false, "READY=1")
+	if err != nil {
+		plog.Errorf("failed to notify systemd for readiness: %v", err)
+	}
+	if !sent {
+		plog.Errorf("forgot to set Type=notify in systemd service file?")
+	}
+}