dotcloud/docker — pull request #4867 by crosbymichael (2014-03-26 18:23:38+00:00)
Title: Cleanly shutdown docker

Ok, so here is what we will do when you stop docker.

### SIGKILL
Nothing we can do here. However, when we restart we will find all ghosts containers and SIGKILL them because we are in an inconsistent state and they cannot be trusted. We will then iterate though the state of the containers that were running and restart them for you.

### SIGTERM, SIGINT, etc
If docker receives a signal that it can handled we will start the shutdown process. This means iterating over all running containers and sending a SIGTERM to them and giving them a grace period ( 10 sec by default like with docker stop ) before we send a SIGKILL. Any containers that were running will be restarted when docker starts again.

#### Implementation Details
1) We discussed keeping the prctl parent death signal to containers when docker dies unexpectedly but I think for consistence across the drivers we should not do this for native even if it is just a SIGTERM or whatever. It makes the shutdown logic much cleaner and consistent in the long run.

2) Because the native driver still needs to kill ghosts ( because we don't deliver the prctl sig) but we don't want to be issuing SIGKILLS to pids that were not our own we now save the start time along with the pid in the native driver so that in the event of a system reboot, we can verify that the pid and it's start time are consistent with what we have on disk.