Skip to content

Commit

Permalink
Merge pull request #202 from sap-contributions/ensure-monit-unmonitor…
Browse files Browse the repository at this point in the history
…-succeeds

Ensure that job is unmonitored before monitoring it again
  • Loading branch information
MarcPaquette committed Oct 4, 2021
2 parents 6e3ae10 + c594b5c commit 1fb8f22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions jobs/cloud_controller_ng/templates/restart_drain.sh.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

source /var/vcap/jobs/cloud_controller_ng/packages/capi_utils/monit_utils.sh

PIDFILE="/var/vcap/sys/run/cloud_controller_ng/restart_drain.pid"

# As this script might run longer than a monit cycle (10s) and thus might be
Expand All @@ -9,7 +11,7 @@ PIDFILE="/var/vcap/sys/run/cloud_controller_ng/restart_drain.pid"
function on_exit {
# Re-enable monitoring of ccng_monit_http_healthcheck. This also enables
# monitoring of nginx_cc and cloud_controller_ng.
/var/vcap/bosh/bin/monit monitor ccng_monit_http_healthcheck
monit_monitor_job ccng_monit_http_healthcheck
rm -f $PIDFILE
}

Expand All @@ -22,6 +24,6 @@ echo "$(date) - pid: $BASHPID - Monit triggered shutdown drain" >> "$LOGFILE"
# Unmonitor cloud_controller_ng. This also unmonitors nginx_cc and
# ccng_monit_http_healthcheck. Monit should not interfere with the graceful
# shutdown.
/var/vcap/bosh/bin/monit unmonitor cloud_controller_ng
monit_unmonitor_job cloud_controller_ng

/var/vcap/jobs/cloud_controller_ng/bin/shutdown_drain 1>&2
11 changes: 11 additions & 0 deletions src/capi_utils/monit_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ function wait_for_server_to_become_healthy() {
return 1
}

# monit_monitor_job
#
# @param job_name
#
# Tells monit to monitor the given job.
#
function monit_monitor_job() {
local job_name="$1"
sudo /var/vcap/bosh/bin/monit monitor "${job_name}"
}

# monit_unmonitor_job
#
# @param job_name
Expand Down

0 comments on commit 1fb8f22

Please sign in to comment.