func InstanceTerminate(rw http.ResponseWriter, r *http.Request) *httperr.Error { rack, err := models.GetSystem() if awsError(err) == "ValidationError" { return httperr.Errorf(404, "no such stack: %s", rack) } if err != nil { return httperr.Server(err) } instanceId := mux.Vars(r)["id"] _, err = models.EC2().TerminateInstances(&ec2.TerminateInstancesInput{ InstanceIds: []*string{&instanceId}, }) if err != nil { return httperr.Server(err) } return RenderSuccess(rw) }
func (instances Instances) testDocker() error { for _, i := range instances { instance := instances[i.Id] res, err := models.EC2().DescribeInstances(&ec2.DescribeInstancesInput{ Filters: []*ec2.Filter{ &ec2.Filter{Name: aws.String("instance-id"), Values: []*string{&i.Id}}, }, }) if err != nil { return err } if len(res.Reservations) != 1 || len(res.Reservations[0].Instances) != 1 { return fmt.Errorf("could not describe container instance") } ip := *res.Reservations[0].Instances[0].PrivateIpAddress if os.Getenv("DEVELOPMENT") == "true" { ip = *res.Reservations[0].Instances[0].PublicIpAddress } d, err := docker.NewClient(fmt.Sprintf("http://%s:2376", ip)) if err != nil { return err } err = d.PullImage(docker.PullImageOptions{ Repository: "busybox", }, docker.AuthConfiguration{}) if err != nil { return err } instance.Docker = true dres, err := d.CreateContainer(docker.CreateContainerOptions{ Config: &docker.Config{ Cmd: []string{"sh", "-c", `dmesg | grep "Remounting filesystem read-only"`}, Image: "busybox", }, }) if err != nil { return err } err = d.StartContainer(dres.ID, nil) if err != nil { return err } code, err := d.WaitContainer(dres.ID) if err != nil { return err } // grep exit status is 0 if any line was selected, 1 otherwise // no "Remounting" selected is healthy if code == 1 { instance.Check = true } instances[i.Id] = instance } return nil }