This commit is contained in:
2023-11-14 14:41:31 -06:00
parent aabc7cb351
commit 9c4977573c
3 changed files with 26 additions and 24 deletions

View File

@@ -1,18 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
VERS='4.13.36-11142023' VERS='4.14.4-11142023'
noheader=' service status-check nightlyrephp7.3-fpm,new backup report check checkcerts gitea update-nodes copynpmcerts singleservercheck update-dyndns backup-offsitepfsense gui nightlyreview update ' noheader=' service status-check nightlyrephp7.3-fpm,new backup report check checkcerts gitea update-nodes copynpmcerts singleservercheck update-dyndns backup-offsitepfsense gui nightlyreview update '
CERT_DAEMON='/snap/bin/certbot' CERT_DAEMON='/snap/bin/certbot'
NM_FOLDER=/opt/idssys/nodemgmt
NM_SCRIPT=${NM_FOLDER}/nodemgmt-scripts.sh
NM_TMPFOLDER=${NM_FOLDER}/.tmp
NM_LOGFOLDER=${NM_FOLDER}/logs
NM_LOGFILE=${NM_LOGFOLDER}/logfile
RENOTIFY_TIMEOUT=3600
[ ! -d ${NM_TMPFOLDER} ] && mkdir ${NM_TMPFOLDER}
[ ! -d ${NM_LOGFOLDER} ] && mkdir ${NM_LOGFOLDER}
declare -i errtime declare -i errtime
@@ -39,6 +29,18 @@ if [ -f ${NM_FOLDER}/conf/defaults.local.inc ]; then
source ${NM_FOLDER}/conf/defaults.local.inc source ${NM_FOLDER}/conf/defaults.local.inc
[ "${NM_FOLDER}" == "" ] && NM_FOLDER=/opt/idssys/nodemgmt
[ "${NM_BACKUP_FOLDER}" == "" ] && NM_BACKUP_FOLDER=/opt/idssys/backups/node-backup
NM_SCRIPT=${NM_FOLDER}/nodemgmt-scripts.sh
NM_TMPFOLDER=${NM_FOLDER}/.tmp
[ "${NM_LOGFOLDER}" == "" ] && NM_LOGFOLDER=${NM_FOLDER}/logs
NM_LOGFILE=${NM_LOGFOLDER}/logfile
[ ! -d ${NM_TMPFOLDER} ] && mkdir ${NM_TMPFOLDER}
[ ! -d ${NM_LOGFOLDER} ] && mkdir ${NM_LOGFOLDER}
[ "${NM_RENOTIFY_TIMEOUT}" == "" ] && NM_RENOTIFY_TIMEOUT=3600
IFS=, IFS=,
LOCAL_SERVICES=(${LOCAL_SERVICES}) LOCAL_SERVICES=(${LOCAL_SERVICES})
unset IFS unset IFS

View File

