unitup 0.0.3 → 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 +43 -14
- package/src/unit.js +1 -0
package/package.json
CHANGED
package/src/systemd.js
CHANGED
|
@@ -479,31 +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 args = ['--user', `_SYSTEMD_USER_UNIT=${unitFilename}`];
|
|
484
|
-
|
|
485
|
-
if (opts.cat || opts.output === 'cat') {
|
|
486
|
-
args.push('-o', 'cat');
|
|
487
|
-
} else if (opts.output) {
|
|
488
|
-
args.push('-o', opts.output);
|
|
489
|
-
}
|
|
482
|
+
const syslogId = `unitup-${safeName}`;
|
|
490
483
|
|
|
491
484
|
if (opts.follow) {
|
|
492
|
-
|
|
493
|
-
|
|
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
|
+
}
|
|
494
491
|
try {
|
|
495
|
-
const child = spawn('journalctl',
|
|
492
|
+
const child = spawn('journalctl', followArgs, { stdio: 'inherit', shell: false });
|
|
496
493
|
child.on('error', () => {});
|
|
497
494
|
return child;
|
|
498
495
|
} catch {
|
|
499
496
|
return null;
|
|
500
497
|
}
|
|
501
|
-
}
|
|
502
|
-
|
|
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
|
+
}
|
|
503
516
|
const lines = opts.lines ? String(opts.lines) : '100';
|
|
504
517
|
args.push('-n', lines);
|
|
505
518
|
|
|
506
519
|
const res = await runCommand('journalctl', args);
|
|
507
|
-
|
|
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
|
+
}
|
|
508
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.';
|
|
509
538
|
}
|