Skip to content

Commit

Permalink
restart: gracefully handle restart failure
Browse files Browse the repository at this point in the history
In case Grist isn't running with the supervisor (e.g. it's running
under nodemon instead via `yarn start`), surface the problem to the
frontend.
  • Loading branch information
jordigh committed Jul 29, 2024
1 parent 024d0b5 commit 4e93041
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 9 additions & 4 deletions app/server/lib/FlexServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1886,10 +1886,15 @@ export class FlexServer implements GristServer {
process.send({ action: 'restart' });
}
});
// On the topic of http response codes, thus spake MDN:
// "409: This response is sent when a request conflicts with the current state of the server."
const status = process.send ? 200 : 409;
return resp.status(status).send();

if(!process.env.GRIST_RUNNING_UNDER_SUPERVISOR) {
// On the topic of http response codes, thus spake MDN:
// "409: This response is sent when a request conflicts with the current state of the server."
return resp.status(409).send({
msg: "Grist must run under the supervisor process in order to restart."
});
}
return resp.status(200).send({ msg: 'ok' });
}));

// Restrict this endpoint to install admins
Expand Down
3 changes: 2 additions & 1 deletion sandbox/supervisor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ let grist;
function startGrist(newConfig={}) {
// H/T https://stackoverflow.com/a/36995148/11352427
grist = spawn('./sandbox/run.sh', {
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
env: {...process.env, GRIST_RUNNING_UNDER_SUPERVISOR: true}
});
grist.on('message', function(data) {
if (data.action === 'restart') {
Expand Down

0 comments on commit 4e93041

Please sign in to comment.