@@ -80,7 +80,7 @@ STATUS(){
echo "$(date) - LOCAL - ${NODE_HOSTNAME} - ${NM_SERVICE_DESC[${srvc}]} is down" >> ${NM_LOGFILE} echo "$(date) - LOCAL - ${NODE_HOSTNAME} - ${NM_SERVICE_DESC[${srvc}]} is down" >> ${NM_LOGFILE}
else else
errtime=`date +%s`-$(stat -c %Y ${NM_TMPFOLDER}/${NODE_HOSTNAME}~${srvc}.down) errtime=`date +%s`-$(stat -c %Y ${NM_TMPFOLDER}/${NODE_HOSTNAME}~${srvc}.down)
if [ $errtime -gt ${RENOTIFY_TIMEOUT} ]; then if [ $errtime -gt ${NM_RENOTIFY_TIMEOUT} ]; then
if [ ! -f ${NM_TMPFOLDER}/${NODE_HOSTNAME}~${srvc}.errtime ]; then if [ ! -f ${NM_TMPFOLDER}/${NODE_HOSTNAME}~${srvc}.errtime ]; then
mv ${NM_TMPFOLDER}/${NODE_HOSTNAME}~${srvc}.down ${NM_TMPFOLDER}/${NODE_HOSTNAME}~${srvc}.errtime mv ${NM_TMPFOLDER}/${NODE_HOSTNAME}~${srvc}.down ${NM_TMPFOLDER}/${NODE_HOSTNAME}~${srvc}.errtime
fi fi
@@ -226,7 +226,7 @@ STATUS(){
elif [ ! -f ${NM_TMPFOLDER}/${nip}~${srvc}.disable ]; then elif [ ! -f ${NM_TMPFOLDER}/${nip}~${srvc}.disable ]; then
errtime=`date +%s`-$(stat -c %Y ${NM_TMPFOLDER}/${nip}~${srvc}.down) errtime=`date +%s`-$(stat -c %Y ${NM_TMPFOLDER}/${nip}~${srvc}.down)
if [ $errtime -gt ${RENOTIFY_TIMEOUT} ]; then if [ $errtime -gt ${NM_RENOTIFY_TIMEOUT} ]; then
[ ! -f ${NM_TMPFOLDER}/${nip}~${srvc}.errtime ] && mv ${NM_TMPFOLDER}/${nip}~${srvc}.down ${NM_TMPFOLDER}/${nip}~${srvc}.errtime [ ! -f ${NM_TMPFOLDER}/${nip}~${srvc}.errtime ] && mv ${NM_TMPFOLDER}/${nip}~${srvc}.down ${NM_TMPFOLDER}/${nip}~${srvc}.errtime
toterrtime=`date +%s`-$(stat -c %Y ${NM_TMPFOLDER}/${nip}~${srvc}.errtime) toterrtime=`date +%s`-$(stat -c %Y ${NM_TMPFOLDER}/${nip}~${srvc}.errtime)
touch ${NM_TMPFOLDER}/${nip}~${srvc}.down touch ${NM_TMPFOLDER}/${nip}~${srvc}.down
@@ -299,7 +299,7 @@ STATUS(){
# #
# else # else
# errtime=`date +%s`-$(stat -c %Y ${NM_TMPFOLDER}/${nip}~${srvc}.down) # errtime=`date +%s`-$(stat -c %Y ${NM_TMPFOLDER}/${nip}~${srvc}.down)
# if [ $errtime -gt ${RENOTIFY_TIMEOUT} ]; then # if [ $errtime -gt ${NM_RENOTIFY_TIMEOUT} ]; then
# if [ ! -f ${NM_TMPFOLDER}/${nip}~${srvc}.errtime ]; then # if [ ! -f ${NM_TMPFOLDER}/${nip}~${srvc}.errtime ]; then
# mv ${NM_TMPFOLDER}/${nip}~${srvc}.down ${NM_TMPFOLDER}/${nip}~${srvc}.errtime # mv ${NM_TMPFOLDER}/${nip}~${srvc}.down ${NM_TMPFOLDER}/${nip}~${srvc}.errtime
# fi # fi
@@ -395,7 +395,7 @@ STATUS(){
echo "$(date) - ${nip} - ${NM_HOSTNAMES[${nip}]}[${nip}] - ${NM_DOCKER_DESC[${docker}]} (docker) is down, could not fix" >> ${NM_LOGFILE} echo "$(date) - ${nip} - ${NM_HOSTNAMES[${nip}]}[${nip}] - ${NM_DOCKER_DESC[${docker}]} (docker) is down, could not fix" >> ${NM_LOGFILE}
else else
errtime=`date +%s`-$(stat -c %Y ${NM_TMPFOLDER}/${nip}~${docker}.down) errtime=`date +%s`-$(stat -c %Y ${NM_TMPFOLDER}/${nip}~${docker}.down)
if [ $errtime -gt ${RENOTIFY_TIMEOUT} ]; then if [ $errtime -gt ${NM_RENOTIFY_TIMEOUT} ]; then
if [ ! -f ${NM_TMPFOLDER}/${nip}~${docker}.errtime ]; then if [ ! -f ${NM_TMPFOLDER}/${nip}~${docker}.errtime ]; then
mv ${NM_TMPFOLDER}/${nip}~${docker}.down ${NM_TMPFOLDER}/${nip}~${docker}.errtime mv ${NM_TMPFOLDER}/${nip}~${docker}.down ${NM_TMPFOLDER}/${nip}~${docker}.errtime
fi fi
@@ -438,13 +438,13 @@ STATUS(){
if [ "${ST_ACTION}" != "check" ]; then if [ "${ST_ACTION}" != "check" ]; then
echo -e "${idsCL[Red]} - Node has been down for $(SHOW_TIME ${toterrtime}) ${idsCL[LightYello]}${LH}${idsCL[Default]}" echo -e "${idsCL[Red]} - Node has been down for $(SHOW_TIME ${toterrtime}) ${idsCL[LightYello]}${LH}${idsCL[Default]}"
fi fi
if [ $errtime -gt ${RENOTIFY_TIMEOUT} ]; then if [ $errtime -gt ${NM_RENOTIFY_TIMEOUT} ]; then
SENDNOTICE "${NM_HOSTNAMES[${nip}]}[${nip}]" "${NM_HOSTNAMES[${nip}]}[${nip}] has been down for $(SHOW_TIME ${toterrtime})" 1 SENDNOTICE "${NM_HOSTNAMES[${nip}]}[${nip}]" "${NM_HOSTNAMES[${nip}]}[${nip}] has been down for $(SHOW_TIME ${toterrtime})" 1
elif [ $errtime -gt 60 ] && [ $errtime -lt 180 ] && [ ! -f ${NM_TMPFOLDER}/${nip}.errtime ]; then elif [ $errtime -gt 60 ] && [ $errtime -lt 180 ] && [ ! -f ${NM_TMPFOLDER}/${nip}.errtime ]; then
SENDNOTICE "${NM_HOSTNAMES[${nip}]}[${nip}]" "${NM_HOSTNAMES[${nip}]}[${nip}] is down" 1 SENDNOTICE "${NM_HOSTNAMES[${nip}]}[${nip}]" "${NM_HOSTNAMES[${nip}]}[${nip}] is down" 1
fi fi
touch ${NM_TMPFOLDER}/${nip}.down touch ${NM_TMPFOLDER}/${nip}.down
# if [ $errtime -gt ${RENOTIFY_TIMEOUT} ] && [ "${EMAIL_NOTICE}" != "" ]; then # if [ $errtime -gt ${NM_RENOTIFY_TIMEOUT} ] && [ "${EMAIL_NOTICE}" != "" ]; then
# echo "${NM_HOSTNAMES[${nip}]}[${nip}] has been down for $(SHOW_TIME ${toterrtime})" | mail -s "${NM_HOSTNAMES[${nip}]}[${nip}]" ${EMAIL_NOTICE} # echo "${NM_HOSTNAMES[${nip}]}[${nip}] has been down for $(SHOW_TIME ${toterrtime})" | mail -s "${NM_HOSTNAMES[${nip}]}[${nip}]" ${EMAIL_NOTICE}
# fi # fi
fi fi
@@ -536,7 +536,7 @@ STATUS(){
else else
snderrtime=`expr $(date +%s) - $(stat -c %Y ${NM_TMPFOLDER}/${nip}~${rcheck}.repl.down)` snderrtime=`expr $(date +%s) - $(stat -c %Y ${NM_TMPFOLDER}/${nip}~${rcheck}.repl.down)`
# echo "HERE: $snderrtime" # echo "HERE: $snderrtime"
if [ ${snderrtime} -gt ${RENOTIFY_TIMEOUT} ]; then if [ ${snderrtime} -gt ${NM_RENOTIFY_TIMEOUT} ]; then
toterrtime=`expr $(date +%s) - $(stat -c %Y ${NM_TMPFOLDER}/${nip}~${rcheck}.repl.errtime)` toterrtime=`expr $(date +%s) - $(stat -c %Y ${NM_TMPFOLDER}/${nip}~${rcheck}.repl.errtime)`
SENDNOTICE "Repl-Timeout-'${NM_HOSTNAMES[${nip}]}[${nip}]'" "${NM_REPL_DESC[${rcheck}]} (${NM_REPL_CHECK_LOC[${rcheck}]}) SENDNOTICE "Repl-Timeout-'${NM_HOSTNAMES[${nip}]}[${nip}]'" "${NM_REPL_DESC[${rcheck}]} (${NM_REPL_CHECK_LOC[${rcheck}]})
It has been down for $(SHOW_TIME ${toterrtime})" 1 It has been down for $(SHOW_TIME ${toterrtime})" 1

View File

@@ -23,13 +23,13 @@ fi
BACKUP(){ BACKUP(){
BACKUP_FOLDER=/opt/idssys/backups/node-backup/$(date +%m-%d-%y)/$(date +%H-%M-%S) backupfolder=/opt/idssys/backups/node-backup/$(date +%m-%d-%y)/$(date +%H-%M-%S)
#BACKUP_FOLDER=/opt/idssys/backups/node-backups/${NODE_HOSTNAME} #/`date +%Y-%m-%d` #BACKUP_FOLDER=/opt/idssys/backups/node-backups/${NODE_HOSTNAME} #/`date +%Y-%m-%d`
#BACKUP_TIMEFOLDER=${BACKUP_DAYFOLDER}/`date +%H-%M` #BACKUP_TIMEFOLDER=${BACKUP_DAYFOLDER}/`date +%H-%M`
# if [ "${action}" != "backup" ]; then echo
echo -e "${idsCL[Green]}Backing up Node Settings and Files...${idsCL[Default]}" echo -e "${idsCL[Yellow]}Backup Path: ${idsCL[Yellow]}${BACKUP_FOLDER}${idsCL[Default]}\n\n"
DIVIDER true echo -e "${idsCL[Green]}Backing up Node Settings and Files...${idsCL[Default]}"
# fi DIVIDER true
[ ! -d ${BACKUP_FOLDER} ] && mkdir -p ${BACKUP_FOLDER} [ ! -d ${BACKUP_FOLDER} ] && mkdir -p ${BACKUP_FOLDER}
for item in "${!NM_BACKUP_ITEMS[@]}"; do for item in "${!NM_BACKUP_ITEMS[@]}"; do
c=0; spc=''; spc1=`expr 20 - ${#item}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done c=0; spc=''; spc1=`expr 20 - ${#item}`; until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
@@ -44,7 +44,7 @@ BACKUP(){
touch ${NM_LOGFOLDER}/backup.lastrun touch ${NM_LOGFOLDER}/backup.lastrun
echo echo
DIVIDER true DIVIDER true
echo -e "${idsCL[Green]}Backups were successfully created in: ${idsCL[Yellow]}${BACKUP_FOLDER}${idsCL[Default]}" echo -e "${idsCL[Green]}Backups were successfully created in: ${idsCL[Yellow]}${BACKUP_FOLDER}${idsCL[Default]}\n\n"
if [ -z $action ] || [ "${action}" = "gui" ]; then if [ -z $action ] || [ "${action}" = "gui" ]; then
ENTER2CONTINUE ENTER2CONTINUE
fi fi