From 37294bd8f7e45bd8f50f92f779a43d9e54416f3d Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sat, 2 Jun 2018 19:18:56 +0100 Subject: [PATCH] Be more aggressive about killing an unresponsive service --- on-ping-service-failure.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/on-ping-service-failure.sh b/on-ping-service-failure.sh index ede5736..7daea36 100755 --- a/on-ping-service-failure.sh +++ b/on-ping-service-failure.sh @@ -5,7 +5,8 @@ # # Request a dump of running threads: -touch $HOME/racket-pkg-website/signals/.dumpinfo +dumprequestfile=$HOME/racket-pkg-website/signals/.dumpinfo +touch $dumprequestfile # Wait a few seconds for the dump to complete: sleep 10 @@ -17,8 +18,20 @@ logarchive=$HOME/ping-failure-logs-$(date +%Y%m%d%H%M%S).tar.gz ls -tr | tail -n 10 | xargs tar -zcf $logarchive \ ) -# Restart the service using daemontools: -svc -du $HOME/service/racket-pkg-website +# Restart the service using daemontools. +if [ -f $dumprequestfile ] +then + # If the `.dumpinfo` signal is still there after our sleep, then + # the process is so far off the rails we shouldn't bother waiting + # for it, so kill it hard. + echo "Killing service hard and restarting it." + svc -dku $HOME/service/racket-pkg-website +else + # Otherwise, it's at least partially awake, so try asking it + # nicely. + echo "Politely requesting service termination before restart." + svc -du $HOME/service/racket-pkg-website +fi # Finally, complain out loud. We expect to be running in some kind of # cron-ish context, so the output we produce here will likely find its