(background.scan): only init values if they do not exist

This commit is contained in:
Christoph Stenglein 2023-08-16 18:36:53 +02:00 committed by rootzoll
parent accea759f6
commit 8119b33f3a
2 changed files with 58 additions and 51 deletions

View file

@ -56,7 +56,7 @@ configFile="/mnt/hdd/raspiblitz.conf"
# INFOFILE - persited state data
infoFile="/home/admin/raspiblitz.info"
# better readbale seconds (slightly off to reduce same time window trigger)
# better readable seconds (slightly off to reduce same time window trigger)
MINUTE=60
MINUTE2=115
MINUTE5=290
@ -78,17 +78,17 @@ usermod -G bitcoin root
####################################################################
# init values
/home/admin/_cache.sh set system_temp_celsius "0"
/home/admin/_cache.sh set system_temp_fahrenheit "0"
/home/admin/_cache.sh set system_count_longscan "0"
/home/admin/_cache.sh set system_count_undervoltage "0"
/home/admin/_cache.sh set system_count_start_blockchain "0"
/home/admin/_cache.sh set system_count_start_lightning "0"
/home/admin/_cache.sh set system_count_start_tui "0"
/home/admin/_cache.sh set btc_default_peers "0"
/home/admin/_cache.sh set btc_default_sync_percentage "0"
/home/admin/_cache.sh set btc_default_address ""
/home/admin/_cache.sh set btc_default_port ""
/home/admin/_cache.sh set system_temp_celsius "0" NX
/home/admin/_cache.sh set system_temp_fahrenheit "0" NX
/home/admin/_cache.sh set system_count_longscan "0" NX
/home/admin/_cache.sh set system_count_undervoltage "0" NX
/home/admin/_cache.sh set system_count_start_blockchain "0" NX
/home/admin/_cache.sh set system_count_start_lightning "0" NX
/home/admin/_cache.sh set system_count_start_tui "0" NX
/home/admin/_cache.sh set btc_default_peers "0" NX
/home/admin/_cache.sh set btc_default_sync_percentage "0" NX
/home/admin/_cache.sh set btc_default_address "" NX
/home/admin/_cache.sh set btc_default_port "" NX
# import all base values from raspiblitz.info
echo "importing: ${infoFile}"

View file

@ -5,7 +5,7 @@
# 2) KEY-VALUE STORE for system state infos (REDIS)
# SECURITY NOTE: The files on the RAMDISK can be set with unix file permissions and so restrict certain users access.
# But all data stored in the KEY-VALUE STORE has to be asumed as system-wide public information.
# But all data stored in the KEY-VALUE STORE has to be assumed as system-wide public information.
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; then
@ -55,7 +55,7 @@ META_OUTDATED_SECONDS=":out"
META_LASTTOUCH_TS=":ts"
META_VALID_FLAG=":val"
# path of the raspiblitz.info file (persiting cache values)
# path of the raspiblitz.info file (persisting cache values)
infoFile="/home/admin/raspiblitz.info"
###################
@ -138,29 +138,36 @@ elif [ "$1" = "set" ]; then
# get parameters
keystr=$2
valuestr=$3
expire=$4
expireOrNx=$4
# check that key & value are given
# check that key & value are provided
if [ "${keystr}" == "" ]; then
echo "# Fail: missing parameter"
exit 1
fi
# filter from expire just numbers
expire="${expire//[^0-9.]/}"
# add an expire flag if given
NX=""
if [ "${expireOrNx}" == "NX" ]; then
NX="NX"
else
# filter from expire just numbers
expireOrNx="${expire//[^0-9.]/}"
additionalParams=""
if [ "${expire}" != "" ]; then
# add an expire flag if given
if [ "${expireOrNx}" != "" ]; then
additionalParams="EX ${expire}"
fi
fi
# set in redis key value cache
redis-cli set ${keystr} "${valuestr}" ${additionalParams} 1>/dev/null
redis-cli set ${NX} ${keystr} "${valuestr}" ${additionalParams} 1>/dev/null
# set in redis the timestamp
timestamp=$(date +%s)
redis-cli set ${keystr}${META_LASTTOUCH_TS} "${timestamp}" ${additionalParams} 1>/dev/null
redis-cli set ${NX} ${keystr}${META_LASTTOUCH_TS} "${timestamp}" ${additionalParams} 1>/dev/null
#echo "# lasttouch(${timestamp})"
# check if the value has a outdate policy
@ -170,7 +177,7 @@ elif [ "$1" = "set" ]; then
fi
#echo "# outdatesecs(${outdatesecs})"
if [ "${outdatesecs}" != "-1" ]; then
# set exipire valid flag (if its gone - value is considered as outdated)
# set expire valid flag (if its gone - value is considered as outdated)
redis-cli set ${keystr}${META_VALID_FLAG} "1" EX ${outdatesecs} 1>/dev/null
fi
@ -243,7 +250,7 @@ elif [ "$1" = "export" ]; then
# get parameter
keyfilter="${2}*"
# go thru all keys by keyfilter
# go through all keys by keyfilter
keylist=$(redis-cli KEYS "${keyfilter}")
readarray -t arr <<< "${keylist}"
for key in "${arr[@]}";do
@ -266,7 +273,7 @@ elif [ "$1" = "export" ]; then
##################################
# COUNT
# count value up
# increment value
##################################
# set
@ -324,7 +331,7 @@ elif [ "$1" = "focus" ]; then
exit
fi
# sanatize parameters (if not -1)
# sanitize parameters (if not -1)
outdatesecs="${outdatesecs//[^0-9.]/}"
# check that key & value are given
@ -333,7 +340,7 @@ elif [ "$1" = "focus" ]; then
exit 1
fi
# add an expire flag if given
# add an expire flag if given
additionalParams=""
if [ "${durationsecs//[^0-9.]/}" != "" ]; then
additionalParams="EX ${durationsecs//[^0-9.]/}"
@ -358,7 +365,7 @@ elif [ "$1" = "meta" ]; then
keystr=$2
default=$3
# check that key & value are given
# check that key & value are provided
if [ "${keystr}" == "" ]; then
echo "# Fail: missing parameter"
exit 1