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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/systemd.js +45 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unitup",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Minimal systemd user service wrapper for Node.js scripts",
5
5
  "main": "src/index.js",
6
6
  "types": "./index.d.ts",
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
- baseArgs.push('-f');
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', ['--user', ...baseArgs], { stdio: 'inherit', shell: false });
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
- } else {
501
- baseArgs.push('--no-pager');
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
- 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
- }
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
  }