6 # Print the message to standard error end exit with error code specified
7 # by the second argument.
10 # - The default error message.
12 # - ${1} - The whole error message, be sure to quote. Optional
13 # - ${2} - the code to exit with, default: 1.
16 warn "${1:-Unspecified run-time error occurred!}"
21 function set_eligibility_off {
22 # Set Nomad eligibility to ineligible for scheduling. Fail otherwise.
26 node_id="$(nomad node status | grep $(hostname) | cut -d ' ' -f 1)" || die
27 node_status="$(nomad node status | grep $(hostname))" || die
29 if [[ "${node_status}" != *"ineligible"* ]]; then
30 nomad node eligibility -disable "${node_id}" || die
31 node_status="$(nomad node status | grep $(hostname))" || die
32 if [[ "${node_status}" != *"ineligible"* ]]; then
33 die "Set eligibility off failed!"
39 function set_eligibility_on {
40 # Set Nomad eligibility to eligible for scheduling. Fail otherwise.
44 node_id="$(nomad node status | grep $(hostname) | cut -d ' ' -f 1)" || die
45 node_status="$(nomad node status | grep $(hostname))" || die
47 if [[ "${node_status}" == *"ineligible"* ]]; then
48 nomad node eligibility -enable "${node_id}" || die
49 node_status="$(nomad node status | grep $(hostname))" || die
50 if [[ "${node_status}" == *"ineligible"* ]]; then
51 die "Set eligibility on failed!"
57 function restart_vfs_service {
58 # Stop and start VF serice. This will reinitialize VFs and driver mappings.
62 warn "Restarting VFs service (this may take few minutes)..."
63 sudo service csit-initialize-vfs stop || die "Failed to stop VFs service!"
64 sudo service csit-initialize-vfs start || die "Failed to start VFs service!"
68 function wait_for_pending_containers {
69 # Wait in loop for defined amount of time for pending containers to
70 # gracefully quit them. If parameter force is specified. Force kill them.
73 # - ${@} - Script parameters.
79 containers=(docker ps --quiet --filter name=csit*)
81 for i in $(seq 1 ${retries}); do
82 mapfile -t pending_containers < <( ${containers[@]} ) || die
83 warn "Waiting for pending containers [${pending_containers[@]}] ..."
84 if [ ${#pending_containers[@]} -eq 0 ]; then
87 sleep "${wait_time}" || die
89 if [ ${#pending_containers[@]} -ne 0 ]; then
90 if [[ "${1-}" == "force" ]]; then
91 warn "Force killing [${pending_containers[@]}] ..."
92 docker rm --force ${pending_containers[@]} || die
94 die "Still few containers running!"
101 # Print the message to standard error.
104 # - ${@} - The text of the message.
110 set_eligibility_off || die
111 wait_for_pending_containers "${@}" || die
112 restart_vfs_service || die
113 set_eligibility_on || die