зеркало из https://github.com/microsoft/docker.git
docker daemon: initialize the daemon pidfile early
fixes https://github.com/dotcloud/docker/issues/6973 Docker-DCO-1.1-Signed-off-by: Vincent Batts <vbatts@redhat.com> (github: vbatts)
This commit is contained in:
Родитель
7c4f7780a1
Коммит
848e837698
|
@ -50,6 +50,9 @@ func remote(eng *engine.Engine) error {
|
|||
// These components should be broken off into plugins of their own.
|
||||
//
|
||||
func daemon(eng *engine.Engine) error {
|
||||
if err := eng.Register("initserverpidfile", server.InitPidfile); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := eng.Register("initserver", server.InitServer); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -149,12 +149,22 @@ func main() {
|
|||
if err := builtins.Register(eng); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// handle the pidfile early. https://github.com/dotcloud/docker/issues/6973
|
||||
if len(*pidfile) > 0 {
|
||||
job := eng.Job("initserverpidfile", *pidfile)
|
||||
if err := job.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// load the daemon in the background so we can immediately start
|
||||
// the http api so that connections don't fail while the daemon
|
||||
// is booting
|
||||
go func() {
|
||||
// Load plugin: httpapi
|
||||
job := eng.Job("initserver")
|
||||
// include the variable here too, for the server config
|
||||
job.Setenv("Pidfile", *pidfile)
|
||||
job.Setenv("Root", realRoot)
|
||||
job.SetenvBool("AutoRestart", *flAutoRestart)
|
||||
|
|
|
@ -72,6 +72,17 @@ func (srv *Server) handlerWrap(h engine.Handler) engine.Handler {
|
|||
}
|
||||
}
|
||||
|
||||
func InitPidfile(job *engine.Job) engine.Status {
|
||||
if len(job.Args) == 0 {
|
||||
return job.Error(fmt.Errorf("no pidfile provided to initialize"))
|
||||
}
|
||||
job.Logf("Creating pidfile")
|
||||
if err := utils.CreatePidFile(job.Args[0]); err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
||||
// jobInitApi runs the remote api server `srv` as a daemon,
|
||||
// Only one api server can run at the same time - this is enforced by a pidfile.
|
||||
// The signals SIGINT, SIGQUIT and SIGTERM are intercepted for cleanup.
|
||||
|
@ -81,13 +92,6 @@ func InitServer(job *engine.Job) engine.Status {
|
|||
if err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
if srv.daemon.Config().Pidfile != "" {
|
||||
job.Logf("Creating pidfile")
|
||||
if err := utils.CreatePidFile(srv.daemon.Config().Pidfile); err != nil {
|
||||
// FIXME: do we need fatal here instead of returning a job error?
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
job.Logf("Setting up signal traps")
|
||||
c := make(chan os.Signal, 1)
|
||||
gosignal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
|
||||
|
|
Загрузка…
Ссылка в новой задаче