title: How to manage passenger stale workers that causes downtime
body: <p>I have a rails app running on <code>ubuntu 14.04</code> machine and it is served by <code>Nginx</code> and <code>passenger</code>. There are times when the app goes down giving the following error</p>
  
  <pre><code>[ agents/LoggingAgent/Main.cpp:338 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) to force shutdown)
  [ agents/LoggingAgent/Main.cpp:400 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected...
  [ ServerKit/Server.h:453 ]: [LoggerAdminServer] Shutdown finished
  [ agents/LoggingAgent/Main.cpp:425 ]: PassengerAgent logger shutdown finished
  [ ServerKit/Server.h:453 ]: [ServerThr.1] Shutdown finished
  [ ServerKit/Server.h:453 ]: [ServerThr.2] Shutdown finished
  [ ServerKit/Server.h:453 ]: [AdminServer] Shutdown finished
  [ agents/HelperAgent/Main.cpp:724 ]: Disconnecting long-running connections for process 19431, application /public#default
  [ agents/HelperAgent/Main.cpp:724 ]: Disconnecting long-running connections for process 19440, application /public#default
  [ agents/Watchdog/Main.cpp:1255 ]: Starting PassengerAgent watchdog...
  [ agents/HelperAgent/Main.cpp:883 ]: Starting PassengerAgent server...
  [ agents/HelperAgent/Main.cpp:232 ]: PassengerAgent server running in multi-application mode.
  [ agents/HelperAgent/Main.cpp:637 ]: PassengerAgent server online, PID 19637
  [ agents/LoggingAgent/Main.cpp:431 ]: Starting PassengerAgent logger...
  [ agents/LoggingAgent/Main.cpp:312 ]: PassengerAgent logger online, PID 19645
  [ agents/HelperAgent/Main.cpp:868 ]: PassengerAgent server shutdown finished
  </code></pre>
  
  <p>And the app remains down unless the <code>Nginx</code> is being restarted. This is probably due to the stale workers which are not serving anymore and eating up the memory (correct me if I am wrong).</p>
  
  <p>I have set the <code>max pool size</code> of passenger to <code>6</code> as my app instance takes <code>150-200 Mb</code> of memory with a <code>2GB RAM</code>.</p>
  
  <p>I was thinking to write a script which regularly check for the stale workers and if found restart the <code>Nginx</code> or do a <code>touch tmp/restart.txt</code>. I also want to know how to check for the stale workers or if the <code>passenger</code> is not working as expected.</p>
  
  <p>Another solution I thought is to regularly restart <code>Nginx</code> or do a <code>touch tmp/restart.txt</code> after a regular interval of time, say one hour.</p>
  
  <p>I have also read the passenger documentation about the three ways of restarting the app</p>
  
  <ul>
  <li><p>passenger-config restart-app </p></li>
  <li><p>restart.txt </p></li>
  <li><p>Restarting Nginx</p></li>
  </ul>
  
  <p>The first two cases won't drop any request while restarting the app but may have zero down time while restarting the app as the restarting of app may take some time depending on the app.</p>
  
  <p>I want to know which would be a good way or is there any other way to get rid of this problem.</p>