diff --git a/etcdmain/etcd.go b/etcdmain/etcd.go index b4220d479..a20e5b912 100644 --- a/etcdmain/etcd.go +++ b/etcdmain/etcd.go @@ -39,8 +39,6 @@ import ( "github.com/coreos/etcd/pkg/types" "github.com/coreos/etcd/proxy/httpproxy" "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/grpc-ecosystem/go-grpc-prometheus" "github.com/prometheus/client_golang/prometheus" @@ -163,20 +161,12 @@ func startEtcdOrProxyV2() { 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 { case lerr := <-errc: diff --git a/etcdmain/gateway.go b/etcdmain/gateway.go index 55fd2e56b..4a64a19ae 100644 --- a/etcdmain/gateway.go +++ b/etcdmain/gateway.go @@ -24,6 +24,7 @@ import ( "github.com/coreos/etcd/client" "github.com/coreos/etcd/pkg/transport" "github.com/coreos/etcd/proxy/tcpproxy" + "github.com/spf13/cobra" ) @@ -135,5 +136,8 @@ func startGateway(cmd *cobra.Command, args []string) { MonitorInterval: getewayRetryDelay, } + // At this point, etcd gateway listener is initialized + notifySystemd() + tp.Run() } diff --git a/etcdmain/grpc_proxy.go b/etcdmain/grpc_proxy.go index 08312e86b..ff3b61333 100644 --- a/etcdmain/grpc_proxy.go +++ b/etcdmain/grpc_proxy.go @@ -165,6 +165,9 @@ func startGRPCProxy(cmd *cobra.Command, args []string) { go func() { errc <- m.Serve() }() + // grpc-proxy is initialized, ready to serve + notifySystemd() + fmt.Fprintln(os.Stderr, <-errc) os.Exit(1) } diff --git a/etcdmain/main.go b/etcdmain/main.go index 87996f7c2..fd4e7f696 100644 --- a/etcdmain/main.go +++ b/etcdmain/main.go @@ -17,6 +17,9 @@ package etcdmain import ( "fmt" "os" + + "github.com/coreos/go-systemd/daemon" + systemdutil "github.com/coreos/go-systemd/util" ) func Main() { @@ -35,3 +38,16 @@ func Main() { 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?") + } +}