Fix migration of services on nodes without any services (#1660)

* Fix migration of services on nodes without any services

* Correctly handle first creation and last deletion.
This commit is contained in:
Tim Wilkinson 2024-10-29 09:48:00 -07:00 committed by GitHub
parent da9417a512
commit 1a49da92ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

View File

@ -37,7 +37,15 @@ if (request.env.REQUEST_METHOD === "PUT") {
configuration.prepareChanges(); configuration.prepareChanges();
if ("services" in request.args) { if ("services" in request.args) {
const services = json(request.args.services); const services = json(request.args.services);
if (!uciMesh.get("setup", "services")) {
uciMesh.set("setup", "services", "services");
}
if (length(services)) {
uciMesh.set("setup", "services", "service", services); uciMesh.set("setup", "services", "service", services);
}
else {
uciMesh.delete("setup", "services", "service");
}
uciMesh.commit("setup"); uciMesh.commit("setup");
} }
if ("aliases" in request.args) { if ("aliases" in request.args) {
@ -108,7 +116,7 @@ const ae = iptoarr(dhcp.end);
const reService = regexp("^([^|]+)\\|1\\|([^|]+)\\|([^|]+)\\|(\\d+)\\|(.*)$"); const reService = regexp("^([^|]+)\\|1\\|([^|]+)\\|([^|]+)\\|(\\d+)\\|(.*)$");
const reLink = regexp("^([^|]+)\\|0\\|\\|([^|]+)\\|\\|$"); const reLink = regexp("^([^|]+)\\|0\\|\\|([^|]+)\\|\\|$");
const reType = regexp("^(.+) \\[([a-z]+)\\]$"); const reType = regexp("^(.+) \\[([a-z]+)\\]$");
const svcs = uciMesh.get("setup", "services", "service"); const svcs = uciMesh.get("setup", "services", "service") || [];
for (let i = 0; i < length(svcs); i++) { for (let i = 0; i < length(svcs); i++) {
const l = trim(svcs[i]); const l = trim(svcs[i]);
const v = match(l, reService); const v = match(l, reService);

View File

@ -55,7 +55,7 @@
} }
f.close(); f.close();
} }
const svcs = uciMesh.get("setup", "services", "service"); const svcs = uciMesh.get("setup", "services", "service") || [];
for (let i = 0; i < length(svcs); i++) { for (let i = 0; i < length(svcs); i++) {
const l = trim(svcs[i]); const l = trim(svcs[i]);
const v = match(l, reService); const v = match(l, reService);

View File

@ -127,7 +127,7 @@ local function get(validate)
end end
-- load the services -- load the services
local svcs = uci.cursor("/etc/config.mesh"):get_all("setup", "services", "service") local svcs = uci.cursor("/etc/config.mesh"):get_all("setup", "services", "service") or {}
for _, svc in ipairs(svcs) for _, svc in ipairs(svcs)
do do
local name, link, proto, host, port, sffx = svc:match("(.*)|(.*)|(.*)|(.*)|(.*)|(.*)") local name, link, proto, host, port, sffx = svc:match("(.*)|(.*)|(.*)|(.*)|(.*)|(.*)")