uptime-kuma/server/embedded-mariadb.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-12-23 14:43:56 +00:00
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;
}
}
}