Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do custom shutdown on SIGTERM with Akka?

Tags:

akka

By default, Akka shuts down the actor system(s) when it receives a SIGTERM. How can I override this behaviour to do my custom shutdown logic before shutting down the akka system? I already have this logic implemented in the actors, using special graceful stop messages - I just need to invoke that logic when the SIGTERM is received.

Or do I have to use some other way of shutting down the application? That is also an option.

like image 463
Robin Green Avatar asked Feb 22 '13 10:02

Robin Green


1 Answers

You can just use sys.shutdownHookThread like this:

def main(args: Array[String]) {
  ... initialization code ...
  sys.shutdownHookThread {
    println "Shutting down ..."
    shutdownHandler ! DoSomething
  }
}
like image 76
rs_atl Avatar answered Nov 02 '22 11:11

rs_atl