Browse Source

Add healthcheck

Vadim Surkov 5 years ago
parent
commit
286da7b15f
2 changed files with 16 additions and 0 deletions
  1. 2 0
      Dockerfile
  2. 14 0
      healthcheck.sh

+ 2 - 0
Dockerfile

@@ -2,5 +2,7 @@ FROM registry.sdsys.ru/report:1.1
 
 RUN mkdir -p /root/.wine/drive_c/services/analis
 COPY analis /root/.wine/drive_c/services/analis/
+COPY healthcheck.sh /opt/healthcheck.sh
+HEALTHCHECK --interval=2m --start-period=3m CMD /opt/healthcheck.sh
 
 ENTRYPOINT ["/usr/bin/xvfb-run","-a","wine","/root/.wine/drive_c/services/analis/AnalisServer.exe"]

+ 14 - 0
healthcheck.sh

@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# Log difference in seconds
+_LOGDIFF=600
+# Log path
+_LOGDIR="/root/.wine/drive_c/services/analis/log"
+# Discover latest modified file
+_LOGFILE=$( ls -t -d -1 ${_LOGDIR}/* | head -1 )
+
+#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 $(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." >> ${_LOGDIR}/healthcheck.log
+   exit 1
+fi