unitup 0.0.6 → 0.0.8
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 +50 -27
package/package.json
CHANGED
package/src/systemd.js
CHANGED
|
@@ -479,42 +479,65 @@ export async function listServices() {
|
|
|
479
479
|
export async function runJournalctlLogs(name, opts = {}) {
|
|
480
480
|
const safeName = sanitizeServiceName(name);
|
|
481
481
|
const unitFilename = getUnitFilename(safeName);
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
482
|
+
const syslogId = `unitup-${safeName}`;
|
|
483
|
+
|
|
484
|
+
const candidateArgSets = [
|
|
485
|
+
['--user', '-u', unitFilename],
|
|
486
|
+
['--user', '-u', `unitup-${safeName}`],
|
|
487
|
+
['--user', '-t', syslogId],
|
|
488
|
+
['-u', unitFilename],
|
|
489
|
+
['-u', `unitup-${safeName}`],
|
|
490
|
+
['-t', syslogId]
|
|
491
|
+
];
|
|
492
|
+
|
|
493
|
+
let chosenCandidate = null;
|
|
494
|
+
|
|
495
|
+
for (const candidateArgs of candidateArgSets) {
|
|
496
|
+
const testArgs = [...candidateArgs, '--no-pager', '-n', '1'];
|
|
497
|
+
const res = await runCommand('journalctl', testArgs);
|
|
498
|
+
const out = (res.stdout || res.stderr || '').trim();
|
|
499
|
+
|
|
500
|
+
if (res.code === 0 && !out.includes('No journal files')) {
|
|
501
|
+
if (!chosenCandidate) {
|
|
502
|
+
chosenCandidate = candidateArgs;
|
|
503
|
+
}
|
|
504
|
+
if (!out.includes('No entries') && !out.includes('0 entries')) {
|
|
505
|
+
chosenCandidate = candidateArgs;
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
489
509
|
}
|
|
490
510
|
|
|
511
|
+
const workingCandidate = chosenCandidate || ['--user', '-u', unitFilename];
|
|
512
|
+
|
|
491
513
|
if (opts.follow) {
|
|
492
|
-
|
|
514
|
+
const followArgs = [...workingCandidate, '-f'];
|
|
515
|
+
if (opts.lines) {
|
|
516
|
+
followArgs.push('-n', String(opts.lines));
|
|
517
|
+
}
|
|
518
|
+
if (opts.cat || opts.output === 'cat') {
|
|
519
|
+
followArgs.push('-o', 'cat');
|
|
520
|
+
} else if (opts.output) {
|
|
521
|
+
followArgs.push('-o', opts.output);
|
|
522
|
+
}
|
|
493
523
|
try {
|
|
494
|
-
const child = spawn('journalctl',
|
|
524
|
+
const child = spawn('journalctl', followArgs, { stdio: 'inherit', shell: false });
|
|
495
525
|
child.on('error', () => {});
|
|
496
526
|
return child;
|
|
497
527
|
} catch {
|
|
498
528
|
return null;
|
|
499
529
|
}
|
|
500
|
-
}
|
|
501
|
-
baseArgs.push('--no-pager');
|
|
502
|
-
const lines = opts.lines ? String(opts.lines) : '100';
|
|
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
|
-
}
|
|
530
|
+
}
|
|
517
531
|
|
|
518
|
-
|
|
532
|
+
const staticArgs = [...workingCandidate, '--no-pager'];
|
|
533
|
+
if (opts.cat || opts.output === 'cat') {
|
|
534
|
+
staticArgs.push('-o', 'cat');
|
|
535
|
+
} else if (opts.output) {
|
|
536
|
+
staticArgs.push('-o', opts.output);
|
|
519
537
|
}
|
|
538
|
+
const lines = opts.lines ? String(opts.lines) : '100';
|
|
539
|
+
staticArgs.push('-n', lines);
|
|
540
|
+
|
|
541
|
+
const res = await runCommand('journalctl', staticArgs);
|
|
542
|
+
return res.stdout || res.stderr || 'No logs found.';
|
|
520
543
|
}
|