@@ -484,16 +484,26 @@ function startListen() {
484484 if ( config . usessl ) {
485485 server . listen ( config . port , function ( ) {
486486 logger . info ( 'HTTPS Server listening at port %d' , config . port ) ;
487+ config . maintenance = false ;
487488 } ) ;
488489 } else {
489490 server . listen ( config . port , function ( ) {
490491 logger . info ( 'HTTP Server listening at port %d' , config . port ) ;
492+ config . maintenance = false ;
491493 } ) ;
492494 }
493495}
494496
495497// sync db then start listen
496- models . sequelize . sync ( ) . then ( startListen ) ;
498+ models . sequelize . sync ( ) . then ( function ( ) {
499+ // check if realtime is ready
500+ if ( realtime . isReady ( ) ) {
501+ models . Revision . checkAllNotesRevision ( function ( err , notes ) {
502+ if ( err ) return new Error ( err ) ;
503+ if ( notes . length <= 0 ) return startListen ( ) ;
504+ } ) ;
505+ }
506+ } ) ;
497507
498508// log uncaught exception
499509process . on ( 'uncaughtException' , function ( err ) {
@@ -510,21 +520,18 @@ process.on('SIGINT', function () {
510520 Object . keys ( io . sockets . sockets ) . forEach ( function ( key ) {
511521 var socket = io . sockets . sockets [ key ] ;
512522 // notify client server going into maintenance status
513- socket . emit ( 'maintenance' , config . version ) ;
523+ socket . emit ( 'maintenance' ) ;
514524 socket . disconnect ( true ) ;
515525 } ) ;
516526 var checkCleanTimer = setInterval ( function ( ) {
517- var usersCount = Object . keys ( realtime . users ) . length ;
518- var notesCount = Object . keys ( realtime . notes ) . length ;
519- // check if all users and notes array are empty
520- if ( usersCount == 0 && notesCount == 0 ) {
521- // close db connection
522- models . sequelize . close ( ) ;
523- clearInterval ( checkCleanTimer ) ;
524- // wait for a while before exit
525- setTimeout ( function ( ) {
526- process . exit ( 0 ) ;
527- } , 100 ) ;
527+ if ( realtime . isReady ( ) ) {
528+ models . Revision . checkAllNotesRevision ( function ( err , notes ) {
529+ if ( err ) return new Error ( err ) ;
530+ if ( notes . length <= 0 ) {
531+ clearInterval ( checkCleanTimer ) ;
532+ return process . exit ( 0 ) ;
533+ }
534+ } ) ;
528535 }
529536 } , 100 ) ;
530537} ) ;
0 commit comments