Initialise gJailHost

This commit is contained in:
yo 2022-06-19 13:55:07 +02:00
parent 1bc248fdcc
commit f919ff2ec3

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"strconv"
"strings" "strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -22,6 +21,7 @@ const (
) )
var ( var (
gJailHost JailHost
gJails []Jail gJails []Jail
gDatastores []Datastore gDatastores []Datastore
@ -261,6 +261,8 @@ You can specify multiple datastores.`,
// TODO : Init log level and log output // TODO : Init log level and log output
func init() { func init() {
var err error
cobra.OnInitialize(initConfig) cobra.OnInitialize(initConfig)
// Global switches // Global switches
@ -320,14 +322,12 @@ func init() {
migrateCmd.AddCommand(migrateCleanCmd) migrateCmd.AddCommand(migrateCleanCmd)
datastoreCmd.AddCommand(datastoreListCmd) datastoreCmd.AddCommand(datastoreListCmd)
// Get FreeBSD version // Get FreeBSD version, hostname, hostid
out, err := executeCommand("freebsd-version") gJailHost, err = NewJailHost()
if err != nil { if err != nil {
fmt.Printf("Error running \"freebsd-version\": %s", err.Error()) fmt.Printf("Error initializing JailHost properties: %v\n", err)
os.Exit(1) os.Exit(1)
} }
gHostVersion, _ = strconv.ParseFloat(strings.Split(out, "-")[0], 32)
} }
func initConfig() { func initConfig() {
@ -336,8 +336,6 @@ func initConfig() {
os.Exit(1) os.Exit(1)
} }
// fmt.Printf("We are in initConfig(), with config file %s\n", gConfigFile)
viper.SetConfigFile(gConfigFile) viper.SetConfigFile(gConfigFile)
if err := viper.ReadInConfig(); err != nil { if err := viper.ReadInConfig(); err != nil {
@ -400,6 +398,7 @@ func initConfig() {
func WriteConfigToDisk(changeauto bool) { func WriteConfigToDisk(changeauto bool) {
for _, j := range gJails { for _, j := range gJails {
if j.ConfigUpdated { if j.ConfigUpdated {
//log.Debug("%s config has changed, write changes to disk\n", j.Name)
// we will manipulate properties so get a copy // we will manipulate properties so get a copy
jc := j.Config jc := j.Config