etcdmain: SdNotify when gateway, grpc-proxy are ready

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyu-Ho Lee 2017-03-09 09:11:43 -08:00
parent ad1d48b73d
commit 01dd60c0f7
4 changed files with 29 additions and 16 deletions

View File

@ -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.
// At this point, the initialization of etcd is done. // The listeners are listening on the TCP ports and ready
// The listeners are listening on the TCP ports and ready // for accepting connections. The etcd instance should be
// for accepting connections. The etcd instance should be // joined with the cluster and ready to serve incoming
// joined with the cluster and ready to serve incoming // connections.
// connections. notifySystemd()
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?")
}
}
select { select {
case lerr := <-errc: case lerr := <-errc:

View File

@ -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()
} }

View File

@ -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)
} }

View File

@ -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?")
}
}