Check out this blog post . This is a βwonderfulβ way to gracefully terminate the streaming job I encountered.
How to transmit a shutdown signal:
Now we know how to provide a graceful shutdown in a spark stream. But how can we transmit a shutdown signal for sparking. One naive option is to use the CTRL + C command on the terminal screen, where we run the driver program, but obviously this is not a good option. One of the solutions I use is the grep process of driving a spark stream and sending a SIGTERM signal. When the driver receives this signal, it initiates a graceful shutdown of the application. We can write a command, as shown below, in some shell script and run the script to send a shutdown signal:
ps -ef | greek spark | grep | awk '{print $ 2}' | xargs kill -SIGTERM
eg. ps -ef | greek spark | grep DataPipelineStreamDriver | awk '{print $ 2}' | xargs kill -SIGTERM
source share