unitup 0.0.1 → 0.0.3
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/README.md +17 -6
- package/bin/unitup.js +0 -0
- package/index.d.ts +11 -0
- package/package.json +2 -2
- package/src/cli.js +14 -1
- package/src/systemd.js +10 -7
- package/src/unit.js +3 -1
package/README.md
CHANGED
|
@@ -277,19 +277,30 @@ unitup status api --raw
|
|
|
277
277
|
|
|
278
278
|
### `unitup logs <name>`
|
|
279
279
|
|
|
280
|
-
|
|
280
|
+
View or stream systemd journalctl logs for a service.
|
|
281
281
|
|
|
282
282
|
```bash
|
|
283
283
|
# View last 100 log lines (default)
|
|
284
|
-
unitup logs
|
|
284
|
+
unitup logs app
|
|
285
285
|
|
|
286
|
-
#
|
|
287
|
-
unitup logs
|
|
286
|
+
# Stream logs in real-time
|
|
287
|
+
unitup logs app --follow
|
|
288
288
|
|
|
289
|
-
#
|
|
290
|
-
unitup logs
|
|
289
|
+
# View last 50 lines of clean raw console output without systemd metadata prefix
|
|
290
|
+
unitup logs app -c --lines 50
|
|
291
|
+
# or
|
|
292
|
+
unitup logs app --cat --lines 50
|
|
293
|
+
|
|
294
|
+
# Specify custom journalctl output format
|
|
295
|
+
unitup logs app --output=json
|
|
291
296
|
```
|
|
292
297
|
|
|
298
|
+
**Options:**
|
|
299
|
+
- `-f`, `--follow`: Stream logs in real time.
|
|
300
|
+
- `-n`, `--lines <N>`: Specify number of log lines to show (default: 100).
|
|
301
|
+
- `-c`, `--cat`: Format log output cleanly without systemd timestamp/hostname metadata prefix (`journalctl -o cat`).
|
|
302
|
+
- `--output <format>`: Custom journalctl output mode (e.g. `cat`, `short`, `json`).
|
|
303
|
+
|
|
293
304
|
---
|
|
294
305
|
|
|
295
306
|
### `unitup list`
|
package/bin/unitup.js
CHANGED
|
File without changes
|
package/index.d.ts
CHANGED
|
@@ -72,6 +72,17 @@ export interface LogOptions {
|
|
|
72
72
|
* @default 100
|
|
73
73
|
*/
|
|
74
74
|
lines?: number;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Raw unformatted console output (-o cat) without systemd metadata prefix.
|
|
78
|
+
* @default false
|
|
79
|
+
*/
|
|
80
|
+
cat?: boolean;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Journalctl output mode (e.g. 'cat', 'short', 'json').
|
|
84
|
+
*/
|
|
85
|
+
output?: string;
|
|
75
86
|
}
|
|
76
87
|
|
|
77
88
|
/**
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unitup",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Minimal systemd user service wrapper for Node.js scripts",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": {
|
|
9
|
-
"unitup": "
|
|
9
|
+
"unitup": "bin/unitup.js"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"test": "node --test test/*.test.js"
|
package/src/cli.js
CHANGED
|
@@ -38,6 +38,8 @@ export function parseArgs(argv) {
|
|
|
38
38
|
enable: false,
|
|
39
39
|
raw: false,
|
|
40
40
|
follow: false,
|
|
41
|
+
cat: false,
|
|
42
|
+
output: '',
|
|
41
43
|
lines: 100,
|
|
42
44
|
help: false,
|
|
43
45
|
version: false
|
|
@@ -114,6 +116,15 @@ export function parseArgs(argv) {
|
|
|
114
116
|
} else if (arg === '-f' || arg === '--follow') {
|
|
115
117
|
result.flags.follow = true;
|
|
116
118
|
i++;
|
|
119
|
+
} else if (arg === '-c' || arg === '--cat') {
|
|
120
|
+
result.flags.cat = true;
|
|
121
|
+
i++;
|
|
122
|
+
} else if (arg === '--output') {
|
|
123
|
+
result.flags.output = argv[i + 1] || '';
|
|
124
|
+
i += 2;
|
|
125
|
+
} else if (arg.startsWith('--output=')) {
|
|
126
|
+
result.flags.output = arg.slice(9);
|
|
127
|
+
i++;
|
|
117
128
|
} else if (!arg.startsWith('-')) {
|
|
118
129
|
if (!result.command) {
|
|
119
130
|
result.command = arg;
|
|
@@ -308,7 +319,9 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
308
319
|
}
|
|
309
320
|
const output = await runJournalctlLogs(name, {
|
|
310
321
|
follow: flags.follow,
|
|
311
|
-
lines: flags.lines
|
|
322
|
+
lines: flags.lines,
|
|
323
|
+
cat: flags.cat,
|
|
324
|
+
output: flags.output
|
|
312
325
|
});
|
|
313
326
|
if (typeof output === 'string') {
|
|
314
327
|
console.log(output);
|
package/src/systemd.js
CHANGED
|
@@ -480,17 +480,16 @@ export async function runJournalctlLogs(name, opts = {}) {
|
|
|
480
480
|
const safeName = sanitizeServiceName(name);
|
|
481
481
|
const unitFilename = getUnitFilename(safeName);
|
|
482
482
|
|
|
483
|
-
const args = ['--user',
|
|
483
|
+
const args = ['--user', `_SYSTEMD_USER_UNIT=${unitFilename}`];
|
|
484
484
|
|
|
485
|
-
if (opts.
|
|
486
|
-
args.push('-
|
|
487
|
-
} else {
|
|
488
|
-
args.push('
|
|
489
|
-
const lines = opts.lines ? String(opts.lines) : '100';
|
|
490
|
-
args.push('-n', lines);
|
|
485
|
+
if (opts.cat || opts.output === 'cat') {
|
|
486
|
+
args.push('-o', 'cat');
|
|
487
|
+
} else if (opts.output) {
|
|
488
|
+
args.push('-o', opts.output);
|
|
491
489
|
}
|
|
492
490
|
|
|
493
491
|
if (opts.follow) {
|
|
492
|
+
args.push('-f');
|
|
494
493
|
// Spawn stream for follow mode
|
|
495
494
|
try {
|
|
496
495
|
const child = spawn('journalctl', args, { stdio: 'inherit', shell: false });
|
|
@@ -500,6 +499,10 @@ export async function runJournalctlLogs(name, opts = {}) {
|
|
|
500
499
|
return null;
|
|
501
500
|
}
|
|
502
501
|
} else {
|
|
502
|
+
args.push('--no-pager');
|
|
503
|
+
const lines = opts.lines ? String(opts.lines) : '100';
|
|
504
|
+
args.push('-n', lines);
|
|
505
|
+
|
|
503
506
|
const res = await runCommand('journalctl', args);
|
|
504
507
|
return res.stdout || res.stderr || 'No logs found.';
|
|
505
508
|
}
|
package/src/unit.js
CHANGED
|
@@ -87,7 +87,9 @@ export function generateUnitContent(opts) {
|
|
|
87
87
|
`WorkingDirectory=${cwd}`,
|
|
88
88
|
`ExecStart=${execStartLine}`,
|
|
89
89
|
`Restart=${restartPolicy}`,
|
|
90
|
-
'RestartSec=3'
|
|
90
|
+
'RestartSec=3',
|
|
91
|
+
'StandardOutput=journal',
|
|
92
|
+
'StandardError=journal'
|
|
91
93
|
];
|
|
92
94
|
|
|
93
95
|
const envObj = opts.env && typeof opts.env === 'object' ? { ...opts.env } : {};
|