mirror of https://github.com/docker/docs.git
sd_notify ready status when accepting API requests
This commit is contained in:
parent
afbea3f13f
commit
97088ebef7
7
api.go
7
api.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/archive"
|
"github.com/dotcloud/docker/archive"
|
||||||
"github.com/dotcloud/docker/auth"
|
"github.com/dotcloud/docker/auth"
|
||||||
|
"github.com/dotcloud/docker/systemd"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"io"
|
"io"
|
||||||
|
@ -1184,8 +1185,6 @@ func ServeRequest(srv *Server, apiversion float64, w http.ResponseWriter, req *h
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListenAndServe(proto, addr string, srv *Server, logging bool) error {
|
func ListenAndServe(proto, addr string, srv *Server, logging bool) error {
|
||||||
log.Printf("Listening for HTTP on %s (%s)\n", addr, proto)
|
|
||||||
|
|
||||||
r, err := createRouter(srv, logging)
|
r, err := createRouter(srv, logging)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1216,5 +1215,9 @@ func ListenAndServe(proto, addr string, srv *Server, logging bool) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
httpSrv := http.Server{Addr: addr, Handler: r}
|
httpSrv := http.Server{Addr: addr, Handler: r}
|
||||||
|
|
||||||
|
log.Printf("Listening for HTTP on %s (%s)\n", addr, proto)
|
||||||
|
// Tell the init daemon we are accepting requests
|
||||||
|
go systemd.SdNotify("READY=1")
|
||||||
return httpSrv.Serve(l)
|
return httpSrv.Serve(l)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package systemd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
var SdNotifyNoSocket = errors.New("No socket")
|
||||||
|
|
||||||
|
// Send a message to the init daemon. It is common to ignore the error.
|
||||||
|
func SdNotify(state string) error {
|
||||||
|
socketAddr := &net.UnixAddr{
|
||||||
|
Name: os.Getenv("NOTIFY_SOCKET"),
|
||||||
|
Net: "unixgram",
|
||||||
|
}
|
||||||
|
|
||||||
|
if socketAddr.Name == "" {
|
||||||
|
return SdNotifyNoSocket
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.Write([]byte(state))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue