package cmd import ( "fmt" //"log" "time" //"errors" "strings" ) func DestroyJails(args []string) { for _, a := range args { cj, err := getJailFromArray(a, []string{""}, gJails) if err != nil { fmt.Printf("Error getting jail: %s\n", err) return } if cj.Running == true { fmt.Printf("Jail %s is running\n", cj.Name) if gForce == false { var answer string fmt.Printf("Stop jail and delete? (y/n) ") fmt.Scanln(&answer) if false == strings.EqualFold(answer, "y") { return } } fmt.Printf("Stopping jail %s\n", cj.Name) StopJail([]string{fmt.Sprintf("%s/%s", cj.Datastore, cj.Name)}) // Give some time to the host OS to free all mounts accessing processes time.Sleep(1 * time.Second) } // Get root and config datasets, then destroy dsRootName, err := zfsGetDatasetByMountpoint(cj.RootPath) if err != nil { fmt.Printf("Error getting root dataset: %s\n", err) return } //fmt.Printf("DEBUG: Prepare to zfs destroy %s\n", dsRootName) if err = zfsDestroy(dsRootName); err != nil { fmt.Printf("Error deleting root dataset: %s\n", err) return } dsConfName, err := zfsGetDatasetByMountpoint(cj.ConfigPath) if err != nil { fmt.Printf("Error getting config dataset: %s\n", err) return } //fmt.Printf("DEBUG: Prepare to zfs destroy %s\n", dsConfName) if err = zfsDestroy(dsConfName); err != nil { fmt.Printf("Error deleting config dataset: %s\n", err) return } fmt.Printf("Jail %s is no more!\n", cj.Name) } }