mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #6976 from vbatts/vbatts-early_daemon_pidfile
docker daemon: initialize the daemon pidfile early
This commit is contained in:
commit
d0e2d9ec39
3 changed files with 24 additions and 7 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -153,12 +153,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)
|
||||
|
|
Loading…
Reference in a new issue