uptime-kuma/server/embedded-mariadb.js
Louis Lam a4de93f976 WIP
2022-12-23 22:43:56 +08:00

52 lines
1.3 KiB
JavaScript

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;
}
}
}