Add an ability to enable/disable nscd (#3652)

This commit is contained in:
Louis Lam 2023-08-28 16:15:48 +08:00 committed by GitHub
parent 0c40f02584
commit cd79df07e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 69 additions and 6 deletions

View file

@ -147,15 +147,18 @@ async function sendAPIKeyList(socket) {
async function sendInfo(socket, hideVersion = false) { async function sendInfo(socket, hideVersion = false) {
let version; let version;
let latestVersion; let latestVersion;
let isContainer;
if (!hideVersion) { if (!hideVersion) {
version = checkVersion.version; version = checkVersion.version;
latestVersion = checkVersion.latestVersion; latestVersion = checkVersion.latestVersion;
isContainer = (process.env.UPTIME_KUMA_IS_CONTAINER === "1");
} }
socket.emit("info", { socket.emit("info", {
version, version,
latestVersion, latestVersion,
isContainer,
primaryBaseURL: await setting("primaryBaseURL"), primaryBaseURL: await setting("primaryBaseURL"),
serverTimezone: await server.getTimezone(), serverTimezone: await server.getTimezone(),
serverTimezoneOffset: server.getTimezoneOffset(), serverTimezoneOffset: server.getTimezoneOffset(),

View file

@ -1194,6 +1194,7 @@ let needSetup = false;
} }
const previousChromeExecutable = await Settings.get("chromeExecutable"); const previousChromeExecutable = await Settings.get("chromeExecutable");
const previousNSCDStatus = await Settings.get("nscd");
await setSettings("general", data); await setSettings("general", data);
server.entryPage = data.entryPage; server.entryPage = data.entryPage;
@ -1211,6 +1212,15 @@ let needSetup = false;
await resetChrome(); await resetChrome();
} }
// Update nscd status
if (previousNSCDStatus !== data.nscd) {
if (data.nscd) {
server.startNSCDServices();
} else {
server.stopNSCDServices();
}
}
callback({ callback({
ok: true, ok: true,
msg: "Saved" msg: "Saved"

View file

@ -341,7 +341,11 @@ class UptimeKumaServer {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async start() { async start() {
this.startServices(); let enable = await Settings.get("nscd");
if (enable || enable === null) {
this.startNSCDServices();
}
} }
/** /**
@ -349,14 +353,18 @@ class UptimeKumaServer {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async stop() { async stop() {
this.stopServices(); let enable = await Settings.get("nscd");
if (enable || enable === null) {
this.stopNSCDServices();
}
} }
/** /**
* Start all system services (e.g. nscd) * Start all system services (e.g. nscd)
* For now, only used in Docker * For now, only used in Docker
*/ */
startServices() { startNSCDServices() {
if (process.env.UPTIME_KUMA_IS_CONTAINER) { if (process.env.UPTIME_KUMA_IS_CONTAINER) {
try { try {
log.info("services", "Starting nscd"); log.info("services", "Starting nscd");
@ -370,7 +378,7 @@ class UptimeKumaServer {
/** /**
* Stop all system services * Stop all system services
*/ */
stopServices() { stopNSCDServices() {
if (process.env.UPTIME_KUMA_IS_CONTAINER) { if (process.env.UPTIME_KUMA_IS_CONTAINER) {
try { try {
log.info("services", "Stopping nscd"); log.info("services", "Stopping nscd");

View file

@ -150,6 +150,43 @@
</div> </div>
</div> </div>
<!-- DNS Cache (nscd) -->
<div v-if="$root.info.isContainer" class="mb-4">
<label class="form-label">
{{ $t("enableNSCD") }}
</label>
<div class="form-check">
<input
id="nscdEnable"
v-model="settings.nscd"
class="form-check-input"
type="radio"
name="nscd"
:value="true"
required
/>
<label class="form-check-label" for="nscdEnable">
{{ $t("Enable") }}
</label>
</div>
<div class="form-check">
<input
id="nscdDisable"
v-model="settings.nscd"
class="form-check-input"
type="radio"
name="nscd"
:value="false"
required
/>
<label class="form-check-label" for="nscdDisable">
{{ $t("Disable") }}
</label>
</div>
</div>
<!-- DNS Cache --> <!-- DNS Cache -->
<div class="mb-4"> <div class="mb-4">
<label class="form-label"> <label class="form-label">

View file

@ -449,9 +449,10 @@
"Server Timezone": "Server Timezone", "Server Timezone": "Server Timezone",
"statusPageMaintenanceEndDate": "End", "statusPageMaintenanceEndDate": "End",
"IconUrl": "Icon URL", "IconUrl": "Icon URL",
"Enable DNS Cache": "Enable DNS Cache for HTTP(s) monitors", "Enable DNS Cache": "(Deprecated) Enable DNS Cache for HTTP(s) monitors",
"Enable": "Enable", "Enable": "Enable",
"Disable": "Disable", "Disable": "Disable",
"enableNSCD": "Enable NSCD (Name Service Cache Daemon) for caching all DNS requests",
"chromeExecutable": "Chrome/Chromium Executable", "chromeExecutable": "Chrome/Chromium Executable",
"chromeExecutableAutoDetect": "Auto Detect", "chromeExecutableAutoDetect": "Auto Detect",
"chromeExecutableDescription": "For Docker users, if Chromium is not yet installed, it may take a few minutes to install and display the test result. It takes 1GB of disk space.", "chromeExecutableDescription": "For Docker users, if Chromium is not yet installed, it may take a few minutes to install and display the test result. It takes 1GB of disk space.",

View file

@ -82,7 +82,7 @@
<option value="redis"> <option value="redis">
Redis Redis
</option> </option>
<option value="tailscale-ping"> <option v-if="$root.info.isContainer" value="tailscale-ping">
Tailscale Ping Tailscale Ping
</option> </option>
</optgroup> </optgroup>

View file

@ -163,6 +163,10 @@ export default {
this.settings.entryPage = "dashboard"; this.settings.entryPage = "dashboard";
} }
if (this.settings.nscd === undefined) {
this.settings.nscd = true;
}
if (this.settings.dnsCache === undefined) { if (this.settings.dnsCache === undefined) {
this.settings.dnsCache = false; this.settings.dnsCache = false;
} }