Skip to content

Commit

Permalink
Fix ineffective wait for background job termination
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LarsMichelsen committed Dec 12, 2024
1 parent 8b1d163 commit 7fce267
Showing 1 changed file with 40 additions and 34 deletions.
74 changes: 40 additions & 34 deletions omd/packages/check_mk/skel/etc/init.d/ui-job-scheduler
Original file line number Diff line number Diff line change
Expand Up @@ -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...'
Expand All @@ -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)
Expand Down

0 comments on commit 7fce267

Please sign in to comment.