mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 08:44:04 +00:00
WIP
This commit is contained in:
parent
5e976afb27
commit
a4de93f976
4 changed files with 101 additions and 17 deletions
|
@ -48,7 +48,10 @@ CMD ["node", "server/server.js"]
|
|||
############################################
|
||||
FROM release-slim AS release
|
||||
RUN apt update && \
|
||||
apt --yes --no-install-recommends install curl && \
|
||||
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash -s -- --mariadb-server-version="mariadb-10.11" && \
|
||||
apt --yes --no-install-recommends install mariadb-server && \
|
||||
apt remove curl && \
|
||||
rm -rf /var/lib/apt/lists/* && \
|
||||
apt --yes autoremove
|
||||
|
||||
|
|
0
docker/my.cnf
Normal file
0
docker/my.cnf
Normal file
|
@ -4,6 +4,7 @@ const { setSetting, setting } = require("./util-server");
|
|||
const { log, sleep } = require("../src/util");
|
||||
const dayjs = require("dayjs");
|
||||
const knex = require("knex");
|
||||
const path = require("path");
|
||||
|
||||
/**
|
||||
* Database & App Data Folder
|
||||
|
@ -109,10 +110,23 @@ class Database {
|
|||
static async connect(testMode = false, autoloadModels = true, noLog = false) {
|
||||
const acquireConnectionTimeout = 120 * 1000;
|
||||
|
||||
let dbConfig;
|
||||
|
||||
try {
|
||||
dbConfig = fs.readFileSync(path.join(Database.dataDir, "db-config.json"));
|
||||
} catch (_) {
|
||||
dbConfig = {
|
||||
type: "sqlite",
|
||||
};
|
||||
}
|
||||
|
||||
let config = {};
|
||||
|
||||
if (dbConfig.type === "sqlite") {
|
||||
const Dialect = require("knex/lib/dialects/sqlite3/index.js");
|
||||
Dialect.prototype._driver = () => require("@louislam/sqlite3");
|
||||
|
||||
const knexInstance = knex({
|
||||
config = {
|
||||
client: Dialect,
|
||||
connection: {
|
||||
filename: Database.path,
|
||||
|
@ -126,7 +140,23 @@ class Database {
|
|||
propagateCreateError: false,
|
||||
acquireTimeoutMillis: acquireConnectionTimeout,
|
||||
}
|
||||
});
|
||||
};
|
||||
} else if (dbConfig === "embedded-mariadb") {
|
||||
config = {
|
||||
client: "mysql",
|
||||
connection: {
|
||||
host: "127.0.0.1",
|
||||
port: 3306,
|
||||
user: "your_database_user",
|
||||
password: "your_database_password",
|
||||
database: "kuma"
|
||||
}
|
||||
};
|
||||
} else {
|
||||
throw new Error("Unknown Database type");
|
||||
}
|
||||
|
||||
const knexInstance = knex(config);
|
||||
|
||||
R.setup(knexInstance);
|
||||
|
||||
|
|
51
server/embedded-mariadb.js
Normal file
51
server/embedded-mariadb.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
const { log } = require("../src/util");
|
||||
const childProcess = require("child_process");
|
||||
|
||||
class EmbeddedMariaDB {
|
||||
|
||||
static childProcess = null;
|
||||
static running = false;
|
||||
|
||||
static init() {
|
||||
|
||||
}
|
||||
|
||||
static start() {
|
||||
if (this.childProcess) {
|
||||
log.log("mariadb", "Already started");
|
||||
return;
|
||||
}
|
||||
|
||||
this.running = true;
|
||||
this.emitChange("Starting cloudflared");
|
||||
this.childProcess = childProcess.spawn(this.cloudflaredPath, args);
|
||||
this.childProcess.stdout.pipe(process.stdout);
|
||||
this.childProcess.stderr.pipe(process.stderr);
|
||||
|
||||
this.childProcess.on("close", (code) => {
|
||||
this.running = false;
|
||||
this.childProcess = null;
|
||||
this.emitChange("Stopped cloudflared", code);
|
||||
});
|
||||
|
||||
this.childProcess.on("error", (err) => {
|
||||
if (err.code === "ENOENT") {
|
||||
this.emitError(`Cloudflared error: ${this.cloudflaredPath} is not found`);
|
||||
} else {
|
||||
this.emitError(err);
|
||||
}
|
||||
});
|
||||
|
||||
this.childProcess.stderr.on("data", (data) => {
|
||||
this.emitError(data.toString());
|
||||
});
|
||||
}
|
||||
|
||||
static stop() {
|
||||
if (this.childProcess) {
|
||||
this.childProcess.kill("SIGINT");
|
||||
this.childProcess = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue