Proper shutdown when scaling down docker containers

Let’s say we have 5 containers running an rpc server that replies to requests from clients. when scaling down to 4 containers via $docker service scale rpc=4 for example, i want to be able to manage all the saved requests in the container and dispatch them or whatever. so i kind of need a shutdown hook for docker containers when using the docker service API.