mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
2cb38709a5
This is a new entrypoint, mostly intended for Docker, so we have one simple process controlling the main Grist process. The purpose of this is to be able to make Grist easily restartable with a new environment.
36 lines
946 B
JavaScript
36 lines
946 B
JavaScript
import {spawn} from 'child_process';
|
|
|
|
let grist;
|
|
|
|
function startGrist(newConfig={}) {
|
|
saveNewConfig(newConfig);
|
|
// H/T https://stackoverflow.com/a/36995148/11352427
|
|
grist = spawn('./sandbox/run.sh', {
|
|
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
|
|
});
|
|
grist.on('message', function(data) {
|
|
if (data.action === 'restart') {
|
|
console.log('Restarting Grist with new environment');
|
|
|
|
// Note that we only set this event handler here, after we have
|
|
// a new environment to reload with. Small chance of a race here
|
|
// in case something else sends a SIGINT before we do it
|
|
// ourselves further below.
|
|
grist.on('exit', () => {
|
|
grist = startGrist(data.newConfig);
|
|
});
|
|
|
|
grist.kill('SIGINT');
|
|
}
|
|
});
|
|
return grist;
|
|
}
|
|
|
|
// Stub function
|
|
function saveNewConfig(newConfig) {
|
|
// TODO: something here to actually persist the new config before
|
|
// restarting Grist.
|
|
}
|
|
|
|
startGrist();
|