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