Merge pull request #3682 from overleaf/bg-check-maintenance-file

check maintenance file periodically to close site

GitOrigin-RevId: 8e29f40a23df96198c6e4603ede2bab852b98740
This commit is contained in:
Brian Gough 2021-02-25 10:49:24 +00:00 committed by Copybot
parent 54212385e6
commit bc4f5a687a
6 changed files with 35 additions and 19 deletions

View file

@ -10,8 +10,14 @@ const {
module.exports = { module.exports = {
check(req, res, next) { check(req, res, next) {
// detach from express for cleaner stack traces if (!settings.siteIsOpen || !settings.editorIsOpen) {
setTimeout(() => runSmokeTestsDetached(req, res).catch(next)) // always return successful health checks when site is closed
res.contentType('application/json')
res.sendStatus(200)
} else {
// detach from express for cleaner stack traces
setTimeout(() => runSmokeTestsDetached(req, res).catch(next))
}
}, },
checkActiveHandles(req, res, next) { checkActiveHandles(req, res, next) {

View file

@ -98,11 +98,13 @@ const AdminController = {
return res.render('admin/register') return res.render('admin/register')
}, },
dissconectAllUsers: (req, res) => { disconnectAllUsers: (req, res) => {
logger.warn('disconecting everyone') logger.warn('disconecting everyone')
const delay = (req.query && req.query.delay) > 0 ? req.query.delay : 10
EditorRealTimeController.emitToAll( EditorRealTimeController.emitToAll(
'forceDisconnect', 'forceDisconnect',
'Sorry, we are performing a quick update to the editor and need to close it down. Please refresh the page to continue.' 'Sorry, we are performing a quick update to the editor and need to close it down. Please refresh the page to continue.',
delay
) )
return res.sendStatus(200) return res.sendStatus(200)
}, },

View file

@ -954,9 +954,9 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
AdminController.closeEditor AdminController.closeEditor
) )
webRouter.post( webRouter.post(
'/admin/dissconectAllUsers', '/admin/disconnectAllUsers',
AuthorizationMiddleware.ensureUserIsSiteAdmin, AuthorizationMiddleware.ensureUserIsSiteAdmin,
AdminController.dissconectAllUsers AdminController.disconnectAllUsers
) )
webRouter.post( webRouter.post(
'/admin/flushProjectToTpds', '/admin/flushProjectToTpds',
@ -981,14 +981,20 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
privateApiRouter.post( privateApiRouter.post(
'/disconnectAllUsers', '/disconnectAllUsers',
AdminController.dissconectAllUsers AdminController.disconnectAllUsers
) )
privateApiRouter.get('/perfTest', (req, res) => res.send('hello')) privateApiRouter.get('/perfTest', (req, res) => res.send('hello'))
publicApiRouter.get('/status', (req, res) => publicApiRouter.get('/status', (req, res) => {
res.send('web sharelatex is alive (web)') if (!Settings.siteIsOpen) {
) res.send('web site is closed (web)')
} else if (!Settings.editorIsOpen) {
res.send('web editor is closed (web)')
} else {
res.send('web sharelatex is alive (web)')
}
})
privateApiRouter.get('/status', (req, res) => privateApiRouter.get('/status', (req, res) =>
res.send('web sharelatex is alive (api)') res.send('web sharelatex is alive (api)')
) )

View file

@ -42,7 +42,7 @@ block content
p.small Will stop anyone opening the editor. Will NOT disconnect already connected users. p.small Will stop anyone opening the editor. Will NOT disconnect already connected users.
.row-spaced .row-spaced
form(method='post',action='/admin/dissconectAllUsers') form(method='post',action='/admin/disconnectAllUsers')
input(name="_csrf", type="hidden", value=csrfToken) input(name="_csrf", type="hidden", value=csrfToken)
button.btn.btn-danger(type="submit") Disconnect all users button.btn.btn-danger(type="submit") Disconnect all users
p.small Will force disconnect all users with the editor open. Make sure to close the editor first to avoid them reconnecting. p.small Will force disconnect all users with the editor open. Make sure to close the editor first to avoid them reconnecting.

View file

@ -25,7 +25,6 @@ block content
.global-alerts(ng-cloak ng-hide="editor.error_state") .global-alerts(ng-cloak ng-hide="editor.error_state")
.alert.alert-danger.small(ng-if="connection.forced_disconnect") .alert.alert-danger.small(ng-if="connection.forced_disconnect")
strong #{translate("disconnected")} strong #{translate("disconnected")}
| #{translate("please_refresh")}
.alert.alert-warning.small(ng-if="connection.reconnection_countdown") .alert.alert-warning.small(ng-if="connection.reconnection_countdown")
strong #{translate("lost_connection")}. strong #{translate("lost_connection")}.

View file

@ -249,22 +249,25 @@ export default ConnectionManager = (function() {
// Site administrators can send the forceDisconnect event to all users // Site administrators can send the forceDisconnect event to all users
this.ide.socket.on('forceDisconnect', message => { this.ide.socket.on('forceDisconnect', (message, delay = 10) => {
this.updateConnectionManagerState('inactive') this.updateConnectionManagerState('inactive')
this.shuttingDown = true // prevent reconnection attempts
this.$scope.$apply(() => { this.$scope.$apply(() => {
this.$scope.permissions.write = false this.$scope.permissions.write = false
return (this.$scope.connection.forced_disconnect = true) return (this.$scope.connection.forced_disconnect = true)
}) })
this.ide.socket.disconnect() // flush changes before disconnecting
this.ide.showGenericMessageModal( this.ide.$scope.$broadcast('flush-changes')
'Please Refresh', setTimeout(() => this.ide.socket.disconnect(), 1000)
this.ide.showLockEditorMessageModal(
'Please wait',
`\ `\
We're performing maintenance on Overleaf and you need to refresh the editor. We're performing maintenance on Overleaf and you need to wait a moment.
Sorry for any inconvenience. Sorry for any inconvenience.
The editor will refresh in automatically in 10 seconds.\ The editor will refresh automatically in ${delay} seconds.\
` `
) )
return setTimeout(() => location.reload(), 10 * 1000) return setTimeout(() => location.reload(), delay * 1000)
}) })
this.ide.socket.on('reconnectGracefully', () => { this.ide.socket.on('reconnectGracefully', () => {