From cd79df07e1996682900aaf9da99325f4edc994b2 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Mon, 28 Aug 2023 16:15:48 +0800 Subject: [PATCH] Add an ability to enable/disable nscd (#3652) --- server/client.js | 3 +++ server/server.js | 10 ++++++++ server/uptime-kuma-server.js | 16 +++++++++---- src/components/settings/General.vue | 37 +++++++++++++++++++++++++++++ src/lang/en.json | 3 ++- src/pages/EditMonitor.vue | 2 +- src/pages/Settings.vue | 4 ++++ 7 files changed, 69 insertions(+), 6 deletions(-) diff --git a/server/client.js b/server/client.js index 2e3bd43b7..7891dd166 100644 --- a/server/client.js +++ b/server/client.js @@ -147,15 +147,18 @@ async function sendAPIKeyList(socket) { async function sendInfo(socket, hideVersion = false) { let version; let latestVersion; + let isContainer; if (!hideVersion) { version = checkVersion.version; latestVersion = checkVersion.latestVersion; + isContainer = (process.env.UPTIME_KUMA_IS_CONTAINER === "1"); } socket.emit("info", { version, latestVersion, + isContainer, primaryBaseURL: await setting("primaryBaseURL"), serverTimezone: await server.getTimezone(), serverTimezoneOffset: server.getTimezoneOffset(), diff --git a/server/server.js b/server/server.js index 59957ba96..25a7d4725 100644 --- a/server/server.js +++ b/server/server.js @@ -1194,6 +1194,7 @@ let needSetup = false; } const previousChromeExecutable = await Settings.get("chromeExecutable"); + const previousNSCDStatus = await Settings.get("nscd"); await setSettings("general", data); server.entryPage = data.entryPage; @@ -1211,6 +1212,15 @@ let needSetup = false; await resetChrome(); } + // Update nscd status + if (previousNSCDStatus !== data.nscd) { + if (data.nscd) { + server.startNSCDServices(); + } else { + server.stopNSCDServices(); + } + } + callback({ ok: true, msg: "Saved" diff --git a/server/uptime-kuma-server.js b/server/uptime-kuma-server.js index 7817c9e1c..6acc8d4df 100644 --- a/server/uptime-kuma-server.js +++ b/server/uptime-kuma-server.js @@ -341,7 +341,11 @@ class UptimeKumaServer { * @returns {Promise} */ async start() { - this.startServices(); + let enable = await Settings.get("nscd"); + + if (enable || enable === null) { + this.startNSCDServices(); + } } /** @@ -349,14 +353,18 @@ class UptimeKumaServer { * @returns {Promise} */ async stop() { - this.stopServices(); + let enable = await Settings.get("nscd"); + + if (enable || enable === null) { + this.stopNSCDServices(); + } } /** * Start all system services (e.g. nscd) * For now, only used in Docker */ - startServices() { + startNSCDServices() { if (process.env.UPTIME_KUMA_IS_CONTAINER) { try { log.info("services", "Starting nscd"); @@ -370,7 +378,7 @@ class UptimeKumaServer { /** * Stop all system services */ - stopServices() { + stopNSCDServices() { if (process.env.UPTIME_KUMA_IS_CONTAINER) { try { log.info("services", "Stopping nscd"); diff --git a/src/components/settings/General.vue b/src/components/settings/General.vue index 9f9a88b65..f8a0d48f2 100644 --- a/src/components/settings/General.vue +++ b/src/components/settings/General.vue @@ -150,6 +150,43 @@ + +
+ + +
+ + +
+ +
+ + +
+
+