Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wakanda Server scripted clean shutdown

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.

like image 338
Kirk Avatar asked Feb 27 '16 15:02

Kirk


2 Answers

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.

like image 185
hamzahik Avatar answered Sep 26 '22 13:09

hamzahik


With all the suggestions for using kill -9, please be aware that kill -9 does not shut down the Wakanda server in a gently manner.

We use it for several years now and shutting the server down this way still causes data corruption in some cases. Especially when you have shared workers working with the database in the background. Wakanda does not cleanly stop the workers.

Our current solution to minimize the problem is: 1. Sent a REST-request to Wakanda to stop the workers (you have to write your own server side method for this). This will still won't shutdown the processes in all cases! 2. Trying to kill the server without -9 parameter (up to three times) 3. If the Wakanda server is still alive, use kill -9

Btw. we asked for this a long time ago. Some reliable commandline tool like: rcwakanda start/stop/restart similar to other services like apache would be helpful.

like image 45
Michael Hong Avatar answered Sep 22 '22 13:09

Michael Hong