Browse Source

modify healthcheck to lower filesystem load

Vadim Surkov 5 years ago
parent
commit
4f5f79b53d
2 changed files with 12 additions and 5 deletions
  1. 1 0
      entrypoint.sh
  2. 11 5
      healthcheck.sh

+ 1 - 0
entrypoint.sh

@@ -5,6 +5,7 @@ then
     ln -s ${LOGPATH} /opt/analis/log 
 fi
 echo "Starting AnalisServer.exe $@"
+echo "This file used to shedule healthchecks" > /opt/analis/checkfile.status
 touch /opt/analis/log/fatal.log
 ln -s /opt/analis/log/fatal.log /opt/analis/fatal.log
 tail -n0 -f /opt/analis/log/fatal.log | while read fread; do echo "[fatal.log]: ${fread}"; done &

+ 11 - 5
healthcheck.sh

@@ -1,14 +1,20 @@
 #!/bin/bash
 
+# Log check schedule
+LOGSCHEDULE=${LOGSCHEDULE:-1800}
 # Log difference in seconds
 _LOGDIFF=600
 # Log path
 _LOGDIR="/opt/analis/log"
 # Discover latest modified file
-_LOGFILE=$( ls -t -d -1 ${_LOGDIR}/Analis* | head -1 )
+_LOGFILE=${_LOGDIR}AnalisatorService_$(date +%d-%m-%Y)
 
-#Check difference between system time and latest modified file in logdir - if it's greater then $_LOGDIFF, then container is not healty
-if [[  $[ $(date +%s) - $(stat -c %Y "${_LOGFILE}") ] -gt ${_LOGDIFF} ]]; then
-   echo -e $(date)" The difference between system time and latest modified file in logdir is "$[ $(date +%s) - $(stat -c %Y ${_LOGFILE}) ]" The service seems to be unhealty.\n\r" >> ${_LOGDIR}/healthcheck.log
-   exit 1
+#Check is it time to run _LOGFILE check
+if [[  $[ $(date +%s) - $(stat -c %Y "/opt/analis/checkfile.status") ] -gt ${LOGSCHEDULE} ]]; then 
+    touch /opt/analis/checkfile.status
+    #Check difference between system time and latest modified file in logdir - if it's greater then $_LOGDIFF, then container is not healty
+    if [[  $[ $(date +%s) - $(stat -c %Y "${_LOGFILE}") ] -gt ${_LOGDIFF} ]]; then
+        echo -e $(date)" The difference between system time and latest modified file in logdir is "$[ $(date +%s) - $(stat -c %Y ${_LOGFILE}) ]" The service seems to be unhealty.\n\r" >> ${_LOGDIR}/healthcheck.log
+        exit 1
+    fi
 fi