Commit 9c76962d authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Add monitoring event for errors in create

parent e51d19e9
......@@ -32,7 +32,10 @@ network_backend_support="@network_backend_support@"
# internally.
MONITOR_FD=9
ERROR_TYPE="ganeti-error"
CLEANUP=( )
ERROR_MSGS=( )
add_cleanup() {
local cmd=""
......@@ -41,6 +44,7 @@ add_cleanup() {
}
log_error() {
ERROR_MSGS+=("$@")
echo "$@" >&2
}
......@@ -49,6 +53,35 @@ close_fd() {
eval "exec $fd>&-"
}
report_error() {
local error_file=$1
local id=$(sed 's/"/\\"/g' <<< "$INSTANCE_NAME")
local type="$ERROR_TYPE"
local location="host"
local msg="["
for err in "${ERROR_MSGS[@]}"; do
msg+="\"$(sed 's/"/\\"/g' <<< "$err")\","
done
if [ ${#msg} -gt 1 ]; then
# remove last comma (,)
msg="${msg%?}"
fi
msg+="]"
local stderr="$(cat "$error_file" | sed 's/"/\\"/g')"
report="{\"id\":\"$id\","
report+="\"type\":\"$type\"," \
report+="\"timestamp\":$(date +%s)," \
report+="\"location\":\"$location\"," \
report+="\"messages\":$msg," \
report+="\"stderr\":\"$stderr\"}"
eval "echo $(printf "%q" "$report") >&${MONITOR_FD}"
}
get_api5_arguments() {
GETOPT_RESULT=$*
# Note the quotes around `$TEMP': they are essential!
......@@ -296,8 +329,19 @@ EOF
}
cleanup() {
# if something fails here, it souldn't call cleanup again...
# Carefull this should be the first command in the function. We want to
# store the last exit code to see if cleanup was triggered by an abnormal
# termination of the script.
local rc=$?
local err_file=$1
# if something fails here, it souldn't call cleanup again...
trap - EXIT
if [ $rc -ne 0 -a -f "$err_file" ]; then
report_error "$err_file"
fi
if [ ${#CLEANUP[*]} -gt 0 ]; then
LAST_ELEMENT=$((${#CLEANUP[*]}-1))
REVERSE_INDEXES=$(seq ${LAST_ELEMENT} -1 0)
......
......@@ -22,8 +22,28 @@ set -o pipefail
. common.sh
ganeti_os_main
# Save stderr to a file
stderr=$(mktemp)
add_cleanup rm "$stderr"
exec 2> >(tee -a "$stderr" >&2)
monitor_pipe=$(mktemp -u)
mkfifo -m 600 "$monitor_pipe"
add_cleanup rm -f "$monitor_pipe"
if [ -n "$PROGRESS_MONITOR" ]; then
{ cat "$monitor_pipe" | tee >( $PROGRESS_MONITOR ) ; } &
else
cat "$monitor_pipe" &
fi
# Create file descriptor to monitor_pipe
eval "exec ${MONITOR_FD}>${monitor_pipe}"
add_cleanup close_fd ${MONITOR_FD}
trap "cleanup $(printf "%q" "$stderr")" EXIT
ganeti_os_main
case $BACKEND_TYPE in
local)
......@@ -47,20 +67,6 @@ case $BACKEND_TYPE in
;;
esac
monitor_pipe=$(mktemp -u)
mkfifo -m 600 "$monitor_pipe"
add_cleanup rm -f "$monitor_pipe"
if [ -z "$PROGRESS_MONITOR" ]; then
PROGRESS_MONITOR="cat"
fi
"$PROGRESS_MONITOR" "$monitor_pipe" &
# Create file descriptor to monitor_pipe
eval "exec ${MONITOR_FD}>${monitor_pipe}"
add_cleanup close_fd ${MONITOR_FD}
# If the target device is not a real block device we'll first losetup it.
# This is needed for file disks.
if [ ! -b "$blockdev" ]; then
......
......@@ -65,8 +65,8 @@
# PITHOS_DATA="/var/lib/pithos/data"
# PROGRESS_MONITOR: External program that monitors the progress of the image
# deployment. This program should accept as argument a named pipe file where
# snf-image outputs monitor messages.
# deployment. The snf-image monitor messages will be redirected to the standard
# input of this program.
# PROGRESS_MONITOR=""
# UNATTEND: This variables overwrites the unattend.xml file used when deploying
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment