mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 13:47:54 +00:00
Merge pull request #1592 from balena-io/1591-patch-journalctl-spawn
Refactor journalctl monitor to only spawn new process on exit
This commit is contained in:
commit
85a5a861d8
@ -73,13 +73,18 @@ class LogMonitor {
|
||||
this.handleRow(row);
|
||||
}
|
||||
},
|
||||
async (data: Buffer) => {
|
||||
log.error(
|
||||
'Non-empty stderr stream from journalctl log fetching: ',
|
||||
data.toString(),
|
||||
);
|
||||
(data: Buffer) => {
|
||||
log.error('journalctl - balena.service stderr: ', data.toString());
|
||||
},
|
||||
() => {
|
||||
// noop for closed
|
||||
},
|
||||
async () => {
|
||||
log.debug('balena.service journalctl process exit.');
|
||||
// On exit of process try to create another
|
||||
await delay(JOURNALCTL_ERROR_RETRY_DELAY);
|
||||
this.start();
|
||||
log.debug('Spawning another process to watch balena.service logs.');
|
||||
return this.start();
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -113,6 +118,7 @@ class LogMonitor {
|
||||
onRow: (row: JournalRow) => void,
|
||||
onError: (data: Buffer) => void,
|
||||
onClose?: () => void,
|
||||
onExit?: () => void,
|
||||
): ReturnType<typeof spawnJournalctl> {
|
||||
const journalctl = spawnJournalctl(options);
|
||||
journalctl.stdout?.pipe(JSONstream.parse(true).on('data', onRow));
|
||||
@ -120,6 +126,9 @@ class LogMonitor {
|
||||
if (onClose) {
|
||||
journalctl.on('close', onClose);
|
||||
}
|
||||
if (onExit) {
|
||||
journalctl.on('exit', onExit);
|
||||
}
|
||||
return journalctl;
|
||||
}
|
||||
|
||||
@ -137,7 +146,10 @@ class LogMonitor {
|
||||
},
|
||||
(row: JournalRow) => this.handleRow(row),
|
||||
async (data: Buffer) => {
|
||||
log.error('journalctl backfill error: ', data.toString());
|
||||
log.error(
|
||||
`journalctl - container ${containerId} stderr: `,
|
||||
data.toString(),
|
||||
);
|
||||
},
|
||||
() => {
|
||||
this.containers[containerId].follow = true;
|
||||
|
Loading…
Reference in New Issue
Block a user