Fix race condition in collect_ceph_status.sh
There is a race condition between collect_ceph_status.sh writing the status file and check_ceph_status.py reading that file. This patch fixes that by directing ceph output into a temp file, and then replacing the old state file with the new temp file using an atomic mv operation. Change-Id: If332d187f8dcb9f7fcd8b4a47f791beb8e27eaaa Closes-Bug: 1755207
This commit is contained in:
parent
8134a12bc5
commit
5dbafb0b2f
|
@ -14,5 +14,11 @@ DATA_DIR="/var/lib/nagios"
|
|||
if [ ! -d $DATA_DIR ]; then
|
||||
mkdir -p $DATA_DIR
|
||||
fi
|
||||
DATA_FILE="${DATA_DIR}/cat-ceph-status.txt"
|
||||
TMP_FILE=$(mktemp -p ${DATA_DIR})
|
||||
|
||||
ceph status --format json >${DATA_DIR}/cat-ceph-status.txt
|
||||
ceph status --format json >${TMP_FILE}
|
||||
|
||||
chown root:nagios ${TMP_FILE}
|
||||
chmod 0640 ${TMP_FILE}
|
||||
mv ${TMP_FILE} ${DATA_FILE}
|
||||
|
|
Loading…
Reference in New Issue