unitup 0.0.3 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/systemd.js +21 -10
- package/src/unit.js +1 -0
package/package.json
CHANGED
package/src/systemd.js
CHANGED
|
@@ -480,30 +480,41 @@ export async function runJournalctlLogs(name, opts = {}) {
|
|
|
480
480
|
const safeName = sanitizeServiceName(name);
|
|
481
481
|
const unitFilename = getUnitFilename(safeName);
|
|
482
482
|
|
|
483
|
-
const
|
|
483
|
+
const baseArgs = ['-u', unitFilename];
|
|
484
484
|
|
|
485
485
|
if (opts.cat || opts.output === 'cat') {
|
|
486
|
-
|
|
486
|
+
baseArgs.push('-o', 'cat');
|
|
487
487
|
} else if (opts.output) {
|
|
488
|
-
|
|
488
|
+
baseArgs.push('-o', opts.output);
|
|
489
489
|
}
|
|
490
490
|
|
|
491
491
|
if (opts.follow) {
|
|
492
|
-
|
|
493
|
-
// Spawn stream for follow mode
|
|
492
|
+
baseArgs.push('-f');
|
|
494
493
|
try {
|
|
495
|
-
const child = spawn('journalctl',
|
|
494
|
+
const child = spawn('journalctl', ['--user', ...baseArgs], { stdio: 'inherit', shell: false });
|
|
496
495
|
child.on('error', () => {});
|
|
497
496
|
return child;
|
|
498
497
|
} catch {
|
|
499
498
|
return null;
|
|
500
499
|
}
|
|
501
500
|
} else {
|
|
502
|
-
|
|
501
|
+
baseArgs.push('--no-pager');
|
|
503
502
|
const lines = opts.lines ? String(opts.lines) : '100';
|
|
504
|
-
|
|
503
|
+
baseArgs.push('-n', lines);
|
|
504
|
+
|
|
505
|
+
// Try --user mode first
|
|
506
|
+
const userRes = await runCommand('journalctl', ['--user', ...baseArgs]);
|
|
507
|
+
const userOut = userRes.stdout || userRes.stderr || '';
|
|
508
|
+
|
|
509
|
+
// If user journal files do not exist or returned no entries, fallback to system journal
|
|
510
|
+
if (!userOut || userOut.includes('No journal files') || userOut.includes('No entries') || userRes.code !== 0) {
|
|
511
|
+
const sysRes = await runCommand('journalctl', baseArgs);
|
|
512
|
+
const sysOut = sysRes.stdout || sysRes.stderr || '';
|
|
513
|
+
if (sysOut && !sysOut.includes('No journal files')) {
|
|
514
|
+
return sysOut;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
505
517
|
|
|
506
|
-
|
|
507
|
-
return res.stdout || res.stderr || 'No logs found.';
|
|
518
|
+
return userOut || 'No logs found.';
|
|
508
519
|
}
|
|
509
520
|
}
|