diff --git a/src/controllers/logman.js b/src/controllers/logman.js index 6d19d28..179a02e 100644 --- a/src/controllers/logman.js +++ b/src/controllers/logman.js @@ -15,11 +15,11 @@ export default function () { try { let domain = await virtualminExec.getDomainInfo(req.query.domain.toString()); let type = req.query.type.toString() - let n = parseInt(req.query.n.toString()) || 100; + let n = parseInt((req.query.n || 100).toString()) || 100; let output = await logmanExec.getLog(domain, type, n); return res.json(output); - } catch (error) { - next(error); + } catch (err) { + next(JSON.stringify(err, Object.getOwnPropertyNames(err))); } }); return router; diff --git a/src/executor/logman.js b/src/executor/logman.js index d9f14c7..20949a0 100644 --- a/src/executor/logman.js +++ b/src/executor/logman.js @@ -5,6 +5,7 @@ import { writeTo } from '../util.js'; import { XMLParser } from "fast-xml-parser"; +import { readFile } from "fs/promises"; class LogmanExecutor { constructor() { @@ -39,8 +40,10 @@ class LogmanExecutor { "tail", "-n", n, domain['Error log']]); case 'passenger': const user = domain['Username']; - const pe = await spawnSudoUtil("SHELL_SUDO", [user, - "passenger-status", "--show=xml"]); + const pe = process.env.NODE_ENV === 'development' ? + { stdout: await readFile('./test/passenger-status', {encoding: 'utf-8'}) } : + await spawnSudoUtil("SHELL_SUDO", [user, + "passenger-status", "--show=xml"]); const peo = pe.stdout.trim(); if (!peo) { return { @@ -59,21 +62,23 @@ class LogmanExecutor { } } let peomaa = Array.isArray(peoma) ? peoma : [peoma]; - let peomaps = peomaa.map(x => x.group.processes).filter(x => x); + let peomaps = peomaa.map(x => x.group).filter(x => x.processes); if (!peomaps.length) { return { code: 255, - stderr: 'No processes from passenger-status is running', + stderr: 'No processes reported from passenger-status is running', stdout: '' } } let procs = peomaps.reduce((a, b) => { - let x = (Array.isArray(b.process) ? b.process : [b.process]); - a[b.group.name] = x.map(y => y.pid).filter(y => typeof y === "number"); - }, peomaps); + let x = (Array.isArray(b.processes.process) ? b.processes.process : [b.processes.process]); + a[b.name] = x.map(y => y.pid).filter(y => typeof y === "number"); + return a; + }, {}); let head = `List of passenger processes running:\n`; head += JSON.stringify(procs, null, 2); head += `\n------------------------\n`; + console.log(head); let pids = Object.values(procs).flatMap(x => x).join('\\|'); const pes = await spawnSudoUtil("SHELL_SUDO", ["root", "bash", "-c", `grep -w "\\^App \\(${pids}\\)" "${this.PASSENGERLOG}" | tail -n ${n}` diff --git a/test/passenger-status b/test/passenger-status new file mode 100644 index 0000000..3d3d3b0 --- /dev/null +++ b/test/passenger-status @@ -0,0 +1,92 @@ + + + 6.0.19 + 5 + 5 + 20 + 5 + 0 + + + /home/bridge/public_html/webssh2/app (production) + READY + 0 + 1 + + /home/bridge/public_html/webssh2/app (production) + /home/bridge/public_html/webssh2/app (production) + /home/bridge/public_html/webssh2/app + + production + U8CALDqmahQomxukXAXm + 1 + 0 + 0 + 1 + 0 + 0 + 0 + ALIVE + bridge + 1036 + bridge + 1036 + + /home/bridge/public_html/webssh2/app + /home/bridge/public_html/webssh2/app (production) + env PORT=$PORT node app.js + /home/bridge/public_html/webssh2/app + 3 + 90000 + production + / + smart + 127.0.0.1 + nobody + nobody + tmp + nginx + /usr/bin/ruby + /usr/bin/python3 + /usr/bin/node + false + LcZ3a5palXtc + 0 + 1 + 300 + 1 + SameSite=Lax; Secure; + + + + 2238686 + 592161411 + 1b17ce1-YJRaByfnLl + -1 + 2 + 2 + 29 + 1704543452738301 + 1704543452745389 + 1704543454007375 + 1704543625386216 + 10m 55s ago + 13m 46s + ALIVE + ENABLED + true + 0 + 24056 + 16813 + 13056 + 14568 + 27624 + 11280320 + 2238536 + node app.js + + + + + + \ No newline at end of file