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:
bulldozer-balena[bot] 2021-02-24 17:50:03 +00:00 committed by GitHub
commit 85a5a861d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;