Mycroft Watchdog Script

From ETCwiki
Revision as of 17:44, 19 October 2021 by Ddxfish (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

If you run Mycroft in Docker, you may have seen a ton of errors when it tries to connect to the Messagebus. I get Errno 111 Connection Refused on Mycroft a ton. In my situation, all I needed to do was /opt/mycroft/./stop-mycroft.sh and then /opt/mycroft/./start-mycroft.sh all and things would start working again. If this is your case too, try this watchdog script inside your Mycroft container.

Add watchdog.sh to /opt/mycroft/startup.sh

#!/bin/bash
source /opt/mycroft/.venv/bin/activate
/opt/mycroft/./start-mycroft.sh all
/opt/mycroft/./watchdog.sh &
tail -f /var/log/mycroft/*.log


/opt/mycroft/watchdog.sh

#!/bin/bash‎
# If you run mycroft in docker you may get Errno 111: Connection Refused
# On my container, a simple ./mycroft-stop and ./mycroft-start all fixes Error 111
# This script checks your audio.log for Error 111 and will restart the mycroft service if it occurs
# put the script in your container, then edit /opt/mycroft/startup.sh 
# Add your background watchdog script after mycroft starts in startup.sh, like: /opt/mycroft/./watchdog.sh &
while true
do
        thetime=`date +%s`
        echo watchdogtest $thetime | tee -a /var/log/mycroft/audio.log
        sleep 20
        oneelevens=`cat /var/log/mycroft/audio.log | sed -n "/$thetime/,$p" | grep -c "Errno 111"`
        echo "Watchdog: checking now" | tee -a /var/log/mycroft/audio.log
        if $oneelevens -gt 0 ; then
                cd /opt/mycroft
                ./mycroft-stop
                sleep 10
                ./mycroft-start all
                echo "Watchdog: mycroft restart attempt finished $oneelevens" | tee -a /var/log/mycroft/audio.log
        else
                echo "Watchdog: mycroft was found without errors $oneelevens" | tee -a /var/log/mycroft/audio.log
        fi
        sleep 90
done

External Links