Rebuild WATCHDOG.
* Watchdog now only send message to log if Device is lost Signed-off-by: Stephan Wendel <me@stephanwe.de>
This commit is contained in:
parent
5978b857be
commit
943f78f5b5
51
webcamd
51
webcamd
@ -400,24 +400,30 @@ function shutdown {
|
|||||||
|
|
||||||
#### Watchdog Functions and Variables
|
#### Watchdog Functions and Variables
|
||||||
## Do not reuse previous functions!
|
## Do not reuse previous functions!
|
||||||
function get_cam_count {
|
function webcamd_watchdog {
|
||||||
local cam_count cfg
|
# Helper Functions
|
||||||
cfg="${WEBCAMD_CFG}"
|
function available {
|
||||||
cam_count="$(crudini --existing=file --get "${cfg}" | \
|
find ${1} &> /dev/null
|
||||||
sed '/webcamd/d' | wc -l)"
|
echo $?
|
||||||
echo "${cam_count}"
|
}
|
||||||
}
|
# local Vars
|
||||||
|
local get_conf_devices conf_cams avail_cams
|
||||||
function get_cam_avail {
|
# Init empty Arrays
|
||||||
local conf_cam avail missing
|
get_conf_devices=()
|
||||||
for (( i=1; i<="$(get_cam_count)"; i++ )); do
|
conf_cams=()
|
||||||
conf_cam="$(get_param "cam $i" device 2> /dev/null)"
|
# Grab devices from config file
|
||||||
avail="$(find ${conf_cam} 2> /dev/null | wc -l)"
|
get_conf_devices=("$(crudini --existing=file --get "${WEBCAMD_CFG}" | \
|
||||||
if [ "${avail}" -eq 0 ]; then
|
sed '/webcamd/d' | cut -d ' ' -f2)")
|
||||||
missing+=("${conf_cam}")
|
# Construct Array with configured Devices
|
||||||
fi
|
for gcd in ${get_conf_devices[*]}; do
|
||||||
|
conf_cams+=("$(crudini --get "${WEBCAMD_CFG}" "cam ${gcd}" "device" \
|
||||||
|
| awk '{print $1}')")
|
||||||
|
done
|
||||||
|
for cc in ${conf_cams[*]}; do
|
||||||
|
if [ "$(available ${cc})" -ne 0 ]; then
|
||||||
|
log_msg "WATCHDOG: Lost Device: "${cc}""
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
echo "${missing[@]}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#### MAIN
|
#### MAIN
|
||||||
@ -458,15 +464,10 @@ initial_check
|
|||||||
construct_streamer
|
construct_streamer
|
||||||
|
|
||||||
## Loop and Watchdog
|
## Loop and Watchdog
|
||||||
|
## In this case watchdog acts more like a "cable defect detector"
|
||||||
|
## The User gets a message if Device is lost.
|
||||||
while true ; do
|
while true ; do
|
||||||
log_msg "WATCHDOG: Gather Informations"
|
webcamd_watchdog
|
||||||
log_msg "WATCHDOG: Configured Cam(s): $(get_cam_count)"
|
|
||||||
if [ -n "$(get_cam_avail)" ]; then
|
|
||||||
log_msg "WATCHDOG: Lost Device(s): $(get_cam_avail)"
|
|
||||||
else
|
|
||||||
log_msg "WATCHDOG: All Device(s) present!"
|
|
||||||
fi
|
|
||||||
log_msg "WATCHDOG: Next Check in 2 minutes..."
|
|
||||||
sleep 120 & sleep_pid="$!"
|
sleep 120 & sleep_pid="$!"
|
||||||
wait "${sleep_pid}"
|
wait "${sleep_pid}"
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user