Merge pull request #18856 from overleaf/jpa-server-ce-shutdown

[server-ce] improve shutdown procedure

GitOrigin-RevId: 5a99868d17f597c366e42625cd39f05146dcb682
This commit is contained in:
Jakob Ackermann 2024-06-17 10:10:04 +02:00 committed by Copybot
parent 6980a44f8b
commit e36de5a62d
8 changed files with 14 additions and 10 deletions

View file

@ -12,6 +12,7 @@ class LogLevelChecker {
this.checkLogLevel() this.checkLogLevel()
// re-check log level every minute // re-check log level every minute
this.checkInterval = setInterval(this.checkLogLevel.bind(this), 1000 * 60) this.checkInterval = setInterval(this.checkLogLevel.bind(this), 1000 * 60)
this.checkInterval.unref()
} }
stop() { stop() {

View file

@ -101,6 +101,7 @@ ENV OPTIMISE_PDF "true"
# ---------------------------------------------------------- # ----------------------------------------------------------
ENV KILL_PROCESS_TIMEOUT 55 ENV KILL_PROCESS_TIMEOUT 55
ENV KILL_ALL_PROCESSES_TIMEOUT 55 ENV KILL_ALL_PROCESSES_TIMEOUT 55
ENV GRACEFUL_SHUTDOWN_DELAY_SECONDS 1
ENV NODE_ENV "production" ENV NODE_ENV "production"
ENV LOG_LEVEL "info" ENV LOG_LEVEL "info"

View file

@ -18,9 +18,12 @@ EXIT_CODE="$?"
if [ $EXIT_CODE -ne 0 ] if [ $EXIT_CODE -ne 0 ]
then then
echo "scripts/disconnect_all_users.js failed with exit code $EXIT_CODE" echo "scripts/disconnect_all_users.js failed with exit code $EXIT_CODE"
exit 1
fi fi
# wait for disconnection # wait for disconnection
sleep 5 while ! sv stop real-time-overleaf; do
sleep 1
done
exit 0 exit 0

View file

@ -9,6 +9,7 @@ EXIT_CODE="$?"
if [ $EXIT_CODE -ne 0 ] if [ $EXIT_CODE -ne 0 ]
then then
echo "document-updater/scripts/flush_all.js failed with exit code $EXIT_CODE" echo "document-updater/scripts/flush_all.js failed with exit code $EXIT_CODE"
exit 1
fi fi
exit 0 exit 0

View file

@ -9,6 +9,7 @@ EXIT_CODE="$?"
if [ $EXIT_CODE -ne 0 ] if [ $EXIT_CODE -ne 0 ]
then then
echo "project-history/scripts/flush_all.js failed with exit code $EXIT_CODE" echo "project-history/scripts/flush_all.js failed with exit code $EXIT_CODE"
exit 1
fi fi
exit 0 exit 0

View file

@ -2,8 +2,6 @@ version: '2.2'
services: services:
sharelatex: sharelatex:
image: ${IMAGE_TAG_CE:-sharelatex/sharelatex:latest} 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 stop_grace_period: 0s
depends_on: depends_on:
mongo: mongo:

View file

@ -93,10 +93,6 @@ async function gracefulShutdown(server, signal) {
'optionalAfterDrainingConnections', 'optionalAfterDrainingConnections',
optionalCleanupHandlersAfterDrainingConnections.concat([ optionalCleanupHandlersAfterDrainingConnections.concat([
{ label: 'metrics module', handler: () => Metrics.close() }, { label: 'metrics module', handler: () => Metrics.close() },
{
label: 'logger module',
handler: () => logger.logLevelChecker?.stop(),
},
]) ])
) )
} catch (err) { } catch (err) {

View file

@ -19,7 +19,8 @@ async function main() {
) )
process.exit(1) 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()
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' '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}` `Disconnect all users from ${args['confirm-site-url']}, with delay ${delay}`
) )
if (isSaaS) {
console.error(' Use CTRL+C in the next 5s to abort.') console.error(' Use CTRL+C in the next 5s to abort.')
await sleep(5 * 1000) await sleep(5 * 1000)
}
await AdminController._sendDisconnectAllUsersMessage(delay) await AdminController._sendDisconnectAllUsersMessage(delay)
} }