unitup 0.0.6 → 0.0.7
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 +45 -27
package/package.json
CHANGED
package/src/systemd.js
CHANGED
|
@@ -479,42 +479,60 @@ 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
|
-
const baseArgs = ['-u', unitFilename];
|
|
484
|
-
|
|
485
|
-
if (opts.cat || opts.output === 'cat') {
|
|
486
|
-
baseArgs.push('-o', 'cat');
|
|
487
|
-
} else if (opts.output) {
|
|
488
|
-
baseArgs.push('-o', opts.output);
|
|
489
|
-
}
|
|
482
|
+
const syslogId = `unitup-${safeName}`;
|
|
490
483
|
|
|
491
484
|
if (opts.follow) {
|
|
492
|
-
|
|
485
|
+
const followArgs = ['--user', '-u', unitFilename, '-f'];
|
|
486
|
+
if (opts.cat || opts.output === 'cat') {
|
|
487
|
+
followArgs.push('-o', 'cat');
|
|
488
|
+
} else if (opts.output) {
|
|
489
|
+
followArgs.push('-o', opts.output);
|
|
490
|
+
}
|
|
493
491
|
try {
|
|
494
|
-
const child = spawn('journalctl',
|
|
492
|
+
const child = spawn('journalctl', followArgs, { stdio: 'inherit', shell: false });
|
|
495
493
|
child.on('error', () => {});
|
|
496
494
|
return child;
|
|
497
495
|
} catch {
|
|
498
496
|
return null;
|
|
499
497
|
}
|
|
500
|
-
}
|
|
501
|
-
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const candidateArgSets = [
|
|
501
|
+
['--user', '-u', unitFilename],
|
|
502
|
+
['--user', '-u', `unitup-${safeName}`],
|
|
503
|
+
['--user', '-t', syslogId],
|
|
504
|
+
['-u', unitFilename],
|
|
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
|
+
}
|
|
502
516
|
const lines = opts.lines ? String(opts.lines) : '100';
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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;
|
|
516
530
|
}
|
|
517
|
-
|
|
518
|
-
return userOut || 'No logs found.';
|
|
519
531
|
}
|
|
532
|
+
|
|
533
|
+
// Fallback return
|
|
534
|
+
const fallbackArgs = ['--user', '-u', unitFilename, '--no-pager', '-n', String(opts.lines || 100)];
|
|
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.';
|
|
520
538
|
}
|