unitup 0.0.3 → 0.0.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unitup",
3
- "version": "0.0.3",
3
+ "version": "0.0.6",
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
@@ -480,30 +480,41 @@ export async function runJournalctlLogs(name, opts = {}) {
480
480
  const safeName = sanitizeServiceName(name);
481
481
  const unitFilename = getUnitFilename(safeName);
482
482
 
483
- const args = ['--user', `_SYSTEMD_USER_UNIT=${unitFilename}`];
483
+ const baseArgs = ['-u', unitFilename];
484
484
 
485
485
  if (opts.cat || opts.output === 'cat') {
486
- args.push('-o', 'cat');
486
+ baseArgs.push('-o', 'cat');
487
487
  } else if (opts.output) {
488
- args.push('-o', opts.output);
488
+ baseArgs.push('-o', opts.output);
489
489
  }
490
490
 
491
491
  if (opts.follow) {
492
- args.push('-f');
493
- // Spawn stream for follow mode
492
+ baseArgs.push('-f');
494
493
  try {
495
- const child = spawn('journalctl', args, { stdio: 'inherit', shell: false });
494
+ const child = spawn('journalctl', ['--user', ...baseArgs], { stdio: 'inherit', shell: false });
496
495
  child.on('error', () => {});
497
496
  return child;
498
497
  } catch {
499
498
  return null;
500
499
  }
501
500
  } else {
502
- args.push('--no-pager');
501
+ baseArgs.push('--no-pager');
503
502
  const lines = opts.lines ? String(opts.lines) : '100';
504
- args.push('-n', lines);
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
+ }
505
517
 
506
- const res = await runCommand('journalctl', args);
507
- return res.stdout || res.stderr || 'No logs found.';
518
+ return userOut || 'No logs found.';
508
519
  }
509
520
  }
package/src/unit.js CHANGED
@@ -84,6 +84,7 @@ export function generateUnitContent(opts) {
84
84
  '',
85
85
  '[Service]',
86
86
  'Type=simple',
87
+ `SyslogIdentifier=unitup-${safeName}`,
87
88
  `WorkingDirectory=${cwd}`,
88
89
  `ExecStart=${execStartLine}`,
89
90
  `Restart=${restartPolicy}`,