mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2025-03-01 00:59:23 +01:00
(background.scan): only init values if they do not exist
This commit is contained in:
parent
accea759f6
commit
8119b33f3a
2 changed files with 58 additions and 51 deletions
|
@ -56,7 +56,7 @@ configFile="/mnt/hdd/raspiblitz.conf"
|
||||||
# INFOFILE - persited state data
|
# INFOFILE - persited state data
|
||||||
infoFile="/home/admin/raspiblitz.info"
|
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
|
MINUTE=60
|
||||||
MINUTE2=115
|
MINUTE2=115
|
||||||
MINUTE5=290
|
MINUTE5=290
|
||||||
|
@ -78,17 +78,17 @@ usermod -G bitcoin root
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
||||||
# init values
|
# init values
|
||||||
/home/admin/_cache.sh set system_temp_celsius "0"
|
/home/admin/_cache.sh set system_temp_celsius "0" NX
|
||||||
/home/admin/_cache.sh set system_temp_fahrenheit "0"
|
/home/admin/_cache.sh set system_temp_fahrenheit "0" NX
|
||||||
/home/admin/_cache.sh set system_count_longscan "0"
|
/home/admin/_cache.sh set system_count_longscan "0" NX
|
||||||
/home/admin/_cache.sh set system_count_undervoltage "0"
|
/home/admin/_cache.sh set system_count_undervoltage "0" NX
|
||||||
/home/admin/_cache.sh set system_count_start_blockchain "0"
|
/home/admin/_cache.sh set system_count_start_blockchain "0" NX
|
||||||
/home/admin/_cache.sh set system_count_start_lightning "0"
|
/home/admin/_cache.sh set system_count_start_lightning "0" NX
|
||||||
/home/admin/_cache.sh set system_count_start_tui "0"
|
/home/admin/_cache.sh set system_count_start_tui "0" NX
|
||||||
/home/admin/_cache.sh set btc_default_peers "0"
|
/home/admin/_cache.sh set btc_default_peers "0" NX
|
||||||
/home/admin/_cache.sh set btc_default_sync_percentage "0"
|
/home/admin/_cache.sh set btc_default_sync_percentage "0" NX
|
||||||
/home/admin/_cache.sh set btc_default_address ""
|
/home/admin/_cache.sh set btc_default_address "" NX
|
||||||
/home/admin/_cache.sh set btc_default_port ""
|
/home/admin/_cache.sh set btc_default_port "" NX
|
||||||
|
|
||||||
# import all base values from raspiblitz.info
|
# import all base values from raspiblitz.info
|
||||||
echo "importing: ${infoFile}"
|
echo "importing: ${infoFile}"
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
# 2) KEY-VALUE STORE for system state infos (REDIS)
|
# 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.
|
# 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
|
# command info
|
||||||
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; then
|
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; then
|
||||||
|
@ -55,7 +55,7 @@ META_OUTDATED_SECONDS=":out"
|
||||||
META_LASTTOUCH_TS=":ts"
|
META_LASTTOUCH_TS=":ts"
|
||||||
META_VALID_FLAG=":val"
|
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"
|
infoFile="/home/admin/raspiblitz.info"
|
||||||
|
|
||||||
###################
|
###################
|
||||||
|
@ -138,29 +138,36 @@ elif [ "$1" = "set" ]; then
|
||||||
# get parameters
|
# get parameters
|
||||||
keystr=$2
|
keystr=$2
|
||||||
valuestr=$3
|
valuestr=$3
|
||||||
expire=$4
|
expireOrNx=$4
|
||||||
|
|
||||||
# check that key & value are given
|
# check that key & value are provided
|
||||||
if [ "${keystr}" == "" ]; then
|
if [ "${keystr}" == "" ]; then
|
||||||
echo "# Fail: missing parameter"
|
echo "# Fail: missing parameter"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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=""
|
additionalParams=""
|
||||||
if [ "${expire}" != "" ]; then
|
# add an expire flag if given
|
||||||
|
if [ "${expireOrNx}" != "" ]; then
|
||||||
additionalParams="EX ${expire}"
|
additionalParams="EX ${expire}"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# set in redis key value cache
|
# 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
|
# set in redis the timestamp
|
||||||
timestamp=$(date +%s)
|
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})"
|
#echo "# lasttouch(${timestamp})"
|
||||||
|
|
||||||
# check if the value has a outdate policy
|
# check if the value has a outdate policy
|
||||||
|
@ -170,7 +177,7 @@ elif [ "$1" = "set" ]; then
|
||||||
fi
|
fi
|
||||||
#echo "# outdatesecs(${outdatesecs})"
|
#echo "# outdatesecs(${outdatesecs})"
|
||||||
if [ "${outdatesecs}" != "-1" ]; then
|
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
|
redis-cli set ${keystr}${META_VALID_FLAG} "1" EX ${outdatesecs} 1>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -243,7 +250,7 @@ elif [ "$1" = "export" ]; then
|
||||||
# get parameter
|
# get parameter
|
||||||
keyfilter="${2}*"
|
keyfilter="${2}*"
|
||||||
|
|
||||||
# go thru all keys by keyfilter
|
# go through all keys by keyfilter
|
||||||
keylist=$(redis-cli KEYS "${keyfilter}")
|
keylist=$(redis-cli KEYS "${keyfilter}")
|
||||||
readarray -t arr <<< "${keylist}"
|
readarray -t arr <<< "${keylist}"
|
||||||
for key in "${arr[@]}";do
|
for key in "${arr[@]}";do
|
||||||
|
@ -266,7 +273,7 @@ elif [ "$1" = "export" ]; then
|
||||||
|
|
||||||
##################################
|
##################################
|
||||||
# COUNT
|
# COUNT
|
||||||
# count value up
|
# increment value
|
||||||
##################################
|
##################################
|
||||||
|
|
||||||
# set
|
# set
|
||||||
|
@ -324,7 +331,7 @@ elif [ "$1" = "focus" ]; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# sanatize parameters (if not -1)
|
# sanitize parameters (if not -1)
|
||||||
outdatesecs="${outdatesecs//[^0-9.]/}"
|
outdatesecs="${outdatesecs//[^0-9.]/}"
|
||||||
|
|
||||||
# check that key & value are given
|
# check that key & value are given
|
||||||
|
@ -358,7 +365,7 @@ elif [ "$1" = "meta" ]; then
|
||||||
keystr=$2
|
keystr=$2
|
||||||
default=$3
|
default=$3
|
||||||
|
|
||||||
# check that key & value are given
|
# check that key & value are provided
|
||||||
if [ "${keystr}" == "" ]; then
|
if [ "${keystr}" == "" ]; then
|
||||||
echo "# Fail: missing parameter"
|
echo "# Fail: missing parameter"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue