Compare commits

..

No commits in common. "cf118ee75d179967b1d3bd4ed6ae532883522c59" and "c4cd7c80cd094dd05a1619e551ef2138a086d088" have entirely different histories.

2 changed files with 31 additions and 67 deletions

41
SendUpdateCommand.sh Executable file → Normal file
View File

@ -1,32 +1,17 @@
#!/bin/bash #!/bin/bash
fifo="" pipe=/tmp/testpipe
read_config() { if [[ ! -p $pipe ]]; then
fifo_dir=$(cat "$1" | jq -r .fifo_dir) echo "Reader not running"
if [ -z "$fifo_dir" ]; then exit 1
return 1 fi
fi
fifo=$(cat "$1" | jq -r .fifo) if [[ "$1" ]]; then
if [ -z "$fifo" ]; then echo "$1" >$pipe
return 1 else
fi echo "Hello from $$" >$pipe
fifo="${fifo_dir}/$fifo"
return 0
}
if [ $# -ne 1 ] ; then
echo "Usage: $0 filename"
exit 1
else
if read_config "$1" ; then
if [[ ! -p $fifo ]]; then
echo "Reader not running on $fifo"
exit 1
fi
echo "update" >$fifo
exit 0
fi
fi fi

View File

@ -1,19 +1,17 @@
#!/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
@ -22,36 +20,32 @@ init_fifo () {
} }
read_config() { read_config() {
fifo_dir=$(cat "$1" | jq -r .fifo_dir) fifo_dir=$(cat ${1} | jq -r .fifo_dir)
if [ -z "$fifo_dir" ]; then fifo="${fifo_dir}/$(cat ${1} | jq -r .fifo)"
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
} }
check_for_apism() { check_for_apism() {
return 0 return 0
} }
check_for_updates() { check_for_updates() {
@ -122,18 +116,16 @@ UpdateController() {
# from some external source to perform an update. # from some external source to perform an update.
while : while :
do do
trigger=$(wait_for_trigger $trigger_timeout) request=$(wait_for_trigger $trigger_timeout)
echo "trigger=$trigger" if [ ${request} = "quit" ]; then
if [ "$trigger" = "quit" ]; then
$trigger_reboot = true $trigger_reboot = true
elif [ "$trigger" != "update" ]; then elif [ ${request} != "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. ?
@ -144,11 +136,9 @@ 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
@ -156,9 +146,6 @@ UpdateController() {
break break
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
@ -269,15 +256,7 @@ UpdateController() {
############################################################################### ###############################################################################
if [ $# -ne 1 ] ; then # start the UpdateController
echo "Usage: $0 filename" # UpdateController
exit 1
else
if read_config "$1" ; then
init_fifo
UpdateController
fi
fi