fix(cli): Refactor logs command to use child_process spawn for real-time log tailing
This commit is contained in:
20
ts/cli.ts
20
ts/cli.ts
@@ -131,8 +131,24 @@ export class NupstCli {
|
||||
*/
|
||||
private async logs(): Promise<void> {
|
||||
try {
|
||||
const logs = execSync('journalctl -u nupst.service -n 50 -f').toString();
|
||||
console.log(logs);
|
||||
// Use exec with spawn to properly follow logs in real-time
|
||||
const { spawn } = await import('child_process');
|
||||
console.log('Tailing nupst service logs (Ctrl+C to exit)...\n');
|
||||
|
||||
const journalctl = spawn('journalctl', ['-u', 'nupst.service', '-n', '50', '-f'], {
|
||||
stdio: ['ignore', 'inherit', 'inherit']
|
||||
});
|
||||
|
||||
// Forward signals to child process
|
||||
process.on('SIGINT', () => {
|
||||
journalctl.kill('SIGINT');
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// Wait for process to exit
|
||||
await new Promise<void>((resolve) => {
|
||||
journalctl.on('exit', () => resolve());
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to retrieve logs:', error);
|
||||
process.exit(1);
|
||||
|
Reference in New Issue
Block a user