Skip to content

Commit

Permalink
etcdmain: SdNotify when gateway, grpc-proxy are ready
Browse files Browse the repository at this point in the history
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Mar 9, 2017
1 parent ade1d97 commit 8d122e7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
22 changes: 6 additions & 16 deletions etcdmain/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions etcdmain/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -135,5 +136,8 @@ func startGateway(cmd *cobra.Command, args []string) {
MonitorInterval: getewayRetryDelay,
}

// At this point, etcd gateway listener is initialized
notifySystemd()

tp.Run()
}
3 changes: 3 additions & 0 deletions etcdmain/grpc_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,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)
}
Expand Down
16 changes: 16 additions & 0 deletions etcdmain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package etcdmain
import (
"fmt"
"os"

"github.com/coreos/go-systemd/daemon"
systemdutil "github.com/coreos/go-systemd/util"
)

func Main() {
Expand All @@ -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?")
}
}

0 comments on commit 8d122e7

Please sign in to comment.