keep backups of the config files

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-24 09:27:23 -05:00
parent acdd6e9c5b
commit aa742d099d
3 changed files with 21 additions and 13 deletions

View File

@ -10,8 +10,7 @@ all:
./virtigo --help ./virtigo --help
xml-add: xml-add:
./virtigo --add-xml /home/nfs3/xml/*.xml ./virtigo --add-xml /tmp/xml/*.xml
# ./virtigo --add-xml /etc/libvirt/qemu/*xml
start-all-droplets: start-all-droplets:
curl --silent http://localhost:8080/start?start=git.wit.org curl --silent http://localhost:8080/start?start=git.wit.org

10
argv.go
View File

@ -11,12 +11,12 @@ import "go.wit.com/log"
var argv args var argv args
type args struct { type args struct {
Dir string `arg:"--dir" help:"defaults to ~/.config/virtigo/"` Xml []string `arg:"--add-xml" help:"add libvirt xml files"`
Port int `arg:"--port" default:"8080" help:"specify a different default port"` CfgDir string `arg:"--dir" help:"defaults to ~/.config/virtigo/"`
Hosts []string `arg:"--hosts" help:"hosts to connect to"` Hosts []string `arg:"--hosts" help:"hosts to connect to"`
Port int `arg:"--port" default:"8080" help:"allow droplet events via http"`
Uptime bool `arg:"--uptime" default:"true" help:"allow uptime checks for things like Kuma"` Uptime bool `arg:"--uptime" default:"true" help:"allow uptime checks for things like Kuma"`
Daemon bool `arg:"--daemon" help:"run in daemon mode"` Daemon bool `arg:"--daemon" help:"run in daemon mode"`
Xml []string `arg:"--add-xml" help:"add libvirt xml files"`
Save bool `arg:"--save" default:"false" help:"save xml changes to the protobuf values"` Save bool `arg:"--save" default:"false" help:"save xml changes to the protobuf values"`
} }
@ -24,7 +24,9 @@ func (a args) Description() string {
return ` return `
virtigo will help control your cluster of hypervisiors virtigo will help control your cluster of hypervisiors
go install go.wit.com/apps/virtigo@latest This maintains a master list of all your vm's (aka 'droplets')
in your homelab cloud. You can import libvirt xml files.
This app talks to your hypervisors via the virtigod daemon.
` `
} }

View File

@ -84,12 +84,14 @@ func readConfigFile(filename string) error {
} }
func writeConfigFile() { func writeConfigFile() {
test := time.Now().Format("YYYYMMDD-HH-MM") // Get the current time
if !writeConfigFileTmp("virtigo.json.new." + test) { now := time.Now()
log.Println("config file write error")
os.Exit(-1) // Format the time to match your desired format: YYYY.MM.DD.HHMMSS
} timestamp := now.Format("2006.01.02.150405")
if !writeConfigFileTmp("virtigo.json") {
filename := "virtigo.json.new." + timestamp
if !writeConfigFileTmp(filename) {
log.Println("config file write error") log.Println("config file write error")
os.Exit(-1) os.Exit(-1)
} }
@ -101,10 +103,15 @@ func writeConfigFile() {
log.Printf("rename fail: %s", err) log.Printf("rename fail: %s", err)
os.Exit(-1) os.Exit(-1)
} }
if !writeConfigFileTmp("virtigo.json") {
log.Println("config file write error")
os.Exit(-1)
}
} }
func writeConfigFileTmp(filename string) bool { func writeConfigFileTmp(filename string) bool {
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "virtigo.json") fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), filename)
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666) cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
defer cfgfile.Close() defer cfgfile.Close()
if err != nil { if err != nil {