v0.36b: fix writeConfigToDisk
This commit is contained in:
84
cmd/root.go
84
cmd/root.go
@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
gVersion = "0.36a"
|
||||
gVersion = "0.36b"
|
||||
|
||||
// TODO : Get from $jail_zpool/defaults.json
|
||||
MIN_DYN_DEVFS_RULESET = 1000
|
||||
@ -137,7 +137,6 @@ ex: gocage list srv-db srv-web`,
|
||||
} else {
|
||||
StartJail(args)
|
||||
}
|
||||
WriteConfigToDisk("", false, false)
|
||||
},
|
||||
}
|
||||
|
||||
@ -149,7 +148,6 @@ ex: gocage list srv-db srv-web`,
|
||||
ListJails(args, false)
|
||||
StopJail(args)
|
||||
StartJail(args)
|
||||
WriteConfigToDisk("", false, false)
|
||||
},
|
||||
}
|
||||
|
||||
@ -172,7 +170,6 @@ Multiples properties can be specified, separated with space (Ex: gocage set allo
|
||||
// Load inventory
|
||||
ListJails(args, false)
|
||||
SetJailProperties(args)
|
||||
WriteConfigToDisk("", true, false)
|
||||
},
|
||||
}
|
||||
|
||||
@ -254,7 +251,6 @@ You can specify multiple jails.`,
|
||||
// Load inventory
|
||||
ListJails(args, false)
|
||||
MigrateJail(args)
|
||||
WriteConfigToDisk("", false, false)
|
||||
},
|
||||
}
|
||||
|
||||
@ -491,58 +487,48 @@ func initConfig() {
|
||||
* default route, so if route change on jailhost this will reflect on jail next
|
||||
* start)
|
||||
*******************************************************************************/
|
||||
func WriteConfigToDisk(jailName string, changeauto bool, forceWrite bool) {
|
||||
for _, j := range gJails {
|
||||
if len(jailName) > 0 && j.Name == jailName || len(jailName) == 0 {
|
||||
if j.ConfigUpdated || forceWrite {
|
||||
log.Debug("%s config has changed, write changes to disk\n", j.Name)
|
||||
func WriteConfigToDisk(j *Jail, changeauto bool) {
|
||||
// we will manipulate properties so get a copy
|
||||
jc := j.Config
|
||||
|
||||
// we will manipulate properties so get a copy
|
||||
jc := j.Config
|
||||
if changeauto == false {
|
||||
// Overwrite "auto" properties
|
||||
ondiskjc, err := getJailConfig(j.ConfigPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// TODO : List all fields, then call getStructFieldValue to compare value with "auto"
|
||||
// If "auto" then keep it that way before writing ondiskjc to disk
|
||||
var properties []string
|
||||
properties = getStructFieldNames(ondiskjc, properties, "")
|
||||
|
||||
if changeauto == false {
|
||||
// Overwrite "auto" properties
|
||||
ondiskjc, err := getJailConfig(j.ConfigPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// TODO : List all fields, then call getStructFieldValue to compare value with "auto"
|
||||
// If "auto" then keep it that way before writing ondiskjc to disk
|
||||
var properties []string
|
||||
properties = getStructFieldNames(ondiskjc, properties, "")
|
||||
|
||||
for _, p := range properties {
|
||||
v, _, err := getStructFieldValue(ondiskjc, p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if v.String() == "auto" {
|
||||
err = setStructFieldValue(&jc, p, "auto")
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR sanitizing config: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
marshaled, err := json.MarshalIndent(jc, "", " ")
|
||||
for _, p := range properties {
|
||||
v, _, err := getStructFieldValue(ondiskjc, p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if v.String() == "auto" {
|
||||
err = setStructFieldValue(&jc, p, "auto")
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR marshaling config: %s\n", err.Error())
|
||||
}
|
||||
|
||||
//fmt.Printf("DEBUG: Will write config to disk, with content:\n")
|
||||
//fmt.Printf(string(marshaled))
|
||||
fmt.Printf("DEBUG: Will write config to disk, Config.Release=%s\n", jc.Release)
|
||||
fmt.Printf("DEBUG: Will write config to disk, Config.Last_started=%s\n", jc.Last_started)
|
||||
|
||||
if os.WriteFile(j.ConfigPath, []byte(marshaled), 0644); err != nil {
|
||||
fmt.Printf("Error writing config file %s: %v\n", j.ConfigPath, err)
|
||||
fmt.Printf("ERROR sanitizing config: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
marshaled, err := json.MarshalIndent(jc, "", " ")
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR marshaling config: %s\n", err.Error())
|
||||
}
|
||||
|
||||
//fmt.Printf("DEBUG: Will write config to disk, with content:\n")
|
||||
//fmt.Printf(string(marshaled))
|
||||
|
||||
if os.WriteFile(j.ConfigPath, []byte(marshaled), 0644); err != nil {
|
||||
fmt.Printf("Error writing config file %s: %v\n", j.ConfigPath, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user