summaryrefslogtreecommitdiff
path: root/configfiles.go
diff options
context:
space:
mode:
Diffstat (limited to 'configfiles.go')
-rw-r--r--configfiles.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/configfiles.go b/configfiles.go
index 5c2b0f6..4ea72e0 100644
--- a/configfiles.go
+++ b/configfiles.go
@@ -84,16 +84,37 @@ func readConfigFile(filename string) error {
}
func writeConfigFile() {
+ test := time.Now().Format("YYYYMMDD-HH-MM")
+ if !writeConfigFileTmp("virtigo.json.new." + test) {
+ log.Println("config file write error")
+ os.Exit(-1)
+ }
+ if !writeConfigFileTmp("virtigo.json") {
+ log.Println("config file write error")
+ os.Exit(-1)
+ }
+
+ origname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "virtigo.json")
+ newname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "virtigo.json.old")
+ err := os.Rename(origname, newname)
+ if err != nil {
+ log.Printf("rename fail: %s", err)
+ os.Exit(-1)
+ }
+}
+
+func writeConfigFileTmp(filename string) bool {
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "virtigo.json")
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
defer cfgfile.Close()
if err != nil {
log.Info("open config file :", err)
- return
+ return false
}
json := me.cluster.FormatJSON()
fmt.Fprintln(cfgfile, json)
log.Info("Write:", fullname, "OK")
+ return true
}
func writeConfigFileDroplets() {