Browse Source

set real basepath if dev flag is set

reid 2 năm trước cách đây
mục cha
commit
610f9a6c5a
5 tập tin đã thay đổi với 31 bổ sung33 xóa
  1. 1 1
      broadcast/broadcast.go
  2. 8 0
      config/config.go
  3. 3 0
      docker/docker.go
  4. 2 2
      main.go
  5. 17 30
      settings/system.json

+ 1 - 1
broadcast/broadcast.go

@@ -160,7 +160,7 @@ func constructPierInfo(piers []string) (map[string]structs.Urbit, error) {
 		}
 		urbit.Info.Running = isRunning
 		urbit.Info.Network = shipNetworks[pier]
-		urbit.Info.URL = "http://" + hostName + ":" + string(dockerConfig.HTTPPort)
+		urbit.Info.URL = fmt.Sprintf("http://%s.local:%d", hostName, dockerConfig.HTTPPort)
 		urbit.Info.LoomSize = int(math.Pow(2, float64(dockerConfig.LoomSize)) / math.Pow(1024, 2))
 		urbit.Info.DiskUsage = dockerStats.DiskUsage
 		urbit.Info.MemUsage = dockerStats.MemoryUsage

+ 8 - 0
config/config.go

@@ -32,6 +32,7 @@ var (
 	HttpOpen           = false
 	UploadSecret       string
 	checkInterval	   = 5 * time.Minute
+	stagingMode		   = os.Getenv("ENVIRONMENT")
 	confMutex          sync.Mutex
 	versMutex          sync.Mutex
 )
@@ -44,6 +45,13 @@ func init() {
 		errmsg := fmt.Sprintf("Couldn't get cwd: %v", err)
 		logger.Error(errmsg)
 	}
+	for _, arg := range os.Args[1:] {
+		if arg == "dev" {
+			BasePath = "/opt/nativeplanet/groundseg"
+		}
+	}
+	pathMsg := fmt.Sprintf("Loading configs from %s",BasePath)
+	logger.Info(pathMsg)
 	confPath := filepath.Join(BasePath, "settings", "system.json")
 	file, err := os.Open(confPath)
 	if err != nil {

+ 3 - 0
docker/docker.go

@@ -54,6 +54,8 @@ func GetShipStatus(patps []string) (map[string]string, error) {
 	}
 }
 
+
+// return the name of a container's network
 func GetContainerNetwork(name string) (string, error) {
 	cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
 	if err != nil {
@@ -70,6 +72,7 @@ func GetContainerNetwork(name string) (string, error) {
 	return "", fmt.Errorf("container is not attached to any network")
 }
 
+// return the disk and memory usage for a container
 func GetContainerStats(containerName string) (structs.ContainerStats, error) {
 	var res structs.ContainerStats
 	cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())

+ 2 - 2
main.go

@@ -14,7 +14,7 @@ import (
 
 var (
 	logger  = slog.New(slog.NewJSONHandler(os.Stdout, nil))
-	devMode = false
+	DevMode = false
 )
 
 func loadService(loadFunc func() error, errMsg string) {
@@ -30,7 +30,7 @@ func main() {
 		// trigger this with `./groundseg dev`
 		if arg == "dev" {
 			logger.Info("Starting GroundSeg in debug mode")
-			devMode = true
+			DevMode = true
 		}
 	}
 	logger.Info("Starting GroundSeg")

+ 17 - 30
settings/system.json

@@ -1,30 +1,17 @@
 {
-    "setup": "complete",
-    "endpointUrl": "dev-api.nativeplanet.live",
+    "setup": "start",
+    "endpointUrl": "api.startram.io",
     "apiVersion": "v1",
-    "piers": [
-        "widwet-mornev-nallux-dozryl",
-        "hocfur-wicnym-nallux-dozryl",
-        "pinlyd-mattyd-nallux-dozryl",
-        "solnys-dibmyn-nallux-dozryl",
-        "wormun-fadwyl-nallux-dozryl",
-        "nopmul-pollyt",
-        "nalruc-nallux-dozryl"
-    ],
+    "piers": [],
     "netCheck": "1.1.1.1:53",
     "updateMode": "auto",
     "updateUrl": "https://version.groundseg.app",
     "updateBranch": "latest",
-    "swapVal": 6,
-    "swapFile": "/opt/nativeplanet/groundseg/swapfile",
-    "keyFile": "/opt/nativeplanet/groundseg/settings/session.key",
+    "swapVal": 16,
+    "swapFile": "settings/swapfile",
+    "keyFile": "settings/session.key",
     "sessions": {
-        "authorized": {
-            "fvu1fml32XNQvsZzWhPFwa6Yjw4eDmva": {
-                "hash": "c1dec51a9ca38ada94a22cebbdc7b60378f53fbedb338df670a3f13373cca58c",
-                "created": "2023-08-11_17:16:05"
-            }
-        },
+        "authorized": {},
         "unauthorized": {}
     },
     "linuxUpdates": {
@@ -33,17 +20,17 @@
         "previous": false
     },
     "dockerData": "/var/lib/docker",
-    "wgOn": true,
-    "wgRegistered": true,
-    "pwHash": "privateprivate",
+    "wgOn": false,
+    "wgRegistered": false,
+    "pwHash": "",
     "c2cInterval": 0,
     "firstBoot": false,
     "wgRegisterd": false,
     "gsVersion": "v2.0.0",
-    "CFG_DIR": "/opt/nativeplanet/groundseg",
-    "updateInterval": 3600,
-    "binHash": "58041cd66c692cddd09e83dedf6c803c1a1a5a46a6cc28167a3fb3e736f3e160",
-    "pubkey": "a1c5VlArTGNXY25vM24zeCtoYUlJOGVUVW5EYjdESEU5VVRoZzN2VHp4Zz0K",
-    "privkey": "cuwW3f4mM1JDxFVq/S8bcRFewY77kY6a6bhi3dQV8NY=",
-    "salt": "privateprivate"
-}
+    "CFG_DIR": "",
+    "updateInterval": 0,
+    "binHash": "",
+    "pubkey": "",
+    "privkey": "",
+    "salt": ""
+}