mirror of
https://github.com/OpenNebula/one.git
synced 2026-12-03 21:52:31 +09:00
M #-: Remove .monitor file when it's not needed (#1897)
This commit is contained in:
1 parent
da065a2fc7
commit
dcc76f4b29
3 files changed
+6
-90
No files matched your search
@@ -1,78 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
#Arguments: hypervisor ds_location monitord_port monitor_push_period host_id hostname
|
||||
HYPERVISOR=$1
|
||||
DATASTORE_LOCATION=${2:-"/var/lib/one/datastores"}
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
REMOTES_DIR="${DRIVER_PATH}/../.."
|
||||
|
||||
mkdir -p "$DATASTORE_LOCATION"
|
||||
|
||||
declare -A SEEN
|
||||
read -r SRC DS_TOTAL_MB DS_USED_MB DS_FREE_MB \
|
||||
<<< $(df -B1M --output=source,size,used,avail $DATASTORE_LOCATION \
|
||||
2>/dev/null | tail -n1)
|
||||
|
||||
# mark the the datasore location SRC as seen
|
||||
SEEN[$SRC]=1
|
||||
|
||||
for DS in $(ls $DATASTORE_LOCATION); do
|
||||
echo $DS | grep -q -E '^[0123456789]+$' || continue
|
||||
|
||||
DIR=$DATASTORE_LOCATION/$DS
|
||||
|
||||
test -d "$DIR" || continue
|
||||
|
||||
read -r SRC TOTAL_MB USED_MB FREE_MB \
|
||||
<<< $(df -B1M --output=source,size,used,avail $DIR \
|
||||
2>/dev/null | tail -n1)
|
||||
|
||||
USED_MB=${USED_MB:-"0"}
|
||||
TOTAL_MB=${TOTAL_MB:-"0"}
|
||||
FREE_MB=${FREE_MB:-"0"}
|
||||
|
||||
echo "DS = ["
|
||||
echo " ID = $DS,"
|
||||
echo " USED_MB = $USED_MB,"
|
||||
echo " TOTAL_MB = $TOTAL_MB,"
|
||||
echo " FREE_MB = $FREE_MB"
|
||||
echo "]"
|
||||
|
||||
# If didn't seen yet add it to the total
|
||||
if [ "${SEEN[$SRC]}" = "" ]; then
|
||||
SEEN[$SRC]=1
|
||||
DS_USED_MB=$((( $DS_USED_MB + $USED_MB )))
|
||||
DS_TOTAL_MB=$((( $DS_TOTAL_MB + $TOTAL_MB )))
|
||||
DS_FREE_MB=$((( $DS_FREE_MB + $FREE_MB )))
|
||||
fi
|
||||
|
||||
# Skip if datastore is not marked for local monitoring
|
||||
[ -e "${DIR}/.monitor" ] || continue
|
||||
|
||||
DRIVER=$(cat ${DIR}/.monitor)
|
||||
[ -z "$DRIVER" ] && DRIVER="ssh" # default is ssh
|
||||
|
||||
SCRIPT_PATH="${REMOTES_DIR}/tm/$DRIVER/monitor_ds"
|
||||
[ -e "$SCRIPT_PATH" ] && "$SCRIPT_PATH" "$DIR"
|
||||
done
|
||||
|
||||
echo "DS_LOCATION_USED_MB=$DS_USED_MB"
|
||||
echo "DS_LOCATION_TOTAL_MB=$DS_TOTAL_MB"
|
||||
echo "DS_LOCATION_FREE_MB=$DS_FREE_MB"
|
||||
@@ -578,10 +578,10 @@ if [ ! -d $2 ]; then
|
||||
mkdir -p $2
|
||||
fi
|
||||
|
||||
MONITOR_FN="\$(dirname $2)/.monitor"
|
||||
|
||||
# create or update .monitor content
|
||||
if [ -n "$3" ]; then
|
||||
MONITOR_FN="\$(dirname $2)/.monitor"
|
||||
|
||||
MONITOR=''
|
||||
if [ -f "\\${MONITOR_FN}" ]; then
|
||||
MONITOR="\\$(cat "\\${MONITOR_FN}" 2>/dev/null)"
|
||||
@@ -590,6 +590,9 @@ if [ -n "$3" ]; then
|
||||
if [ "x\\${MONITOR}" != "x$3" ]; then
|
||||
echo "$3" > "\\${MONITOR_FN}"
|
||||
fi
|
||||
else
|
||||
# remove .monitor file (to avoid errors on driver change)
|
||||
rm -f "\\${MONITOR_FN}"
|
||||
fi
|
||||
EOF`
|
||||
SSH_EXEC_RC=$?
|
||||
|
||||
+1
-10
@@ -69,17 +69,8 @@ if [[ "$LCM_STATE" =~ ^(16|60|61)$ ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# preserve .monitor content (if any)
|
||||
MONITOR_CMD=$(cat <<EOF
|
||||
if [ -r '${SRC_DIR}/.monitor' ]; then
|
||||
cat '${SRC_DIR}/.monitor' 2>/dev/null || :
|
||||
fi
|
||||
EOF
|
||||
)
|
||||
|
||||
MONITOR=$(ssh_monitor_and_log "$SRC_HOST" "$MONITOR_CMD" 'Get .monitor')
|
||||
|
||||
ssh_make_path "$DST_HOST" "$DST_PATH" "$MONITOR"
|
||||
ssh_make_path "$DST_HOST" "$DST_PATH"
|
||||
|
||||
RANDOM_FILE=$(ssh "$DST_HOST" "mktemp -p \"$DST_DIR\"")
|
||||
trap "ssh $DST_HOST \"rm -f $RANDOM_FILE\"" EXIT
|
||||
|
||||
Reference in new issue
Block a user