v0.36b: fix writeConfigToDisk
This commit is contained in:
parent
310564b4af
commit
24439a8181
@ -118,6 +118,7 @@ func SetJailProperties(args []string) {
|
||||
gJails[i].ConfigUpdated = true
|
||||
}
|
||||
}
|
||||
WriteConfigToDisk(&gJails[i], false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
18
cmd/root.go
18
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,12 +487,7 @@ 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
|
||||
|
||||
@ -533,17 +524,12 @@ func WriteConfigToDisk(jailName string, changeauto bool, forceWrite bool) {
|
||||
|
||||
//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)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func Execute() {
|
||||
|
@ -1365,7 +1365,7 @@ func StartJail(args []string) {
|
||||
}
|
||||
|
||||
// Synchronize jail config to disk
|
||||
WriteConfigToDisk(cj.Name, false, false)
|
||||
WriteConfigToDisk(cj, false)
|
||||
|
||||
start_cmd := fmt.Sprintf("/usr/sbin/jail -f /var/run/jail.%s.conf -c", cj.InternalName)
|
||||
|
||||
@ -1512,10 +1512,11 @@ func StartJail(args []string) {
|
||||
// TODO: Apply rctl
|
||||
|
||||
// Update last_started
|
||||
// 23/07/2023 : This is not working, when writing to disk the old value is used
|
||||
dt := time.Now()
|
||||
curDate := fmt.Sprintf("%s", dt.Format("2006-01-02 15:04:05"))
|
||||
fmt.Sprintf(cj.Config.Last_started, curDate)
|
||||
WriteConfigToDisk(cj.Name, false, true)
|
||||
cj.Config.Last_started = curDate
|
||||
WriteConfigToDisk(cj, false)
|
||||
|
||||
|
||||
/*
|
||||
|
16
cmd/stop.go
16
cmd/stop.go
@ -290,16 +290,8 @@ func StopJail(args []string) {
|
||||
return
|
||||
}
|
||||
cvers = strings.TrimRight(cvers, "\n")
|
||||
|
||||
//fmt.Sprintf(cj.Config.Release, cvers)
|
||||
//cj.Config.Release = cvers
|
||||
//cj.ConfigUpdated = true
|
||||
|
||||
// This is working in this context, but value is not available in WriteConfigToDisk context :/
|
||||
setStructFieldValue(cj, "Config.Release", cvers)
|
||||
//fmt.Printf("DEBUG: release was set, now is : %s\n", cj.Config.Release)
|
||||
|
||||
// We need to get the real Config object, not a copy of it
|
||||
cj.Config.Release = cvers
|
||||
WriteConfigToDisk(cj, false)
|
||||
|
||||
out, err := executeCommand(fmt.Sprintf("rctl jail:%s", cj.InternalName))
|
||||
if err == nil && len(out) > 0 {
|
||||
@ -464,9 +456,7 @@ func StopJail(args []string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//fmt.Printf("DEBUG: release = %s\n", cj.Config.Release)
|
||||
WriteConfigToDisk(cj.Name, false, true)
|
||||
WriteConfigToDisk(cj, false)
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user