示例#1
0
func (a *HostAgent) removeInstance(stateID string, ctr *docker.Container) {
	rc, err := ctr.Wait(time.Second)
	if err != nil || rc != 0 || glog.GetVerbosity() > 0 {
		// TODO: output of docker logs is potentially very large
		// this should be implemented another way, perhaps a docker attach
		// or extend docker to give last N seconds
		if output, err := exec.Command("docker", "logs", "--tail", "10000", ctr.ID).CombinedOutput(); err != nil {
			glog.Errorf("Could not get logs for container %s", ctr.ID)
		} else {
			glog.Warningf("Last 10000 lines of container %s:\n %s", ctr.ID, string(output))
		}
	}
	if ctr.IsRunning() {
		glog.Errorf("Instance %s (%s) is still running, killing container")
		ctr.Kill()
	}
	if err := ctr.Delete(true); err != nil {
		glog.Errorf("Could not remove instance %s (%s): %s", stateID, ctr.ID, err)
	}
	glog.Infof("Service state %s (%s) receieved exit code %d", stateID, ctr.ID, rc)

}