@tyevco/homelab-lxc-agent 1.9.2 → 1.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.js +20 -3
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -54,19 +54,32 @@ function createAgentServer(config) {
|
|
|
54
54
|
const httpServer = (0, http_1.createServer)();
|
|
55
55
|
const io = new socket_io_1.Server(httpServer);
|
|
56
56
|
let capabilities = { lxcAvailable: false };
|
|
57
|
-
|
|
57
|
+
// Maps socket → endpoint so rescan can push per-connection data
|
|
58
|
+
const authenticatedSockets = new Map();
|
|
58
59
|
const emitInfo = (socket) => {
|
|
59
60
|
socket.emit("info", {
|
|
60
61
|
version: config.version,
|
|
61
62
|
...capabilities,
|
|
62
63
|
});
|
|
63
64
|
};
|
|
65
|
+
const pushContainerList = async (socket, endpoint) => {
|
|
66
|
+
const list = await lxc.getContainerList(endpoint);
|
|
67
|
+
console.log(`[lxc] Pushing container list to main server (${Object.keys(list).length} container(s))`);
|
|
68
|
+
socket.emit("agent", "lxcContainerList", { ok: true,
|
|
69
|
+
lxcContainerList: list,
|
|
70
|
+
endpoint });
|
|
71
|
+
};
|
|
64
72
|
const rescan = async () => {
|
|
65
73
|
console.log("[agent] Scanning capabilities...");
|
|
66
74
|
capabilities = await detectCapabilities();
|
|
67
|
-
for (const socket of authenticatedSockets) {
|
|
75
|
+
for (const [socket] of authenticatedSockets) {
|
|
68
76
|
emitInfo(socket);
|
|
69
77
|
}
|
|
78
|
+
if (capabilities.lxcAvailable) {
|
|
79
|
+
for (const [socket, endpoint] of authenticatedSockets) {
|
|
80
|
+
pushContainerList(socket, endpoint).catch((e) => console.error("[lxc] Failed to push container list during rescan:", e instanceof Error ? e.message : e));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
70
83
|
};
|
|
71
84
|
// Initial scan, then periodic rescan
|
|
72
85
|
rescan().then(() => {
|
|
@@ -97,9 +110,13 @@ function createAgentServer(config) {
|
|
|
97
110
|
const { username, password } = data;
|
|
98
111
|
if (username === config.username && password === config.password) {
|
|
99
112
|
loggedIn = true;
|
|
100
|
-
authenticatedSockets.
|
|
113
|
+
authenticatedSockets.set(socket, endpoint);
|
|
101
114
|
console.log(`[agent] Authenticated as ${username}`);
|
|
102
115
|
cb?.({ ok: true });
|
|
116
|
+
// Immediately push the container list so the main server doesn't have to ask
|
|
117
|
+
if (capabilities.lxcAvailable) {
|
|
118
|
+
pushContainerList(socket, endpoint).catch((e) => console.error("[lxc] Failed to push initial container list:", e instanceof Error ? e.message : e));
|
|
119
|
+
}
|
|
103
120
|
}
|
|
104
121
|
else {
|
|
105
122
|
console.warn(`[agent] Login failed for ${username}`);
|