Wakanda Server completed a clean shutdown

What is the best way to perform a clean shutdown of a Wakanda server using OS X shell scripts?

This will be with the solution currently loaded and working.

+5
source share
5 answers

Best practices for the upcoming 1.1.0 release:

  • Refer to the applicationWillStop event on service to handle the closing logic of the application.
  • service wakanda stop for Ubuntu and normal kill for Mac OS ( kill -9 should always be the last resort after some timeout, but this is no longer necessary)

Best practice for current version 1.0.x:

  • Prepare the server shutdown using the HTTP Request Handler or another method (make sure this is very good and only accept connections from localhost)
  • service wakanda stop for Ubuntu and normal kill for Mac OS ( kill -9 should always be the last resort after some timeout, but this is no longer necessary)

More details:

We must distinguish between an HTTP server such as Apache and an application server such as Wakanda Server.

For example, when you use SharedWorker in Wakanda, you create a separate thread that will run some code. Suppose an employee performs some kind of critical processing of data. If you allow the server to close this worker for you, this can lead to incoherence of data in your application. Therefore, you must process any โ€œlogicalโ€ business logic by closing it before the server stops the application.

Starting with version 1.1.0, instead of creating a special HTTP Request Handler , which you can call to prepare for a server shutdown, you can use a service that processes the applicationWillStop event.

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

  • Notify each service about applicationWillStop event
  • Notify each service of the httpServerWillStop event
  • Wait until the entire service code is executed - Services are called one at a time (the server waits for the code to process the event that completed its execution before the next service is called) -
  • Refuse any new incoming HTTP requests
  • Process all HTTP requests in the HTTP server queue
  • Ask all workers and threads to execute JS code to stop execution (including request handler code).
  • Check if there are any threads / JS Contexts are still active, if so, wait a maximum of 5 seconds.
  • The server forces all JavaScript contexts to stop execution and kills all remaining topics
  • The server is waiting for threads to close.
  • Server is stopping

In versions prior to 1.1.0, the server asks workers to close before notifying services of closing events. Thatโ€™s why we couldnโ€™t rely on services to perform a clean shutdown of SharedWorkers .

+6
source

With all suggestions for using kill -9, remember that kill -9 does not close the Wakanda server carefully.

We have been using it for several years, and shutting down the server this way still causes data corruption in some cases. Especially when you exchanged employees working with the database in the background. Wakanda does not stop workers from being clean.

Our current solution to minimize the problem is: 1. Sent a REST request to Wakanda to stop workers (for this you need to write your own server-side method). This all the same will not stop processes in all cases! 2. Attempt to kill the server without the -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 command line tool such as: rcwakanda start / stop / restart is similar to other services such as apache.

+5
source

This shell script is tested on Mac OS:

 #killWakanda.sh pids=$(pgrep $1) kill -9 $pids 

Depends on the fact that you are using the Enterprise community version for the Wakanda version. The Wakanda server name can be passed as a parameter (Wakanda Server or Wakanda Enterprise Server):

It kills the Wakanda Enterprise server

 sh /pathOfShellScript/killWakanda.sh Wakanda Enterprise Server 

It kills the Wakanda community server

 sh /pathOfShellScript/killWakanda.sh Wakanda Server 
+3
source

I had the same experience as Michael Hung. I would not use kill -9 to close the Wakanda server. This does not gracefully shut down workers and can lead to data corruption. The correct way to shut down the Wakanda server is using the solution.quitServer () function, as described here: http://doc.wakanda.org/home2.en.html#/Global-Application/Solution/quitServer.301-635546.en.html

My solution was to have one common worker who manages all the other workers (the "work manager"). An RPC / REST call can be called to call a "work manager" to exit the server. The work manager then calls on all other workers to give them time to gracefully close. Then after X seconds, the working manager calls the .quitServer () solution.

+3
source

When starting Wakanda Server as a background process, you can completely stop it using the process ID and the kill -sigterm .

Sigterm

A SIGTERM signal is sent to the process to request its completion. Unlike a SIGKILL signal, it can be caught, interpreted, or ignored by a process. This allows the process to perform an excellent cessation of freeing resources and maintaining state if necessary. SIGINT is almost identical to SIGTERM.

Here is a sample code that demonstrates this:

 ps -A | grep wakanda-server kill -SIGTERM pid_from_line_above 

Note: you must replace pid_from_line_above with the PID that is returned by ps -A | grep wakanda-server ps -A | grep wakanda-server


For your bash script, something like this may occur:

 killall -TERM /Applications/Wakanda\ Server.app/Contents/MacOS/Wakanda\ Server sleep 15 killall -KILL /Applications/Wakanda\ Server.app/Contents/MacOS/Wakanda\ Server 

The script first sends a normal termination signal to the process, then waits 15 seconds before sending the kill signal to the process, forcing it to exit.

Reminder: kill -SIGKILL PID cannot be caught or ignored.

Sigkill

A SIGKILL signal is sent to a process to cause it to kill immediately. Unlike SIGTERM and SIGINT, this signal cannot be caught or ignored, and the receiving process will not be able to clear when this signal is received.


Although the best way to do this might be to use LaunchDaemon, as suggested in response to osx startupitems shell script does not launch the application

See also: Administering Wakanda Server for Unix

+1
source

Source: https://habr.com/ru/post/1244011/


All Articles