Use getJailFromArray so we can handle same name jails

This commit is contained in:
yo 2022-07-10 14:15:26 +02:00
parent 170dce31b3
commit e7a6bdd376

View File

@ -190,24 +190,22 @@ func stopJail(jail *Jail) error {
func StopJail(args []string) {
// Current jail were stopping
var cj *Jail
var err error
for _, j := range args {
for _, rj := range gJails {
if rj.Name == j {
cj = &rj
break
}
}
if cj == nil {
fmt.Printf("Jail not found: %s\n", j)
for _, a := range args {
// Check if jail exist and is distinctly named
cj, err = getJailFromArray(a, gJails)
if err != nil {
fmt.Printf("Error getting jail: %s\n", err)
continue
}
if cj.Running == false {
fmt.Printf("Jail %s is not running!\n", cj.Name)
continue
}
fmt.Printf("> Stopping jail %s\n", j)
fmt.Printf("> Stopping jail %s\n", a)
out, err := executeCommand(fmt.Sprintf("rctl jail:%s", cj.InternalName))
if err == nil && len(out) > 0 {