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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unitup",
3
- "version": "0.0.3",
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,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
- args.push('-f');
493
- // Spawn stream for follow mode
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', args, { stdio: 'inherit', shell: false });
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
- } else {
502
- args.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
+ }
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
- return res.stdout || res.stderr || 'No logs found.';
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
  }
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}`,