Skip to content

Commit

Permalink
Added chmod logs folder
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterbrandsen authored Feb 5, 2024
1 parent 22f89dc commit d074c10
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 105 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "screeps-performance-server",
"version": "1.13.0",
"version": "1.13.1",
"dependencies": {
"@octokit/core": "^4.2.0",
"discord.js": "^14.9.0",
Expand Down
103 changes: 2 additions & 101 deletions src/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export default class Helper {
await api.auth();

api.socket.connect();
api.socket.on("connected", () => {});
api.socket.on("auth", () => {});
api.socket.on("connected", () => { });

Check failure on line 81 in src/exporter.js

View workflow job for this annotation

GitHub Actions / Run linters

Delete `·`
api.socket.on("auth", () => { });

Check failure on line 82 in src/exporter.js

View workflow job for this annotation

GitHub Actions / Run linters

Delete `·`
api.socket.subscribe(`room:${room}`, statusUpdater);
api.socket.subscribe("console", (event) => {
if (event.data.messages) {
Expand Down Expand Up @@ -149,105 +149,6 @@ export default class Helper {
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
}

/**
* startServer method
*
* Starts the private server
* @return {object}
*/
static async startServer() {
const stopCommand = `${basicCommand} down --volumes --remove-orphans --rmi all`;
const upCommand = `${basicCommand} up -d`;
const serverLogsCommand = `${basicCommand} logs -f screeps`;

const maxTime = new Promise((resolve) => {
setTimeout(resolve, 30 * 60 * 1000, "Timeout");
});

const startServer = new Promise(async (resolve) => {
console.log("\r\nProcess: Starting server...");
console.log("Stopping server...");
execSync(stopCommand, { stdio: argv.debug ? "inherit" : "ignore" });
RemoveLogs();

console.log("Starting server, this will take a while...");
execSync(upCommand);
await this.sleep(10);

let hitCountMissing = 1;
const child = exec(serverLogsCommand, { stdio: "pipe" });
child.stdout.on("data", (data) => {
const lines = data ? data.split(/(\r?\n)/g) : [];
lines.forEach((line) => {
if (argv.debug) console.log(line);
if (line.includes("[main] exec: screeps-engine-main")) {
hitCountMissing -= 1;
if (hitCountMissing === 0) {
child.kill();
resolve(true);
}
}
});
});
});
return Promise.race([startServer, maxTime])
.then((result) => {
if (result === "Timeout") {
console.log("Timeout starting server!");
return false;
}
return true;
})
.catch((result) => {
console.error("error", { data: result });
return false;
});
}

static async restartServer() {
const restartCommand = `${basicCommand} restart screeps`;
const serverLogsCommand = `${basicCommand} logs -f screeps`;

const maxTime = new Promise((resolve) => {
setTimeout(resolve, 30 * 60 * 1000, "Timeout");
});

const restartServer = new Promise(async (resolve) => {
console.log("\r\nProcess: Restart server...");
console.log("Restarting server...\r\n");
exec(restartCommand);
await this.sleep(10);

let hitCountMissing = 2;
const child = exec(serverLogsCommand, { stdio: "pipe" });
child.stdout.on("data", (data) => {
const lines = data ? data.split(/(\r?\n)/g) : [];
lines.forEach((line) => {
if (argv.debug) console.log(line);
if (line.includes("[main] exec: screeps-engine-main")) {
hitCountMissing -= 1;
if (hitCountMissing === 0) {
child.kill();
resolve(true);
}
}
});
});
});
return Promise.race([restartServer, maxTime])
.then((result) => {
if (result === "Timeout") {
console.log("Timeout starting server!");
return false;
}
return true;
})
.catch((result) => {
console.error("error", { data: result });
return false;
});
}

static initControllerID(event, status, controllerRooms) {
if (status[event.id].controller === null) {
// eslint-disable-next-line prefer-destructuring
Expand Down
9 changes: 6 additions & 3 deletions src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export default class Helper {
await api.auth();

api.socket.connect();
api.socket.on("connected", () => {});
api.socket.on("auth", () => {});
api.socket.on("connected", () => { });

Check failure on line 81 in src/helper.js

View workflow job for this annotation

GitHub Actions / Run linters

Delete `·`
api.socket.on("auth", () => { });

Check failure on line 82 in src/helper.js

View workflow job for this annotation

GitHub Actions / Run linters

Delete `·`
api.socket.subscribe(`room:${room}`, statusUpdater);
api.socket.subscribe("console", (event) => {
if (event.data.messages) {
Expand Down Expand Up @@ -171,7 +171,10 @@ export default class Helper {
RemoveLogs();

console.log("Starting server, this will take a while...");
exec(upCommand);
try {
execSync("mkdir ./logs && chmod 777 ./logs")

Check failure on line 175 in src/helper.js

View workflow job for this annotation

GitHub Actions / Run linters

Insert `;`
} catch { }

Check failure on line 176 in src/helper.js

View workflow job for this annotation

GitHub Actions / Run linters

Empty block statement
execSync(upCommand);
await this.sleep(10);

let hitCountMissing = 1;
Expand Down

0 comments on commit d074c10

Please sign in to comment.