Wakanda Server scripted clean shutdown

前端 未结 5 1625
野趣味
野趣味 2021-01-18 18:51

What is best practice to perform a clean shutdown of a Wakanda server via OS X shell scripting?

This would be with a solution currently loaded and operating.

5条回答
  •  清酒与你
    2021-01-18 18:57

    The best practice for the upcoming release 1.1.0 :

    • Handle the applicationWillStop event on a service to handle app specific closing logic
    • service wakanda stop for Ubuntu and a normal kill for Mac OS ( kill -9 should always be the last resort after some kind of timeout but this should not be necessary anymore)

    The best practice for the current release 1.0.x :

    • Prepare server stop by using an HTTP Request Handler or another method (make sure to secure this very well and accept connections only from localhost)
    • service wakanda stop for Ubuntu and a normal kill for Mac OS ( kill -9 should always be the last resort after some kind of timeout but this should not be necessary anymore)

    More details :

    We should make a distinction between an HTTP Server like Apache and an application server like Wakanda Server.

    For example, when you are using a SharedWorker in Wakanda, your are creating a separate thread that is going to run some code. Suppose that worker is doing some kind of critical data manipulation. If you let the server close that worker for you, it might cause data incoherence in your application. You should therefore handle any business logic specific "clean" close before the server stops the app.

    Starting from version 1.1.0, instead of creating a special HTTP Request Handler that you can call to prepare the server's stop, you can use a service that handles the event applicationWillStop.

    When the server receives a blockable kill signal ( TERM, QUIT, INT ), it will start the stopping process ( The following is true for version 1.1.x of Wakanda Digital App Factory ) :

    • Notify every service of the event applicationWillStop
    • Notify every service of the event httpServerWillStop
    • Wait for all services code execution to be done - Services are called one at a time (the server waits for the code handling the event to end its execution before calling the next service) -
    • Refuse any new incoming HTTP Requests
    • Process all HTTP requests in the HTTP Server's queue
    • Ask all the workers and threads executing JS code to stop the execution (including request handlers code).
    • Check if there are any threads/JS Contexts still active, if it is the case wait maximum 5 seconds.
    • The server forces all JavaScript contexts to stop the execution and kills all the remaining threads
    • The server waits for the threads to be closed
    • The server stops

    In the versions prior to 1.1.0 the server asks the workers to close before notifying the services about the closing events. That is why we couldn't rely on the services to do a clean close of the SharedWorkers.

提交回复
热议问题