Code Modifications #261
@ -1,35 +1,46 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
process.env.BDS_DOCKER_IMAGE = true;
|
process.env.BDS_DOCKER_IMAGE = true;
|
||||||
const fs = require("fs");
|
|
||||||
const BdsCore = require("../index");
|
const BdsCore = require("../index");
|
||||||
const { CronJob } = require("cron");
|
const { CronJob } = require("cron");
|
||||||
|
|
||||||
async function UpdateInstallServer(OldServerRunner) {
|
async function UpdateInstallServer(OldServerRunner, pre_stop = () => {}) {
|
||||||
if (process.env.SERVER_VERSION === "true") {
|
if (process.env.SERVER_VERSION === "true") {
|
||||||
|
if (typeof pre_stop === "function") await pre_stop();
|
||||||
if (typeof OldServerRunner === "function") {
|
if (typeof OldServerRunner === "function") {
|
||||||
OldServerRunner.stop();
|
OldServerRunner.stop();
|
||||||
}
|
}
|
||||||
const BackupBds = BdsCore.BdsBackup.CreateBackup();
|
// Create Backup and Write
|
||||||
const ServerDownloadResult = await BdsCore.BdsDownload("latest");
|
(BdsCore.BdsBackup.CreateBackup()).write_file()
|
||||||
if (!ServerDownloadResult.skip) {
|
const ServerDownloadResult = await BdsCore.BdsDownload("latest");
|
||||||
console.log("Server Update Sucess, Version:", ServerDownloadResult.version);
|
if (ServerDownloadResult.skip) {
|
||||||
return StartServer();
|
console.log("Server Update Sucess, Version:", ServerDownloadResult.version);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
await BdsCore.BdsDownload(process.env.SERVER_VERSION);
|
|
||||||
}
|
}
|
||||||
|
return StartServer();
|
||||||
|
} else {
|
||||||
|
await BdsCore.BdsDownload(process.env.SERVER_VERSION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function StartServer() {
|
function StartServer() {
|
||||||
let IsUpdate = false;
|
let IsUpdate = false;
|
||||||
const Server = BdsCore.BdsManegerServer.StartServer();
|
const Server = BdsCore.BdsManegerServer.StartServer();
|
||||||
Server.on("log", data => process.stdout.write(data));
|
Server.on("log", data => {
|
||||||
|
if (process.env.PULLIMAGE) {
|
||||||
|
const { value: DataToTest, regex: IsRegex } = BdsCore.ExtraJSON.Extra.StartedServer[BdsCore.BdsSettings.GetPlatform()];
|
||||||
|
if (IsRegex) {
|
||||||
|
if (RegExp(DataToTest, "gi").test(data)) {
|
||||||
|
return Server.stop();
|
||||||
|
}
|
||||||
|
} else return Server.stop();
|
||||||
|
}
|
||||||
|
return process.stdout.write(data)
|
||||||
|
});
|
||||||
Server.on("exit", code => {
|
Server.on("exit", code => {
|
||||||
if (!IsUpdate) process.exit(code);
|
if (!IsUpdate) process.exit(code);
|
||||||
});
|
});
|
||||||
new CronJob("*/1 * * * *", async () => {
|
new CronJob("*/1 * * * *", async () => {
|
||||||
console.log("Checking for updates...");
|
console.log("Checking for updates...");
|
||||||
await UpdateInstallServer(Server);
|
await UpdateInstallServer(Server, () => IsUpdate = true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user