summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-23 00:48:35 -0500
committerJeff Carr <[email protected]>2024-10-23 00:48:35 -0500
commit62d406e0de0fcfe373ae45ed8920dc8a9e3e1034 (patch)
tree30263802857ebdf488f70c61d1a55b7b5b290d84
parenta3ea303ab86e5db6510a00e373b6e7a6620d426a (diff)
set a homedir
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--Makefile3
-rw-r--r--configfiles.go21
-rw-r--r--http.go1
-rw-r--r--main.go24
-rw-r--r--structs.go2
5 files changed, 37 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index b3133ae..07bd16c 100644
--- a/Makefile
+++ b/Makefile
@@ -30,6 +30,9 @@ curl-uptime:
curl-droplets:
curl --silent http://localhost:8080/droplets
+curl-writeconfig:
+ curl --silent http://localhost:8080/writeconfig
+
# this is for release builds using the go.mod files
release-build:
@echo ${REDOMOD}
diff --git a/configfiles.go b/configfiles.go
index 3146e1b..0eca9a7 100644
--- a/configfiles.go
+++ b/configfiles.go
@@ -12,8 +12,7 @@ import (
func readConfigFile() {
me.cluster = new(pb.Cluster)
- homeDir, _ := os.UserHomeDir()
- fullname := filepath.Join(homeDir, ".config/virtigo.json")
+ fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "virtigo.json")
pfile, err := os.ReadFile(fullname)
if err != nil {
log.Info("open config file :", err)
@@ -57,8 +56,7 @@ func readConfigFile() {
}
func writeConfigFile() {
- homeDir, _ := os.UserHomeDir()
- fullname := filepath.Join(homeDir, ".config/virtigo.json")
+ 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 {
@@ -67,4 +65,19 @@ func writeConfigFile() {
}
json := me.cluster.FormatJSON()
fmt.Fprintln(cfgfile, json)
+ log.Info("Write:", fullname, "OK")
+}
+
+func writeConfigFileDroplets() {
+ fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "droplets.text")
+ 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
+ }
+ // text := me.cluster.Droplets.FormatTEXT()
+ text := me.cluster.FormatTEXT()
+ fmt.Fprintln(cfgfile, text)
+ log.Info("Write:", fullname, "OK")
}
diff --git a/http.go b/http.go
index cf6ad67..1d201f8 100644
--- a/http.go
+++ b/http.go
@@ -58,6 +58,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
if tmp == "/writeconfig" {
writeConfigFile()
+ writeConfigFileDroplets()
fmt.Fprintln(w, "OK")
return
}
diff --git a/main.go b/main.go
index 169dcf5..f97f891 100644
--- a/main.go
+++ b/main.go
@@ -6,6 +6,7 @@ import (
"embed"
"fmt"
"os"
+ "path/filepath"
"time"
"go.wit.com/dev/alexflint/arg"
@@ -18,6 +19,11 @@ var Version string
var resources embed.FS
func main() {
+ if os.Getenv("VIRTIGO_HOME") == "" {
+ homeDir, _ := os.UserHomeDir()
+ fullpath := filepath.Join(homeDir, ".config/virtigo")
+ os.Setenv("VIRTIGO_HOME", fullpath)
+ }
pp := arg.MustParse(&argv)
if !argv.Uptime {
@@ -39,16 +45,16 @@ func main() {
me.delay = 5 * time.Second
/*
- log.Info("command line hypervisors:", argv.Hosts)
- for _, name := range argv.Hosts {
- h := findHypervisor(name)
- if h != nil {
- log.Info("command line hypervisor", name, "already in config file")
- continue
+ log.Info("command line hypervisors:", argv.Hosts)
+ for _, name := range argv.Hosts {
+ h := findHypervisor(name)
+ if h != nil {
+ log.Info("command line hypervisor", name, "already in config file")
+ continue
+ }
+ h = addHypervisor(name)
+ h.pb.Active = true
}
- h = addHypervisor(name)
- h.pb.Active = true
- }
*/
if argv.Start != "" {
diff --git a/structs.go b/structs.go
index b7ce4c4..0cf0176 100644
--- a/structs.go
+++ b/structs.go
@@ -24,7 +24,7 @@ type virtigoT struct {
names []string
hypers []*HyperT
droplets []*DropletT
- delay time.Duration // how often to poll the hypervisors
+ delay time.Duration // how often to poll the hypervisors
killcount int
unstable time.Time // the last time the cluster was incorrect
}