From 960f0236186d311a9651eae0f87a5115b865b658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Guti=C3=A9rrez=20Hermoso?= Date: Mon, 29 Jul 2024 16:28:55 -0400 Subject: [PATCH] restart: gracefully handle restart failure 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. --- app/server/lib/FlexServer.ts | 13 +++++++++---- sandbox/supervisor.mjs | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/server/lib/FlexServer.ts b/app/server/lib/FlexServer.ts index 15429b2d..240d8195 100644 --- a/app/server/lib/FlexServer.ts +++ b/app/server/lib/FlexServer.ts @@ -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({ + error: "Cannot automatically restart the Grist server to enact changes. Please restart server manually." + }); + } + return resp.status(200).send({ msg: 'ok' }); })); // Restrict this endpoint to install admins diff --git a/sandbox/supervisor.mjs b/sandbox/supervisor.mjs index 832d42df..f7178f3c 100644 --- a/sandbox/supervisor.mjs +++ b/sandbox/supervisor.mjs @@ -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') {