2024-06-13 21:45:41 +00:00
|
|
|
import {spawn} from 'child_process';
|
|
|
|
|
|
|
|
let grist;
|
|
|
|
|
|
|
|
function startGrist(newConfig={}) {
|
|
|
|
// H/T https://stackoverflow.com/a/36995148/11352427
|
|
|
|
grist = spawn('./sandbox/run.sh', {
|
2024-07-29 20:28:55 +00:00
|
|
|
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
|
|
|
env: {...process.env, GRIST_RUNNING_UNDER_SUPERVISOR: true}
|
2024-06-13 21:45:41 +00:00
|
|
|
});
|
|
|
|
grist.on('message', function(data) {
|
|
|
|
if (data.action === 'restart') {
|
2024-07-22 14:00:07 +00:00
|
|
|
console.log('Restarting Grist with new configuration');
|
2024-06-13 21:45:41 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
startGrist();
|