Add start and stop all jails for boot/shutdown, add debug mode

This commit is contained in:
yo
2022-10-15 14:53:43 +02:00
parent 38266af66e
commit c97f5317dd
3 changed files with 80 additions and 5 deletions

View File

@ -10,6 +10,8 @@ import (
//"reflect"
"strconv"
"strings"
log "github.com/sirupsen/logrus"
)
// TODO : Use SYS_RCTL_GET_RACCT syscall
@ -166,6 +168,33 @@ func stopJail(jail *Jail) error {
return nil
}
// Stop all running jails by reverse priority
func StopAllRunningJails() {
var stopList []Jail
// Get boot enabled jails
for _, j := range gJails {
if j.Running == true {
stopList = append(stopList, j)
}
}
// Order by priority
js := initJailSortStruct()
fct, _, err := getStructFieldValue(js, "Config.PriorityDec")
if err != nil {
log.Errorf("ERROR getting JailSort struct field \"Config.PriorityDec\"\n")
return
}
JailsOrderedBy(fct.Interface().(jailLessFunc)).Sort(stopList)
for _, j := range stopList {
jFullName := fmt.Sprintf("%s/%s", j.Datastore, j.Name)
log.Debugf("Stopping %s with priority %s\n", jFullName, j.Config.Priority)
StopJail([]string{jFullName})
}
}
/*
Stop jail:
Remove rctl rules