From e36de5a62d650f387ef883147c3734e32cc59275 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 17 Jun 2024 10:10:04 +0200 Subject: [PATCH] Merge pull request #18856 from overleaf/jpa-server-ce-shutdown [server-ce] improve shutdown procedure GitOrigin-RevId: 5a99868d17f597c366e42625cd39f05146dcb682 --- libraries/logger/log-level-checker.js | 1 + server-ce/Dockerfile | 1 + server-ce/init_preshutdown_scripts/00_close_site | 5 ++++- .../init_preshutdown_scripts/01_flush_document_updater | 1 + .../init_preshutdown_scripts/02_flush_project_history | 1 + server-ce/test/docker-compose.yml | 2 -- services/web/app/src/infrastructure/GracefulShutdown.js | 4 ---- services/web/scripts/disconnect_all_users.js | 9 ++++++--- 8 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libraries/logger/log-level-checker.js b/libraries/logger/log-level-checker.js index 05e9484f44..b1b041d037 100644 --- a/libraries/logger/log-level-checker.js +++ b/libraries/logger/log-level-checker.js @@ -12,6 +12,7 @@ class LogLevelChecker { this.checkLogLevel() // re-check log level every minute this.checkInterval = setInterval(this.checkLogLevel.bind(this), 1000 * 60) + this.checkInterval.unref() } stop() { diff --git a/server-ce/Dockerfile b/server-ce/Dockerfile index 13e87ccb9e..6802f657aa 100644 --- a/server-ce/Dockerfile +++ b/server-ce/Dockerfile @@ -101,6 +101,7 @@ ENV OPTIMISE_PDF "true" # ---------------------------------------------------------- ENV KILL_PROCESS_TIMEOUT 55 ENV KILL_ALL_PROCESSES_TIMEOUT 55 +ENV GRACEFUL_SHUTDOWN_DELAY_SECONDS 1 ENV NODE_ENV "production" ENV LOG_LEVEL "info" diff --git a/server-ce/init_preshutdown_scripts/00_close_site b/server-ce/init_preshutdown_scripts/00_close_site index 6e1a196872..fafc426b3f 100755 --- a/server-ce/init_preshutdown_scripts/00_close_site +++ b/server-ce/init_preshutdown_scripts/00_close_site @@ -18,9 +18,12 @@ EXIT_CODE="$?" if [ $EXIT_CODE -ne 0 ] then echo "scripts/disconnect_all_users.js failed with exit code $EXIT_CODE" + exit 1 fi # wait for disconnection -sleep 5 +while ! sv stop real-time-overleaf; do + sleep 1 +done exit 0 diff --git a/server-ce/init_preshutdown_scripts/01_flush_document_updater b/server-ce/init_preshutdown_scripts/01_flush_document_updater index 2e9af99316..0900fe5fac 100755 --- a/server-ce/init_preshutdown_scripts/01_flush_document_updater +++ b/server-ce/init_preshutdown_scripts/01_flush_document_updater @@ -9,6 +9,7 @@ EXIT_CODE="$?" if [ $EXIT_CODE -ne 0 ] then echo "document-updater/scripts/flush_all.js failed with exit code $EXIT_CODE" + exit 1 fi exit 0 diff --git a/server-ce/init_preshutdown_scripts/02_flush_project_history b/server-ce/init_preshutdown_scripts/02_flush_project_history index 47f08b4b91..f8ac51600c 100755 --- a/server-ce/init_preshutdown_scripts/02_flush_project_history +++ b/server-ce/init_preshutdown_scripts/02_flush_project_history @@ -9,6 +9,7 @@ EXIT_CODE="$?" if [ $EXIT_CODE -ne 0 ] then echo "project-history/scripts/flush_all.js failed with exit code $EXIT_CODE" + exit 1 fi exit 0 diff --git a/server-ce/test/docker-compose.yml b/server-ce/test/docker-compose.yml index c32c0d1201..60a8afbce3 100644 --- a/server-ce/test/docker-compose.yml +++ b/server-ce/test/docker-compose.yml @@ -2,8 +2,6 @@ version: '2.2' services: sharelatex: image: ${IMAGE_TAG_CE:-sharelatex/sharelatex:latest} - # TODO(das7pad): increase timeout after speeding up the graceful shutdown procedure - # stop_grace_period: 60s stop_grace_period: 0s depends_on: mongo: diff --git a/services/web/app/src/infrastructure/GracefulShutdown.js b/services/web/app/src/infrastructure/GracefulShutdown.js index 122edc9c72..2446397b1d 100644 --- a/services/web/app/src/infrastructure/GracefulShutdown.js +++ b/services/web/app/src/infrastructure/GracefulShutdown.js @@ -93,10 +93,6 @@ async function gracefulShutdown(server, signal) { 'optionalAfterDrainingConnections', optionalCleanupHandlersAfterDrainingConnections.concat([ { label: 'metrics module', handler: () => Metrics.close() }, - { - label: 'logger module', - handler: () => logger.logLevelChecker?.stop(), - }, ]) ) } catch (err) { diff --git a/services/web/scripts/disconnect_all_users.js b/services/web/scripts/disconnect_all_users.js index 16b3e51cc5..186d6fd346 100644 --- a/services/web/scripts/disconnect_all_users.js +++ b/services/web/scripts/disconnect_all_users.js @@ -19,7 +19,8 @@ async function main() { ) process.exit(1) } - if (Settings.overleaf && args['confirm-site-url'] !== Settings.siteUrl) { + const isSaaS = Boolean(Settings.overleaf) + if (isSaaS && args['confirm-site-url'] !== Settings.siteUrl) { console.error() console.error( 'Please confirm the environment you want to disconnect ALL USERS from by specifying the site URL aka PUBLIC_URL, e.g. --confirm-site-url=https://www.dev-overleaf.com for the dev-env' @@ -46,8 +47,10 @@ async function main() { `Disconnect all users from ${args['confirm-site-url']}, with delay ${delay}` ) - console.error(' Use CTRL+C in the next 5s to abort.') - await sleep(5 * 1000) + if (isSaaS) { + console.error(' Use CTRL+C in the next 5s to abort.') + await sleep(5 * 1000) + } await AdminController._sendDisconnectAllUsersMessage(delay) }