Cleanup: refactor shutdown and signal handling facility

This disentangles the following functions, which were previously all mixed together:

* 1) Waiting for jobs to terminate when shutting down
* 2) Handling signals in the Docker daemon
* 3) Per-subsystem cleanup handlers
* 4) pidfile management

Responsibilities are dispatched as follows:

* Signal traps are set in `main`, and trigger `engine.Shutdown`
* `engine.Shutdown` coordinates cleanup by waiting for jobs to complete, and calling shutdown handlers
* To perform cleanup at shutdown, each subsystem registers handlers with `engine.OnShutdown`
* `daemon` is one subsystem, so it registers cleanup via `engine.OnShutdown`.
* `daemon` owns the pidfile, which is used to lock access to `/var/lib/docker`. Part of its cleanup is to remove the pidfile.

IsShutdown was needed after, from daemon.monitor (see the blame of
engine.go to see which commit created which).

I can get rid of checkShutdown and use IsShutdown everywhere

On Thursday, August 7, 2014, Alexandr Morozov <notifications@github.com>
wrote:

> In engine/engine.go:
>
> > +			h()
> > +		}(h)
> > +	}
> > +	done := make(chan struct{})
> > +	go func() {
> > +		wg.Wait()
> > +		close(done)
> > +	}()
> > +	select {
> > +	case <-time.After(time.Second * 5):
> > +	case <-done:
> > +	}
> > +	return
> > +}
> > +
> > +func (eng *Engine) checkShutdown() error {
>
> what differnce of this function from IsShutdown? And why it is private?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/docker/docker/pull/7449/files#r15977621>.
>