unitup 0.0.7 → 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 +42 -37
package/package.json
CHANGED
package/src/systemd.js
CHANGED
|
@@ -481,8 +481,40 @@ export async function runJournalctlLogs(name, opts = {}) {
|
|
|
481
481
|
const unitFilename = getUnitFilename(safeName);
|
|
482
482
|
const syslogId = `unitup-${safeName}`;
|
|
483
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
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const workingCandidate = chosenCandidate || ['--user', '-u', unitFilename];
|
|
512
|
+
|
|
484
513
|
if (opts.follow) {
|
|
485
|
-
const followArgs = [
|
|
514
|
+
const followArgs = [...workingCandidate, '-f'];
|
|
515
|
+
if (opts.lines) {
|
|
516
|
+
followArgs.push('-n', String(opts.lines));
|
|
517
|
+
}
|
|
486
518
|
if (opts.cat || opts.output === 'cat') {
|
|
487
519
|
followArgs.push('-o', 'cat');
|
|
488
520
|
} else if (opts.output) {
|
|
@@ -497,42 +529,15 @@ export async function runJournalctlLogs(name, opts = {}) {
|
|
|
497
529
|
}
|
|
498
530
|
}
|
|
499
531
|
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
['-u', `unitup-${safeName}`],
|
|
506
|
-
['-t', syslogId]
|
|
507
|
-
];
|
|
508
|
-
|
|
509
|
-
for (const candidateArgs of candidateArgSets) {
|
|
510
|
-
const args = [...candidateArgs, '--no-pager'];
|
|
511
|
-
if (opts.cat || opts.output === 'cat') {
|
|
512
|
-
args.push('-o', 'cat');
|
|
513
|
-
} else if (opts.output) {
|
|
514
|
-
args.push('-o', opts.output);
|
|
515
|
-
}
|
|
516
|
-
const lines = opts.lines ? String(opts.lines) : '100';
|
|
517
|
-
args.push('-n', lines);
|
|
518
|
-
|
|
519
|
-
const res = await runCommand('journalctl', args);
|
|
520
|
-
const out = (res.stdout || res.stderr || '').trim();
|
|
521
|
-
|
|
522
|
-
if (
|
|
523
|
-
out &&
|
|
524
|
-
!out.includes('No journal files') &&
|
|
525
|
-
!out.includes('No entries') &&
|
|
526
|
-
!out.includes('0 entries') &&
|
|
527
|
-
res.code === 0
|
|
528
|
-
) {
|
|
529
|
-
return out;
|
|
530
|
-
}
|
|
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);
|
|
531
537
|
}
|
|
538
|
+
const lines = opts.lines ? String(opts.lines) : '100';
|
|
539
|
+
staticArgs.push('-n', lines);
|
|
532
540
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
if (opts.cat || opts.output === 'cat') fallbackArgs.push('-o', 'cat');
|
|
536
|
-
const defaultRes = await runCommand('journalctl', fallbackArgs);
|
|
537
|
-
return defaultRes.stdout || defaultRes.stderr || 'No logs found.';
|
|
541
|
+
const res = await runCommand('journalctl', staticArgs);
|
|
542
|
+
return res.stdout || res.stderr || 'No logs found.';
|
|
538
543
|
}
|