Browse Source

Fix hostname and pid_file errors

- Add missing pid_file config default
- Replace hostname command with /proc/sys/kernel/hostname
- Add fallback random ID if no hostname
Luis Rosales 2 months ago
parent
commit
d8f4538c10
1 changed files with 11 additions and 3 deletions
  1. 11 3
      package/src/client2server-unified.lua

+ 11 - 3
package/src/client2server-unified.lua

@@ -16,6 +16,7 @@ local cfg = {
     log_level = "info",
     buffer_file = "/tmp/event_buffer",
     max_buffer = 100,
+    pid_file = "/var/run/client2server.pid",
     -- Server
     server_url = os.getenv("SERVER_URL") or "wss://your-server.com:3843",
     server_token = os.getenv("SERVER_TOKEN") or "secret-token",
@@ -70,9 +71,16 @@ pcall(function()
 end)
 
 if cfg.router_id == "" then
-    local f = io.popen("hostname")
-    cfg.router_id = f and (f:read("*a") or ""):gsub("%s+$", "") or "unknown"
-    if f then f:close() end
+    -- Try multiple methods to get hostname
+    local f = io.popen("cat /proc/sys/kernel/hostname 2>/dev/null")
+    if f then
+        cfg.router_id = f:read("*a") or "unknown"
+        f:close()
+    end
+    if cfg.router_id == "" or not cfg.router_id then
+        cfg.router_id = "router-" .. math.random(1000, 9999)
+    end
+    cfg.router_id = cfg.router_id:gsub("%s+$", "")
 end
 
 -- ============================================================================