Currently, when shutting down CDAP in CM, the CSD just sends the master process a SIGTERM. Master proceeds to shut all containers and itself down. However, if this is a multi-service shutdown/restart, CM goes on and could potentially shutdown Yarn before Master can gracefully shutdown.
Instead, the CSD can configure a stopRunner to run a script which can wait and confirm for shutdown. We may however need master to expose the state of the containers to do this. Currently Router shutdown is independent, so not sure if we can rely on the api. Also, need to think about how this would work in HA... ideally only the active master waits for containers.
The CSD has the capability of running a stopRunner instead of just sending the SIGTERM it currenty does.