Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an ability to enable/disable nscd #3652

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
WIP
  • Loading branch information
louislam committed Aug 27, 2023
commit 057db464107646cff5dcec08bcc9c6013a332f13
3 changes: 3 additions & 0 deletions server/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
10 changes: 10 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"
Expand Down
16 changes: 12 additions & 4 deletions server/uptime-kuma-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,22 +341,30 @@ class UptimeKumaServer {
* @returns {Promise<void>}
*/
async start() {
this.startServices();
let enable = await Settings.get("nscd");

if (enable || enable === undefined) {
this.startNSCDServices();
}
}

/**
* Stop the server
* @returns {Promise<void>}
*/
async stop() {
this.stopServices();
let enable = await Settings.get("nscd");

if (enable || enable === undefined) {
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");
Expand All @@ -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");
Expand Down
37 changes: 37 additions & 0 deletions src/components/settings/General.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,43 @@
</div>
</div>

<!-- DNS Cache (nscd) -->
<div 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">
Expand Down
3 changes: 2 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
4 changes: 4 additions & 0 deletions src/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down