Skip to content

Commit

Permalink
Add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Aug 17, 2024
1 parent c092b90 commit 29573d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
15 changes: 3 additions & 12 deletions src/controllers/logman.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,12 @@ import { logmanExec } from '../executor/logman.js';

export default function () {
var router = express.Router();
router.get('/get', checkGet(['domain', 'type']), async function (req, res, next) {
router.get('/get', checkGet(['user', 'type']), async function (req, res, next) {
try {
let domain = await virtualminExec.getDomainInfo(req.query.domain.toString());
let type = req.query.type.toString()
let user = req.query.user.toString()
let n = parseInt((req.query.n || 100).toString()) || 100;
let output = await logmanExec.getLog(domain, type, n);
return res.json(output);
} catch (err) {
next(err);
}
});
router.post('/restart', checkGet(['domain']), async function (req, res, next) {
try {
let domain = await virtualminExec.getDomainInfo(req.query.domain.toString());
let output = await logmanExec.restartPassenger(domain);
let output = await logmanExec.getLog(user, type, n);
return res.json(output);
} catch (err) {
next(err);
Expand Down
32 changes: 13 additions & 19 deletions src/executor/logman.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,28 @@ class LogmanExecutor {
}
}
/**
* @param {any} domain
* @param {string} user
* @param {string} type
* @param {number} n
*/
async getLog(domain, type, n) {
async getLog(user, type, n) {
switch (type) {
case 'access':
if (!domain['Access log']) {
return {
code: 255,
stderr: 'No access log found',
stdout: '',
}
}
return await spawnSudoUtil("SHELL_SUDO", ["root",
"tail", "-n", n, domain['Access log']]);
"tail", "-n", n + '', `/home/${user}/logs/access_log`]);
case 'error':
if (!domain['Error log']) {
return {
code: 255,
stderr: 'No error log found',
stdout: '',
}
}
return await spawnSudoUtil("SHELL_SUDO", ["root",
"tail", "-n", n, domain['Error log']]);
"tail", "-n", n + '', `/home/${user}/logs/error_log`]);
case 'php':
return await spawnSudoUtil("SHELL_SUDO", ["root",
"tail", "-n", n + '', `/home/${user}/logs/php_log`]);
case 'unit-stdout':
return await spawnSudoUtil("SHELL_SUDO", ["root",
"tail", "-n", n + '', `/home/${user}/logs/unit_stdout_log`]);
case 'unit-stderr':
return await spawnSudoUtil("SHELL_SUDO", ["root",
"tail", "-n", n + '', `/home/${user}/logs/unit_stderr_log`]);
case 'passenger':
const user = domain['Username'];
const procs = await this.getPassengerPids(user);
if (procs.code !== 0) {
return procs;
Expand Down

0 comments on commit 29573d1

Please sign in to comment.