mirror of https://github.com/docker/docs.git
Merge pull request #234 from ehazlett/graceful-cleanup-on-create-fail
add cleanup for create failure
This commit is contained in:
commit
9c3624b170
10
commands.go
10
commands.go
|
@ -190,7 +190,17 @@ func cmdCreate(c *cli.Context) {
|
||||||
|
|
||||||
host, err := store.Create(name, driver, c)
|
host, err := store.Create(name, driver, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("Error creating host: %s", err)
|
||||||
|
if c.GlobalBool("debug") {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
} else {
|
||||||
|
log.Warnf("Removing created machine. You can run machine with the --debug flag to avoid this.")
|
||||||
|
// we know there was an error so do not check for the error on removal
|
||||||
|
// instead we will Fatal with a message to prevent spamming with error messages
|
||||||
|
_ = store.Remove(name, true)
|
||||||
|
log.Warn("You will want to check the provider to make sure the machine and associated resources were properly removed.")
|
||||||
|
log.Fatal("Error creating machine")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err := store.SetActive(host); err != nil {
|
if err := store.SetActive(host); err != nil {
|
||||||
log.Fatalf("error setting active host: %v", err)
|
log.Fatalf("error setting active host: %v", err)
|
||||||
|
|
4
host.go
4
host.go
|
@ -227,9 +227,7 @@ func (h *Host) Upgrade() error {
|
||||||
|
|
||||||
func (h *Host) Remove(force bool) error {
|
func (h *Host) Remove(force bool) error {
|
||||||
if err := h.Driver.Remove(); err != nil {
|
if err := h.Driver.Remove(); err != nil {
|
||||||
if force {
|
if !force {
|
||||||
log.Errorf("Error removing host, force removing anyway: %s", err)
|
|
||||||
} else {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue