mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-27 11:58:34 +00:00
Refactor journalctl monitor to only spawn new process on exit
Change-type: patch Closes: #1591 Signed-off-by: Miguel Casqueira <miguel@balena.io>
This commit is contained in:
parent
64127b24d2
commit
898b72c7f7
@ -73,13 +73,18 @@ class LogMonitor {
|
|||||||
this.handleRow(row);
|
this.handleRow(row);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async (data: Buffer) => {
|
(data: Buffer) => {
|
||||||
log.error(
|
log.error('journalctl - balena.service stderr: ', data.toString());
|
||||||
'Non-empty stderr stream from journalctl log fetching: ',
|
},
|
||||||
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);
|
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,
|
onRow: (row: JournalRow) => void,
|
||||||
onError: (data: Buffer) => void,
|
onError: (data: Buffer) => void,
|
||||||
onClose?: () => void,
|
onClose?: () => void,
|
||||||
|
onExit?: () => void,
|
||||||
): ReturnType<typeof spawnJournalctl> {
|
): ReturnType<typeof spawnJournalctl> {
|
||||||
const journalctl = spawnJournalctl(options);
|
const journalctl = spawnJournalctl(options);
|
||||||
journalctl.stdout?.pipe(JSONstream.parse(true).on('data', onRow));
|
journalctl.stdout?.pipe(JSONstream.parse(true).on('data', onRow));
|
||||||
@ -120,6 +126,9 @@ class LogMonitor {
|
|||||||
if (onClose) {
|
if (onClose) {
|
||||||
journalctl.on('close', onClose);
|
journalctl.on('close', onClose);
|
||||||
}
|
}
|
||||||
|
if (onExit) {
|
||||||
|
journalctl.on('exit', onExit);
|
||||||
|
}
|
||||||
return journalctl;
|
return journalctl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +146,10 @@ class LogMonitor {
|
|||||||
},
|
},
|
||||||
(row: JournalRow) => this.handleRow(row),
|
(row: JournalRow) => this.handleRow(row),
|
||||||
async (data: Buffer) => {
|
async (data: Buffer) => {
|
||||||
log.error('journalctl backfill error: ', data.toString());
|
log.error(
|
||||||
|
`journalctl - container ${containerId} stderr: `,
|
||||||
|
data.toString(),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
this.containers[containerId].follow = true;
|
this.containers[containerId].follow = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user