Skip to content

Commit

Permalink
Add fix indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Dec 1, 2024
1 parent 92fe4f3 commit 00b1e94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/controllers/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ export default function () {
lastTestOK = lastTestResult.status == 'OK';
lastTest = Date.now();
}
res.status(lastTestOK ? 200 : 500).json(lastTestResult);
if (lastTestResult.codes.nginx === 1) {
await fixNGINX(lastTestResult);
}
if (lastTestResult.codes.fpms.some(x => x === 1)) {
await fixPHP(lastTestResult);
}
res.status(lastTestOK ? 200 : 500).json(lastTestResult);
} catch (error) {
next(error);
}
Expand Down
8 changes: 8 additions & 0 deletions src/executor/pulse.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { spawnSudoUtil } from "../util.js";

export async function fixPHP(test) {
const edits = [];
for (const [name, logs] of Object.entries(test.logs.fpms)) {
const [lastLog] = logs.splice(logs.length - 1);
if (lastLog.endsWith("ERROR: FPM initialization failed")) {
for (const element of logs) {
let m = element.match(/ALERT: \[pool (\d+)\]/);
if (m) {
await spawnSudoUtil("CLEAN_DOMAIN", ["mv", m[1], ""]);
edits.push(m[1]);
}
}
}
}
test.fixes = test.fixes || {};
test.fixes.fpm = edits;
}

export async function fixNGINX(test) {
const logs = test.logs.nginx;
const [lastLog] = logs.splice(logs.length - 1);
const edits = [];
if (lastLog == "nginx: configuration file /etc/nginx/nginx.conf test failed") {
for (const element of logs) {
let m = element.match(/nginx: \[emerg\] cannot load certificate \"([\w.\/]+)\"/);
Expand All @@ -28,10 +33,13 @@ export async function fixNGINX(test) {
let m2 = f.match(/\/etc\/nginx\/conf.d\/(.+)\.conf/);
if (m2) {
await spawnSudoUtil("CLEAN_DOMAIN", ["mv", "", m2[1]]);
edits.push(m2[1]);
}
}
}
}
}
test.fixes = test.fixes || {};
test.fixes.nginx = edits;
}

0 comments on commit 00b1e94

Please sign in to comment.