testing wait_trigger
This commit is contained in:
parent
fabd452de9
commit
cf118ee75d
@ -1,17 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
fifo=""
|
||||
|
||||
GIT_SSL_NO_VERIFY=true
|
||||
|
||||
init_fifo () {
|
||||
trap rm -f ${fifo} EXIT
|
||||
trap "rm -f $fifo" EXIT
|
||||
if [ $? -eq 0 ]; then
|
||||
# set trap
|
||||
if [[ ! -p ${fifo} ]]; then
|
||||
mkfifo ${fifo}
|
||||
if [[ ! -p "$fifo" ]]; then
|
||||
mkfifo "$fifo"
|
||||
if [ $? -eq 0 ]; then
|
||||
# fifo created
|
||||
echo "created fifo=$fifo"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
@ -20,26 +22,30 @@ init_fifo () {
|
||||
}
|
||||
|
||||
read_config() {
|
||||
fifo_dir=$(cat ${1} | jq -r .fifo_dir)
|
||||
fifo="${fifo_dir}/$(cat ${1} | jq -r .fifo)"
|
||||
fifo_dir=$(cat "$1" | jq -r .fifo_dir)
|
||||
if [ -z "$fifo_dir" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
fifo=$(cat "$1" | jq -r .fifo)
|
||||
if [ -z "$fifo" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
fifo="${fifo_dir}/$fifo"
|
||||
return 0
|
||||
}
|
||||
|
||||
if read_config UpdateController.conf; then
|
||||
echo "fifo=$fifo"
|
||||
#init_fifo "$fifo"
|
||||
fi
|
||||
|
||||
wait_for_trigger() {
|
||||
if [[ "$1" -eq -1 ]]; then
|
||||
# wait for external impulse
|
||||
if read line <$fifo; then
|
||||
if [ "$line" == "quit" ] || [ "$line" == "update" ]; then
|
||||
if [ "$line" = "quit" ] || [ "$line" = "update" ]; then
|
||||
echo "$line"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
sleep ${1}
|
||||
sleep $1
|
||||
echo "sleep"
|
||||
fi
|
||||
}
|
||||
@ -116,16 +122,18 @@ UpdateController() {
|
||||
# from some external source to perform an update.
|
||||
while :
|
||||
do
|
||||
request=$(wait_for_trigger $trigger_timeout)
|
||||
if [ ${request} = "quit" ]; then
|
||||
trigger=$(wait_for_trigger $trigger_timeout)
|
||||
echo "trigger=$trigger"
|
||||
if [ "$trigger" = "quit" ]; then
|
||||
$trigger_reboot = true
|
||||
elif [ ${request} != "update" ]; then
|
||||
elif [ "$trigger" != "update" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if $trigger_reboot; then
|
||||
echo "CRITICAL send message to reboot the PSA"
|
||||
send_reboot_message_to_system_controller
|
||||
continue
|
||||
fi
|
||||
|
||||
# Is APISM running, listening on the correct ports etc. ?
|
||||
@ -136,9 +144,11 @@ UpdateController() {
|
||||
check_apism_count=$((check_apism_count+1))
|
||||
if [[ "$check_apism_count" -eq 5 ]]; then
|
||||
trigger_reboot=true
|
||||
check_apism_count=0
|
||||
echo "ERROR APISM not working"
|
||||
continue 2
|
||||
fi
|
||||
echo "[$check_apism_count]: $(date +'%Y-%m-%d %T') check APISM"
|
||||
sleep 60s
|
||||
else
|
||||
# APISM up and working
|
||||
@ -147,6 +157,9 @@ UpdateController() {
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$(date +'%Y-%m-%d %T') checking for updates..."
|
||||
exit 1
|
||||
|
||||
# Are there new updates available ?
|
||||
if ! check_for_updates; then
|
||||
echo "DEBUG no updates available"
|
||||
@ -256,7 +269,15 @@ UpdateController() {
|
||||
|
||||
###############################################################################
|
||||
|
||||
# start the UpdateController
|
||||
# UpdateController
|
||||
if [ $# -ne 1 ] ; then
|
||||
echo "Usage: $0 filename"
|
||||
exit 1
|
||||
else
|
||||
if read_config "$1" ; then
|
||||
init_fifo
|
||||
UpdateController
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user