зеркало из https://github.com/microsoft/docker.git
Implement cleanup unix sockets after serving.
Signed-off-by: Rik Nijessen <riknijessen@gmail.com>
This commit is contained in:
Родитель
385d4beaa5
Коммит
0c0e9836c4
|
@ -1578,6 +1578,11 @@ func ServeApi(job *engine.Job) engine.Status {
|
|||
chErrors <- err
|
||||
return
|
||||
}
|
||||
job.Eng.OnShutdown(func() {
|
||||
if err := srv.Close(); err != nil {
|
||||
log.Errorf("%s", err.Error())
|
||||
}
|
||||
})
|
||||
chErrors <- srv.Serve()
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -10,8 +10,30 @@ import (
|
|||
|
||||
"github.com/docker/docker/engine"
|
||||
"github.com/docker/docker/pkg/systemd"
|
||||
"net"
|
||||
)
|
||||
|
||||
type UnixHttpServer struct {
|
||||
srv *http.Server
|
||||
l net.Listener
|
||||
}
|
||||
|
||||
func (s *UnixHttpServer) Serve() error {
|
||||
return s.srv.Serve(s.l)
|
||||
}
|
||||
func (s *UnixHttpServer) Close() error {
|
||||
if err := s.l.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := os.Stat(s.srv.Addr); err != nil {
|
||||
return fmt.Errorf("Error removing unix socket %s: %s", s.srv.Addr, err.Error())
|
||||
}
|
||||
if err := os.Remove(s.srv.Addr); err != nil {
|
||||
return fmt.Errorf("Error removing unix socket %s: %s", s.srv.Addr, err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewServer sets up the required Server and does protocol specific checking.
|
||||
func NewServer(proto, addr string, job *engine.Job) (Server, error) {
|
||||
// Basic error and sanity checking
|
||||
|
@ -27,7 +49,7 @@ func NewServer(proto, addr string, job *engine.Job) (Server, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func setupUnixHttp(addr string, job *engine.Job) (*HttpServer, error) {
|
||||
func setupUnixHttp(addr string, job *engine.Job) (*UnixHttpServer, error) {
|
||||
r := createRouter(job.Eng, job.GetenvBool("Logging"), job.GetenvBool("EnableCors"), job.Getenv("CorsHeaders"), job.Getenv("Version"))
|
||||
|
||||
if err := syscall.Unlink(addr); err != nil && !os.IsNotExist(err) {
|
||||
|
@ -49,7 +71,7 @@ func setupUnixHttp(addr string, job *engine.Job) (*HttpServer, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return &HttpServer{&http.Server{Addr: addr, Handler: r}, l}, nil
|
||||
return &UnixHttpServer{&http.Server{Addr: addr, Handler: r}, l}, nil
|
||||
}
|
||||
|
||||
// serveFd creates an http.Server and sets it up to serve given a socket activated
|
||||
|
|
Загрузка…
Ссылка в новой задаче