How to safely terminate services, especially those that manage Persistent Entities?

How to safely terminate services, especially those that manage Persistent Entities?

This is already handled via Akka's CoordinatedShutdown, and Play and Lagom, both using Akka, have wired their lifecycles to this mechanism. They are set up such that when a SIGTERM signal is received, an orchestrated termination happens. In that termination, the node being SIGTERM'd notifies the peers it is leaving the cluster, entities running locally are removed and, eventually, moved to another node. Finally, direct TCP connection between nodes of the cluster is shutdown.