ruby-on-railskubernetessidekiqlifecyclegraceful-shutdown

sidekiqctl stop halting the further execution of commands in preStop on devtron


Trying to run sidekiqctl stop in preStop hook of pod lifecycle, doing so to gracefully shutdown sidekiq process while pod termination.

Script that I'm trying to execute in preStop hook

    echo "Stopping sidekiq..."
    for pid in $SIDEKIQ_PIDS/*.pid; do
      echo "Stopping specific pid..."
      bundle exec sidekiqctl stop $pid 30
      echo "removing pid file"
      rm -rf $pid
    done
    echo "done"

Expected behaviour:

Sidekiq process should gracefully shutdown and all the echo statement should be printed

Actual behaviour:

it's running fine till sidekiqctl stop command. I have the checked the pod logs, sidekiq shutdown logs are getting captured but no further echo command are getting executing that leads to preStopFailed event.

Pod logs: enter image description here

Note:

Have tried various method to debug the sidekiqctl stop commands output like running it in background then waiting for that that process to compelete and Also tried by increasing the graceTimeout and sidekiqctl command timeout still the same issue.


Solution

  • After a lot of hit and trial, reached on below conclusion

    NOTE: don't forget to add >> /proc/1/fd/1 2>&1 for log redirection, it helped in debugging.