How does Jenkins receive TERM/SIGTERM signal?

I’m running Jenkins in a Kubernetes container, and I see that when the pod is deleted, the clean up method for Jenkins is not called. However, when I upgrade the Jenkins version through the Jenkins UI, the application is cleaned up as part of shutting down.

Does Jenkins code handle the TERM/SIGTERM signal (which Kubernetes sends to the application when the pod is being terminated) at all?
Otherwise, how can I ensure that my Jenkins application is properly cleaned up when running it in a Kubernetes container?

1 Like

are you meaning in pipeline?

I believe UI does a safeRestart, which waits for jobs to be finished. Kubernetes doesn’t really have the concept of “Don’t kill this pod yet”

I don’t know the answer to your question though.

Thanks @halkeye - we ended using the PreStop K8s hook and running a script that will call the safeExit api, so we can clean up the Jenkins instance before the container terminates.