diff --git a/.gitignore b/.gitignore index eb84e7e..18cfd66 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ node_modules *.pem .env git -log.txt +runner_stdout.txt diff --git a/README.md b/README.md index e5128e7..bb48068 100644 --- a/README.md +++ b/README.md @@ -88,8 +88,6 @@ After it's running, the logs will be to the systemd journal: `sudo journalctl -u benchbot.service` -As well as to `./log.txt`. - # Github Settings ## Permissions diff --git a/bench.js b/bench.js index 121f831..a4b2d3f 100644 --- a/bench.js +++ b/bench.js @@ -1,3 +1,4 @@ +const fs = require("fs") const cp = require("child_process") const path = require("path") @@ -8,6 +9,9 @@ function errorResult(message, error) { let cwd = process.cwd(); console.log(`process cwd: ${cwd}`); +const wrapCmd = path.join(__dirname, "wrap_cmd.sh") +const runnerOutput = path.join(__dirname, "runner_stdout.txt") + const Mutex = require('async-mutex').Mutex; const mutex = new Mutex(); var shell = require('shelljs'); @@ -29,41 +33,21 @@ function BenchContext(app, config) { try { if (shouldLogOutput) { console.log(`<=== Start command output (cwd: ${process.cwd()})`) + cp.execFileSync("/bin/dash", ["-c", `${cmd} | tee ${runnerOutput}`], { stdio: "inherit" }) + stdout = fs.readFileSync(runnerOutput).toString() + } else { + stdout = cp.execSync(cmd, { stdio: "pipe", shell: true }).toString() } - - await new Promise(function (resolve) { - const proc = cp.spawn("/bin/bash", ["-c", cmd], { stdio: "pipe" }) - - proc.stdout.on("data", function (data) { - data = data.toString() - - if (data && shouldLogOutput) { - console.log(data.trim()) - } - - stdout += data - }) - - proc.stderr.on("data", function (data) { - data = data.toString() - - if (data && shouldLogOutput) { - console.log(data.trim()) - } - - stderr += data - }) - - proc.on("close", function (code) { - error = !!code - resolve() - }) - }) } catch (err) { error = true if (err.code) { + app.log(`Command ${cmd} failed with error code ${error.code}`); stdout = err.stdout.toString() + stderr = err.stderr.toString() + if (stderr) { + app.log(`stderr: ${stderr.trim()}`); + } } else { app.log.error("Caught exception in command execution") app.log.error(err) diff --git a/run b/run index 9a83af6..3eb06ae 100755 --- a/run +++ b/run @@ -139,7 +139,7 @@ main() { source ~/.cargo/env && \ cd "$install_location" && \ yarn && \ - yarn start 2>&1 | tee -a log.txt + yarn start 2>&1 } follow_service_logs() {