mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-03-03 16:05:56 +00:00
Compare commits
No commits in common. "1b379690dd5103d31b39aee7519665159a69c5e5" and "c6a9a78175078b411df260e80d00af1cc3bea3ac" have entirely different histories.
1b379690dd
...
c6a9a78175
7 changed files with 19 additions and 171 deletions
|
@ -1,13 +0,0 @@
|
||||||
// Update info_json column to LONGTEXT mainly for MariaDB
|
|
||||||
exports.up = function (knex) {
|
|
||||||
return knex.schema
|
|
||||||
.alterTable("monitor_tls_info", function (table) {
|
|
||||||
table.text("info_json", "longtext").alter();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.down = function (knex) {
|
|
||||||
return knex.schema.alterTable("monitor_tls_info", function (table) {
|
|
||||||
table.text("info_json", "text").alter();
|
|
||||||
});
|
|
||||||
};
|
|
|
@ -27,6 +27,7 @@ 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"
|
||||||
|
@ -45,7 +46,6 @@ 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,7 +9,6 @@ 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
|
||||||
|
@ -383,11 +382,9 @@ 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(port = undefined, hostname = undefined) {
|
static async patch() {
|
||||||
// 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();
|
||||||
|
@ -412,7 +409,7 @@ class Database {
|
||||||
await R.exec("PRAGMA foreign_keys = ON");
|
await R.exec("PRAGMA foreign_keys = ON");
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.migrateAggregateTable(port, hostname);
|
await this.migrateAggregateTable();
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Allow missing patch files for downgrade or testing pr.
|
// Allow missing patch files for downgrade or testing pr.
|
||||||
|
@ -738,11 +735,9 @@ 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(port, hostname = undefined) {
|
static async migrateAggregateTable() {
|
||||||
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
|
||||||
|
@ -763,17 +758,7 @@ class Database {
|
||||||
throw new Error("Aggregate table migration is already in progress");
|
throw new Error("Aggregate table migration is already in progress");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
await Settings.set("migrateAggregateTableState", "migrating");
|
||||||
* Start migration server for displaying the migration status
|
|
||||||
* @type {SimpleMigrationServer}
|
|
||||||
*/
|
|
||||||
let migrationServer;
|
|
||||||
let msg;
|
|
||||||
|
|
||||||
if (port) {
|
|
||||||
migrationServer = new SimpleMigrationServer();
|
|
||||||
await migrationServer.start(port, hostname);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("db", "Migrating Aggregate Table");
|
log.info("db", "Migrating Aggregate Table");
|
||||||
|
|
||||||
|
@ -792,13 +777,10 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Settings.set("migrateAggregateTableState", "migrating");
|
|
||||||
|
|
||||||
let progressPercent = 0;
|
let progressPercent = 0;
|
||||||
let part = 100 / monitors.length;
|
let part = 100 / monitors.length;
|
||||||
let i = 1;
|
let i = 1;
|
||||||
|
@ -829,9 +811,7 @@ class Database {
|
||||||
`, [ monitor.monitor_id, date.date ]);
|
`, [ monitor.monitor_id, date.date ]);
|
||||||
|
|
||||||
if (heartbeats.length > 0) {
|
if (heartbeats.length > 0) {
|
||||||
msg = `[DON'T STOP] Migrating monitor data ${monitor.monitor_id} - ${date.date} [${progressPercent.toFixed(2)}%][${i}/${monitors.length}]`;
|
log.info("db", `[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) {
|
||||||
|
@ -849,13 +829,9 @@ class Database {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = "Clearing non-important heartbeats";
|
|
||||||
log.info("db", msg);
|
|
||||||
migrationServer?.update(msg);
|
|
||||||
|
|
||||||
await Database.clearHeartbeatData(true);
|
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");
|
||||||
|
|
|
@ -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(port, hostname);
|
await Database.patch();
|
||||||
|
|
||||||
let jwtSecretBean = await R.findOne("setting", " `key` = ? ", [
|
let jwtSecretBean = await R.findOne("setting", " `key` = ? ", [
|
||||||
"jwtSecret",
|
"jwtSecret",
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
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,
|
|
||||||
};
|
|
|
@ -198,15 +198,11 @@ export default {
|
||||||
return this.$route.query.searchText || "";
|
return this.$route.query.searchText || "";
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
const newQuery = {
|
this.$router.replace({
|
||||||
|
query: {
|
||||||
...this.$route.query,
|
...this.$route.query,
|
||||||
searchText: value,
|
searchText: value,
|
||||||
};
|
|
||||||
if (!value) {
|
|
||||||
delete newQuery.searchText;
|
|
||||||
}
|
}
|
||||||
this.$router.replace({
|
|
||||||
query: newQuery,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -290,22 +286,13 @@ export default {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
updateFilter(newFilter) {
|
updateFilter(newFilter) {
|
||||||
let newQuery = {
|
|
||||||
...this.$route.query,
|
|
||||||
...newFilter,
|
|
||||||
};
|
|
||||||
if (!newFilter.status || newFilter.status.length === 0) {
|
|
||||||
delete newQuery.status;
|
|
||||||
}
|
|
||||||
if (!newFilter.active || newFilter.active.length === 0) {
|
|
||||||
delete newQuery.active;
|
|
||||||
}
|
|
||||||
if (!newFilter.tags || newFilter.tags.length === 0) {
|
|
||||||
delete newQuery.tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.$router.replace({
|
this.$router.replace({
|
||||||
query: newQuery,
|
query: {
|
||||||
|
...this.$route.query,
|
||||||
|
status: newFilter.status,
|
||||||
|
active: newFilter.active,
|
||||||
|
tags: newFilter.tags,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -192,26 +192,8 @@ const routes = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const router = createRouter({
|
export const router = createRouter({
|
||||||
linkActiveClass: "active",
|
linkActiveClass: "active",
|
||||||
history: createWebHistory(),
|
history: createWebHistory(),
|
||||||
routes,
|
routes,
|
||||||
});
|
});
|
||||||
|
|
||||||
router.beforeEach((to, from) => {
|
|
||||||
// If the path is same, either the query or has has changed so avoid changing query params
|
|
||||||
// Without this check, modifying any query params will be blocked
|
|
||||||
// Check if redirectedFrom is defined to check if this function has already been run
|
|
||||||
// Without this check, the router will be stuck in an infinite loop
|
|
||||||
if (to.path !== from.path && !to.redirectedFrom) {
|
|
||||||
return {
|
|
||||||
...to,
|
|
||||||
query: {
|
|
||||||
...to.query,
|
|
||||||
...from.query,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export { router };
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue