FIX: Increase timeout when trying to reload unicorn.

FIX: Increase timeout when trying to reload unicorn.

Also fail better when reloading takes too long by sending
unicorn a TERM.

From cfa0321aaa0690f0a7dbc0c0868afbc1ef1ca02b Mon Sep 17 00:00:00 2001
From: Guo Xiang Tan <tgx_world@hotmail.com>
Date: Tue, 4 Dec 2018 13:42:10 +0800
Subject: [PATCH] FIX: Increase timeout when trying to reload unicorn.

Also fail better when reloading takes too long by sending
unicorn a TERM.

diff --git a/config/unicorn_launcher b/config/unicorn_launcher
index 39604fd..a7251cf 100755
--- a/config/unicorn_launcher
+++ b/config/unicorn_launcher
@@ -25,24 +25,29 @@ function on_reload()
   unset NEW_UNICORN_PID
 
   count=0
-  while [ "$count" -lt 30 -a -z "$NEW_UNICORN_PID" ]; do
+  while [ "$count" -lt 180 -a -z "$NEW_UNICORN_PID" ]; do
     NEW_UNICORN_PID=`ps -f --ppid $UNICORN_PID | grep 'unicorn master' | grep -v old | grep -v worker | awk '{ print $2 }'`
     log "Waiting for new unicorn master pid... $NEW_UNICORN_PID"
     count=$((count+1))
     sleep 1
   done
 
-  count=0
-  while [ "$count" -lt 30 -a -z "$(ps -f --ppid $NEW_UNICORN_PID | grep worker | head -1 | awk '{ print $2 }')" ]; do
-    log "Waiting for new unicorn workers under $NEW_UNICORN_PID to start up..."
-    count=$((count+1))
-    sleep 1
-  done
+  if [ -n "$NEW_UNICORN_PID" ]; then
+    count=0
+    while [ "$count" -lt 180 -a -z "$(ps -f --ppid $NEW_UNICORN_PID | grep worker | head -1 | awk '{ print $2 }')" ]; do
+      log "Waiting for new unicorn workers under $NEW_UNICORN_PID to start up..."
+      count=$((count+1))
+      sleep 1
+    done
 
-  curl $LOCAL_WEB &> /dev/null
-  kill -s QUIT $UNICORN_PID
-  log "Old pid is: $UNICORN_PID New pid is: $NEW_UNICORN_PID"
-  UNICORN_PID=$NEW_UNICORN_PID
+    curl $LOCAL_WEB &> /dev/null
+    kill -s QUIT $UNICORN_PID
+    log "Old pid is: $UNICORN_PID New pid is: $NEW_UNICORN_PID"
+    UNICORN_PID=$NEW_UNICORN_PID
+  else
+    log "Unicorn is taking too long to reload...Sending TERM to $UNICORN_PID"
+    kill -s TERM $UNICORN_PID
+  fi
 }
 
 function on_reopenlogs()

GitHub

2 Likes