firmware/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher-json

45 lines
1.0 KiB
Bash

#!/bin/sh
test -f /tmp/started || exit
# Allow only one instance
lockfile="/var/lock/${0##*/}.json.lock"
if ! lock -n "$lockfile"; then
echo "Only one instance of $0 allowed."
exit 1
fi
trap "lock -u \"$lockfile\"" INT TERM EXIT
[ -s /etc/config/nodewatcher ] || exit 1
[ "$(uci get nodewatcher.@script[0].disabled)" = "1" ] && exit 0
SCRIPT_DATA_FILE=$(uci get nodewatcher.@script[0].data_file).json
debug() {
(>&2 echo "nodewatcher: $1")
}
#This method generates the crawl data JSON file that is being fetched by netmon
#and provided by a small local httpd
crawl() {
debug "Putting all information into a JSON-File and save it at $SCRIPT_DATA_FILE"
for f in /usr/lib/nodewatcher-json.d/*.sh; do
tmp="$($f)"
if [ $? -ne 0 ]; then
debug "Error when executing subscript $f, exiting!"
exit 1
fi
done
SCRIPT_DATA_DIR=$(dirname "$SCRIPT_DATA_FILE")
test -d "$SCRIPT_DATA_DIR" || mkdir -p "$SCRIPT_DATA_DIR"
}
LANG=C
#Erzeugt die statusdaten
debug "Generate actual status data"
crawl
exit 0