mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-02-26 21:45:57 +00:00
Compare commits
7 commits
b795d9e914
...
1e1c7c1c0a
Author | SHA1 | Date | |
---|---|---|---|
|
1e1c7c1c0a | ||
|
46d8744fa4 | ||
|
7d8dc55dbe | ||
|
fd05aad398 | ||
|
a70a2c6b35 | ||
|
2f5a6d9648 | ||
|
21a6b4a131 |
8 changed files with 135 additions and 20 deletions
|
@ -27,7 +27,6 @@ RUN mkdir ./data
|
||||||
# ⭐ Main Image
|
# ⭐ Main Image
|
||||||
############################################
|
############################################
|
||||||
FROM $BASE_IMAGE AS release
|
FROM $BASE_IMAGE AS release
|
||||||
USER node
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source="https://github.com/louislam/uptime-kuma"
|
LABEL org.opencontainers.image.source="https://github.com/louislam/uptime-kuma"
|
||||||
|
@ -46,6 +45,7 @@ CMD ["node", "server/server.js"]
|
||||||
# Rootless Image
|
# Rootless Image
|
||||||
############################################
|
############################################
|
||||||
FROM release AS rootless
|
FROM release AS rootless
|
||||||
|
USER node
|
||||||
|
|
||||||
############################################
|
############################################
|
||||||
# Mark as Nightly
|
# Mark as Nightly
|
||||||
|
|
|
@ -9,6 +9,7 @@ const mysql = require("mysql2/promise");
|
||||||
const { Settings } = require("./settings");
|
const { Settings } = require("./settings");
|
||||||
const { UptimeCalculator } = require("./uptime-calculator");
|
const { UptimeCalculator } = require("./uptime-calculator");
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
|
const { SimpleMigrationServer } = require("./utils/simple-migration-server");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database & App Data Folder
|
* Database & App Data Folder
|
||||||
|
@ -382,9 +383,11 @@ class Database {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Patch the database
|
* Patch the database
|
||||||
|
* @param {number} port Start the migration server for aggregate tables on this port if provided
|
||||||
|
* @param {string} hostname Start the migration server for aggregate tables on this hostname if provided
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async patch() {
|
static async patch(port = undefined, hostname = undefined) {
|
||||||
// Still need to keep this for old versions of Uptime Kuma
|
// Still need to keep this for old versions of Uptime Kuma
|
||||||
if (Database.dbConfig.type === "sqlite") {
|
if (Database.dbConfig.type === "sqlite") {
|
||||||
await this.patchSqlite();
|
await this.patchSqlite();
|
||||||
|
@ -409,7 +412,7 @@ class Database {
|
||||||
await R.exec("PRAGMA foreign_keys = ON");
|
await R.exec("PRAGMA foreign_keys = ON");
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.migrateAggregateTable();
|
await this.migrateAggregateTable(port, hostname);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Allow missing patch files for downgrade or testing pr.
|
// Allow missing patch files for downgrade or testing pr.
|
||||||
|
@ -735,9 +738,11 @@ class Database {
|
||||||
* Normally, it should be in transaction, but UptimeCalculator wasn't designed to be in transaction before that.
|
* Normally, it should be in transaction, but UptimeCalculator wasn't designed to be in transaction before that.
|
||||||
* I don't want to heavily modify the UptimeCalculator, so it is not in transaction.
|
* I don't want to heavily modify the UptimeCalculator, so it is not in transaction.
|
||||||
* Run `npm run reset-migrate-aggregate-table-state` to reset, in case the migration is interrupted.
|
* Run `npm run reset-migrate-aggregate-table-state` to reset, in case the migration is interrupted.
|
||||||
|
* @param {number} port Start the migration server on this port if provided
|
||||||
|
* @param {string} hostname Start the migration server on this hostname if provided
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async migrateAggregateTable() {
|
static async migrateAggregateTable(port, hostname = undefined) {
|
||||||
log.debug("db", "Enter Migrate Aggregate Table function");
|
log.debug("db", "Enter Migrate Aggregate Table function");
|
||||||
|
|
||||||
// Add a setting for 2.0.0-dev users to skip this migration
|
// Add a setting for 2.0.0-dev users to skip this migration
|
||||||
|
@ -758,6 +763,18 @@ class Database {
|
||||||
throw new Error("Aggregate table migration is already in progress");
|
throw new Error("Aggregate table migration is already in progress");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start migration server for displaying the migration status
|
||||||
|
* @type {SimpleMigrationServer}
|
||||||
|
*/
|
||||||
|
let migrationServer;
|
||||||
|
let msg;
|
||||||
|
|
||||||
|
if (port) {
|
||||||
|
migrationServer = new SimpleMigrationServer();
|
||||||
|
await migrationServer.start(port, hostname);
|
||||||
|
}
|
||||||
|
|
||||||
await Settings.set("migrateAggregateTableState", "migrating");
|
await Settings.set("migrateAggregateTableState", "migrating");
|
||||||
|
|
||||||
log.info("db", "Migrating Aggregate Table");
|
log.info("db", "Migrating Aggregate Table");
|
||||||
|
@ -777,6 +794,7 @@ class Database {
|
||||||
let count = countResult.count;
|
let count = countResult.count;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
log.warn("db", `Aggregate table ${table} is not empty, migration will not be started (Maybe you were using 2.0.0-dev?)`);
|
log.warn("db", `Aggregate table ${table} is not empty, migration will not be started (Maybe you were using 2.0.0-dev?)`);
|
||||||
|
await migrationServer?.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -811,7 +829,9 @@ class Database {
|
||||||
`, [ monitor.monitor_id, date.date ]);
|
`, [ monitor.monitor_id, date.date ]);
|
||||||
|
|
||||||
if (heartbeats.length > 0) {
|
if (heartbeats.length > 0) {
|
||||||
log.info("db", `[DON'T STOP] Migrating monitor data ${monitor.monitor_id} - ${date.date} [${progressPercent.toFixed(2)}%][${i}/${monitors.length}]`);
|
msg = `[DON'T STOP] Migrating monitor data ${monitor.monitor_id} - ${date.date} [${progressPercent.toFixed(2)}%][${i}/${monitors.length}]`;
|
||||||
|
log.info("db", msg);
|
||||||
|
migrationServer?.update(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let heartbeat of heartbeats) {
|
for (let heartbeat of heartbeats) {
|
||||||
|
@ -829,9 +849,13 @@ class Database {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Database.clearHeartbeatData(true);
|
msg = "Clearing non-important heartbeats";
|
||||||
|
log.info("db", msg);
|
||||||
|
migrationServer?.update(msg);
|
||||||
|
|
||||||
|
await Database.clearHeartbeatData(true);
|
||||||
await Settings.set("migrateAggregateTableState", "migrated");
|
await Settings.set("migrateAggregateTableState", "migrated");
|
||||||
|
await migrationServer?.stop();
|
||||||
|
|
||||||
if (monitors.length > 0) {
|
if (monitors.length > 0) {
|
||||||
log.info("db", "Aggregate Table Migration Completed");
|
log.info("db", "Aggregate Table Migration Completed");
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const https = require("https");
|
const https = require("https");
|
||||||
const fs = require("fs");
|
const fs = require("fs/promises");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const Database = require("./database");
|
const Database = require("./database");
|
||||||
const { axiosAbortSignal } = require("./util-server");
|
const { axiosAbortSignal, fileExists } = require("./util-server");
|
||||||
|
|
||||||
class DockerHost {
|
class DockerHost {
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ class DockerHost {
|
||||||
options.socketPath = dockerHost.dockerDaemon;
|
options.socketPath = dockerHost.dockerDaemon;
|
||||||
} else if (dockerHost.dockerType === "tcp") {
|
} else if (dockerHost.dockerType === "tcp") {
|
||||||
options.baseURL = DockerHost.patchDockerURL(dockerHost.dockerDaemon);
|
options.baseURL = DockerHost.patchDockerURL(dockerHost.dockerDaemon);
|
||||||
options.httpsAgent = new https.Agent(DockerHost.getHttpsAgentOptions(dockerHost.dockerType, options.baseURL));
|
options.httpsAgent = new https.Agent(await DockerHost.getHttpsAgentOptions(dockerHost.dockerType, options.baseURL));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -143,7 +143,7 @@ class DockerHost {
|
||||||
* @param {string} url The docker host URL rewritten to https://
|
* @param {string} url The docker host URL rewritten to https://
|
||||||
* @returns {object} HTTP agent options
|
* @returns {object} HTTP agent options
|
||||||
*/
|
*/
|
||||||
static getHttpsAgentOptions(dockerType, url) {
|
static async getHttpsAgentOptions(dockerType, url) {
|
||||||
let baseOptions = {
|
let baseOptions = {
|
||||||
maxCachedSessions: 0,
|
maxCachedSessions: 0,
|
||||||
rejectUnauthorized: true
|
rejectUnauthorized: true
|
||||||
|
@ -156,10 +156,10 @@ class DockerHost {
|
||||||
let certPath = path.join(Database.dockerTLSDir, dirName, DockerHost.CertificateFileNameCert);
|
let certPath = path.join(Database.dockerTLSDir, dirName, DockerHost.CertificateFileNameCert);
|
||||||
let keyPath = path.join(Database.dockerTLSDir, dirName, DockerHost.CertificateFileNameKey);
|
let keyPath = path.join(Database.dockerTLSDir, dirName, DockerHost.CertificateFileNameKey);
|
||||||
|
|
||||||
if (dockerType === "tcp" && fs.existsSync(caPath) && fs.existsSync(certPath) && fs.existsSync(keyPath)) {
|
if (dockerType === "tcp" && await fileExists(caPath) && await fileExists(certPath) && await fileExists(keyPath)) {
|
||||||
let ca = fs.readFileSync(caPath);
|
let ca = await fs.readFile(caPath);
|
||||||
let key = fs.readFileSync(keyPath);
|
let key = await fs.readFile(keyPath);
|
||||||
let cert = fs.readFileSync(certPath);
|
let cert = await fs.readFile(certPath);
|
||||||
certOptions = {
|
certOptions = {
|
||||||
ca,
|
ca,
|
||||||
key,
|
key,
|
||||||
|
|
|
@ -739,7 +739,7 @@ class Monitor extends BeanModel {
|
||||||
} else if (dockerHost._dockerType === "tcp") {
|
} else if (dockerHost._dockerType === "tcp") {
|
||||||
options.baseURL = DockerHost.patchDockerURL(dockerHost._dockerDaemon);
|
options.baseURL = DockerHost.patchDockerURL(dockerHost._dockerDaemon);
|
||||||
options.httpsAgent = new https.Agent(
|
options.httpsAgent = new https.Agent(
|
||||||
DockerHost.getHttpsAgentOptions(dockerHost._dockerType, options.baseURL)
|
await DockerHost.getHttpsAgentOptions(dockerHost._dockerType, options.baseURL)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1716,7 +1716,7 @@ async function initDatabase(testMode = false) {
|
||||||
log.info("server", "Connected to the database");
|
log.info("server", "Connected to the database");
|
||||||
|
|
||||||
// Patch the database
|
// Patch the database
|
||||||
await Database.patch();
|
await Database.patch(port, hostname);
|
||||||
|
|
||||||
let jwtSecretBean = await R.findOne("setting", " `key` = ? ", [
|
let jwtSecretBean = await R.findOne("setting", " `key` = ? ", [
|
||||||
"jwtSecret",
|
"jwtSecret",
|
||||||
|
|
|
@ -4,7 +4,7 @@ const { sendInfo } = require("../client");
|
||||||
const { checkLogin } = require("../util-server");
|
const { checkLogin } = require("../util-server");
|
||||||
const GameResolver = require("gamedig/lib/GameResolver");
|
const GameResolver = require("gamedig/lib/GameResolver");
|
||||||
const { testChrome } = require("../monitor-types/real-browser-monitor-type");
|
const { testChrome } = require("../monitor-types/real-browser-monitor-type");
|
||||||
const fs = require("fs");
|
const fs = require("fs/promises");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
let gameResolver = new GameResolver();
|
let gameResolver = new GameResolver();
|
||||||
|
@ -90,17 +90,17 @@ module.exports.generalSocketHandler = (socket, server) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("getPushExample", (language, callback) => {
|
socket.on("getPushExample", async (language, callback) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let dir = path.join("./extra/push-examples", language);
|
let dir = path.join("./extra/push-examples", language);
|
||||||
let files = fs.readdirSync(dir);
|
let files = await fs.readdir(dir);
|
||||||
|
|
||||||
for (let file of files) {
|
for (let file of files) {
|
||||||
if (file.startsWith("index.")) {
|
if (file.startsWith("index.")) {
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
code: fs.readFileSync(path.join(dir, file), "utf8"),
|
code: await fs.readFile(path.join(dir, file), "utf8"),
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ const radiusClient = require("node-radius-client");
|
||||||
const redis = require("redis");
|
const redis = require("redis");
|
||||||
const oidc = require("openid-client");
|
const oidc = require("openid-client");
|
||||||
const tls = require("tls");
|
const tls = require("tls");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
dictionaries: {
|
dictionaries: {
|
||||||
|
@ -1062,3 +1063,9 @@ module.exports.axiosAbortSignal = (timeoutMs) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.fileExists = (file) => {
|
||||||
|
return fs.promises.access(file, fs.constants.F_OK)
|
||||||
|
.then(() => true)
|
||||||
|
.catch(() => false);
|
||||||
|
};
|
||||||
|
|
84
server/utils/simple-migration-server.js
Normal file
84
server/utils/simple-migration-server.js
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
const express = require("express");
|
||||||
|
const http = require("node:http");
|
||||||
|
const { log } = require("../../src/util");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SimpleMigrationServer
|
||||||
|
* For displaying the migration status of the server
|
||||||
|
* Also, it is used to let Docker healthcheck know the status of the server, as the main server is not started yet, healthcheck will think the server is down incorrectly.
|
||||||
|
*/
|
||||||
|
class SimpleMigrationServer {
|
||||||
|
/**
|
||||||
|
* Express app instance
|
||||||
|
* @type {?Express}
|
||||||
|
*/
|
||||||
|
app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server instance
|
||||||
|
* @type {?Server}
|
||||||
|
*/
|
||||||
|
server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response object
|
||||||
|
* @type {?Response}
|
||||||
|
*/
|
||||||
|
response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the server
|
||||||
|
* @param {number} port Port
|
||||||
|
* @param {string} hostname Hostname
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
start(port, hostname) {
|
||||||
|
this.app = express();
|
||||||
|
this.server = http.createServer(this.app);
|
||||||
|
|
||||||
|
this.app.get("/", (req, res) => {
|
||||||
|
res.set("Content-Type", "text/plain");
|
||||||
|
res.write("Migration is in progress, listening message...\n");
|
||||||
|
if (this.response) {
|
||||||
|
this.response.write("Disconnected\n");
|
||||||
|
this.response.end();
|
||||||
|
}
|
||||||
|
this.response = res;
|
||||||
|
// never ending response
|
||||||
|
});
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.server.listen(port, hostname, () => {
|
||||||
|
if (hostname) {
|
||||||
|
log.info("migration", `Migration server is running on http://${hostname}:${port}`);
|
||||||
|
} else {
|
||||||
|
log.info("migration", `Migration server is running on http://localhost:${port}`);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the message
|
||||||
|
* @param {string} msg Message to update
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
update(msg) {
|
||||||
|
this.response?.write(msg + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the server
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async stop() {
|
||||||
|
this.response?.write("Finished, please refresh this page.\n");
|
||||||
|
this.response?.end();
|
||||||
|
await this.server?.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
SimpleMigrationServer,
|
||||||
|
};
|
Loading…
Add table
Reference in a new issue