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) {
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(),

View file

@ -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"

View file

@ -341,7 +341,11 @@ class UptimeKumaServer {
* @returns {Promise<void>}
*/
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>}
*/
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");

View file

@ -150,6 +150,43 @@
</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 -->
<div class="mb-4">
<label class="form-label">

View file

@ -449,9 +449,10 @@
"Server Timezone": "Server Timezone",
"statusPageMaintenanceEndDate": "End",
"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",
"Disable": "Disable",
"enableNSCD": "Enable NSCD (Name Service Cache Daemon) for caching all DNS requests",
"chromeExecutable": "Chrome/Chromium Executable",
"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.",

View file

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

View file

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