From 7fce26748f58dedcebdc3cb6410be3a65c512e6e Mon Sep 17 00:00:00 2001 From: Lars Michelsen Date: Thu, 12 Dec 2024 13:29:21 +0100 Subject: [PATCH] Fix ineffective wait for background job termination When stopping the site, at some point we need to ensure that all background jobs are stopped. The intention was to do this in ui-job-scheduler init script, but the code was not accessible before. Change-Id: Icb57aad697ad50d669290ae71d33674aefb1789d --- .../check_mk/skel/etc/init.d/ui-job-scheduler | 74 ++++++++++--------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/omd/packages/check_mk/skel/etc/init.d/ui-job-scheduler b/omd/packages/check_mk/skel/etc/init.d/ui-job-scheduler index 96e1d2ccc4e..784f663ab76 100755 --- a/omd/packages/check_mk/skel/etc/init.d/ui-job-scheduler +++ b/omd/packages/check_mk/skel/etc/init.d/ui-job-scheduler @@ -38,6 +38,45 @@ exit_failure() { exit 1 } +stop_ui_scheduler() { + echo -n 'Stopping ui-job-scheduler...' + if [ -z "$THE_PID" ]; then + exit_successfully 'not running.' + fi + + if ! process_is_running; then + exit_successfully 'not running (PID file orphaned)' + fi + + echo -n "killing $THE_PID..." + if ! kill "$THE_PID" 2>/dev/null; then + exit_successfully 'OK' + fi + + # Signal could be sent + + # Patiently wait for the process to stop + if await_process_stop 60; then + exit_successfully 'OK' + fi + + # Insist on killing the process + force_kill + if await_process_stop 10; then + exit_successfully 'OK' + fi + exit_failure 'failed' +} + +wait_for_background_jobs() { + echo -n "Waiting for background-jobs to finish..." + if cmk-wait-for-background-jobs; then + exit_successfully 'OK' + else + exit_failure "Failed (some were still running)" + fi +} + case "$1" in start) echo -n 'Starting ui-job-scheduler...' @@ -53,40 +92,7 @@ case "$1" in fi ;; stop) - echo -n 'Stopping ui-job-scheduler...' - if [ -z "$THE_PID" ]; then - exit_successfully 'not running.' - fi - - if ! process_is_running; then - exit_successfully 'not running (PID file orphaned)' - fi - - echo -n "killing $THE_PID..." - if ! kill "$THE_PID" 2>/dev/null; then - exit_successfully 'OK' - fi - - # Signal could be sent - - # Patiently wait for the process to stop - if await_process_stop 60; then - exit_successfully 'OK' - fi - - # Insist on killing the process - force_kill - if await_process_stop 10; then - exit_successfully 'OK' - fi - exit_failure 'failed' - - echo -n "Waiting for background-jobs to finish..." - if cmk-wait-for-background-jobs; then - echo "OK" - else - echo "Failed (some were still running)" - fi + (stop_ui_scheduler) && wait_for_background_jobs ;; restart)