BLOCKDEV=blockdev
REGLOOKUP=reglookup
CHNTPW=chntpw
+DATE="date -u" # Time in UTC
CLEANUP=( )
ERRORS=( )
WARNINGS=( )
+MSG_TYPE_TASK_START="TASK_START"
+MSG_TYPE_TASK_END="TASK_END"
+
+STDERR_LINE_SIZE=10
+
add_cleanup() {
local cmd=""
for arg; do cmd+=$(printf "%q " "$arg"); done
}
warn() {
- WARNINGS+=("$@")
echo "Warning: $@" >&2
+ echo "WARNING:$@" > "$MONITOR"
}
-report_start_task() {
-
- local type="start-task"
- local timestamp=$(date +%s.%N)
- local name="${PROGNAME}"
-
- report="{\"id\":\"$id\","
- report+="\"type\":\"$type\"," \
- report+="\"timestamp\":$(date +%s.%N)," \
- report+="\"name\":\"$name\"}"
-
- echo "$report" > "$MONITOR"
+report_task_start() {
+ echo "$MSG_TYPE_TASK_START:${PROGNAME:2}" > "$MONITOR"
}
-json_list() {
- declare -a items=("${!1}")
- report="["
- for item in "${items[@]}"; do
- report+="\"$(sed 's/"/\\"/g' <<< "$item")\","
- done
- if [ ${#report} -gt 1 ]; then
- # remove last comma(,)
- report="${report%?}"
- fi
- report+="]"
-
- echo "$report"
+report_task_end() {
+ echo "$MSG_TYPE_TASK_END:${PROGNAME:2}" > "$MONITOR"
}
-report_end_task() {
-
- local type="end-task"
- local timestam=$(date +%s.%N)
- local name=${PROGNAME}
- local warnings=$(json_list WARNINGS[@])
-
- report="{\"id\":\"$id\","
- report+="\"type\":\"$type\"," \
- report+="\"timestamp\":$(date +%s)," \
- report+="\"name\":\"$name\"," \
- report+="\"warnings\":\"$warnings\"}"
-
- echo "$report" > "$MONITOR"
+report_error() {
+ if [ ${#ERRORS[*]} -eq 0 ]; then
+ # No error message. Print stderr
+ local lines=$(tail --lines=${STDERR_LINE_SIZE} "$STDERR_FILE" | wc -l)
+ echo -n "STDERR:${lines}:" > "$MONITOR"
+ tail --lines=$lines "$STDERR_FILE" > "$MONITOR"
+ else
+ echo -n "ERROR:" > "$MONITOR"
+ for line in "${ERRORS[@]}"; do
+ echo "$line" > "$MONITOR"
+ done
+ fi
}
-report_error() {
- local type="ganeti-error"
- local timestamp=$(date +%s.%N)
- local location="${PROGNAME}"
- local errors=$(json_list ERRORS[@])
- local warnings=$(json_list WARNINGS[@])
- local stderr="$(cat "$STDERR_FILE" | sed 's/"/\\"/g')"
-
- report="{\"id\":\"$id\","
- report+="\"type\":\"$type\"," \
- report+="\"timestamp\":$(date +%s)," \
- report+="\"location\":\"$location\"," \
- report+="\"errors\":$errors," \
- report+="\"warnings\":$warnings," \
- report+="\"stderr\":\"$stderr\"}"
-
- echo "$report" > "$MONITOR"
+system_poweroff() {
+ echo o > /proc/sysrq-trigger
}
get_base_distro() {
echo "suse"
elif [ -e "$root_dir/etc/gentoo-release" ]; then
echo "gentoo"
+ elif [ -e "$root_dir/etc/arch-release" ]; then
+ echo "arch"
else
warn "Unknown base distro."
fi
echo "suse"
elif [ -e "$root_dir/etc/gentoo-release" ]; then
echo "gentoo"
+ elif [ -e "$root_dir/etc/arch-release" ]; then
+ echo "arch"
else
warn "Unknown distro."
fi
rc=$?
if [ $rc -eq 0 ]; then
- report_end_task
+ report_task_end
else
report_error
fi
}
check_if_excluded() {
-
- local exclude=SNF_IMAGE_PROPERTY_EXCLUDE_TASK_${PROGNAME:2}
+ local name="$(tr [a-z] [A-Z] <<< ${PROGNAME:2})"
+ local exclude="SNF_IMAGE_PROPERTY_EXCLUDE_TASK_${name}"
if [ -n "${!exclude}" ]; then
- warn "Task $PROGNAME was excluded and will not run."
+ warn "Task ${PROGNAME:2} was excluded and will not run."
exit 0
fi