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,11 +10,11 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
// TODO : Use log
//log "github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
)
const (
gVersion = "0.29g"
gVersion = "0.30"
// TODO : Get from $jail_zpool/defaults.json
MIN_DYN_DEVFS_RULESET = 1000
@ -27,6 +27,7 @@ var (
gUseSudo bool
gForce bool
gDebug bool
gConfigFile string
gDisplayJColumns string
@ -109,7 +110,11 @@ ex: gocage list srv-db srv-web`,
Run: func(cmd *cobra.Command, args []string) {
// Load inventory
ListJails(args, false)
StopJail(args)
if len(args) == 0 {
StopAllRunningJails()
} else {
StopJail(args)
}
},
}
@ -119,11 +124,17 @@ ex: gocage list srv-db srv-web`,
Run: func(cmd *cobra.Command, args []string) {
// Load inventory
ListJails(args, false)
StartJail(args)
if len(args) == 0 {
StartJailsAtBoot()
} else {
StartJail(args)
}
WriteConfigToDisk(false)
},
}
restartCmd = &cobra.Command{
Use: "restart",
Short: "restart jail",
@ -293,6 +304,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&gConfigFile, "config", "c", "/usr/local/etc/gocage.conf.yml", "GoCage configuration file")
rootCmd.PersistentFlags().BoolVarP(&gUseSudo, "sudo", "u", false, "Use sudo to run commands")
rootCmd.PersistentFlags().StringVarP(&gTimeZone, "timezone", "t", "", "Specify timezone. Will get from /var/db/zoneinfo if not set.")
rootCmd.PersistentFlags().BoolVarP(&gDebug, "debug", "d", false, "Debug mode")
// Command dependant switches
@ -414,6 +426,12 @@ func initConfig() {
fmt.Printf("More than 3 sort criteria is not supported!\n")
os.Exit(1)
}
if gDebug {
log.SetLevel(log.DebugLevel)
log.Debugf("Debug mode enabled\n")
}
}
/********************************************************************************