Add gocage destroy command
This commit is contained in:
parent
956e25c849
commit
e11fc96e05
57
cmd/destroy.go
Normal file
57
cmd/destroy.go
Normal file
@ -0,0 +1,57 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
//"log"
|
||||
//"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func DestroyJails(args []string) {
|
||||
for _, a := range args {
|
||||
cj, err := getJailFromArray(a, 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)})
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
//TODO: Delete jail named directory
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user