title: How to stop God from leaving stale Resque worker processes?
body: <p>I'm trying to understand how to monitor the resque worker for <a href="https://github.com/travis-ci/travis-ci">travis-ci</a> with god in such a way that stopping the resque watch via god won't leave a stale worker process.</p>
  
  <p>In the following I'm talking about the worker process, not forked job child processes (i.e. the queue is empty all the time).</p>
  
  <p>When I manually start the resque worker like this:</p>
  
  <pre><code>$ QUEUE=builds rake resque:work
  </code></pre>
  
  <p>I'll get a single process:</p>
  
  <pre><code>$ ps x | grep resque
   7041 s001  S+     0:05.04 resque-1.13.0: Waiting for builds
  </code></pre>
  
  <p>And this process will go away as soon as I stop the worker task.</p>
  
  <p>But when I start the same thing with god (<a href="https://github.com/travis-ci/travis-ci/blob/master/config/resque.god.example">exact configuration is here</a>, basically the same thing as the <a href="https://github.com/defunkt/resque/blob/master/examples/god/resque.god">resque/god example</a>) like this ...</p>
  
  <pre><code>$ RAILS_ENV=development god -c config/resque.god -D
  I [2011-03-27 22:49:15]  INFO: Loading config/resque.god
  I [2011-03-27 22:49:15]  INFO: Syslog enabled.
  I [2011-03-27 22:49:15]  INFO: Using pid file directory: /Volumes/Users/sven/.god/pids
  I [2011-03-27 22:49:15]  INFO: Started on drbunix:///tmp/god.17165.sock
  I [2011-03-27 22:49:15]  INFO: resque-0 move 'unmonitored' to 'init'
  I [2011-03-27 22:49:15]  INFO: resque-0 moved 'unmonitored' to 'init'
  I [2011-03-27 22:49:15]  INFO: resque-0 [trigger] process is not running (ProcessRunning)
  I [2011-03-27 22:49:15]  INFO: resque-0 move 'init' to 'start'
  I [2011-03-27 22:49:15]  INFO: resque-0 start: cd /Volumes/Users/sven/Development/projects/travis &amp;&amp; rake resque:work
  I [2011-03-27 22:49:15]  INFO: resque-0 moved 'init' to 'start'
  I [2011-03-27 22:49:15]  INFO: resque-0 [trigger] process is running (ProcessRunning)
  I [2011-03-27 22:49:15]  INFO: resque-0 move 'start' to 'up'
  I [2011-03-27 22:49:15]  INFO: resque-0 moved 'start' to 'up'
  I [2011-03-27 22:49:15]  INFO: resque-0 [ok] memory within bounds [784kb] (MemoryUsage)
  I [2011-03-27 22:49:15]  INFO: resque-0 [ok] process is running (ProcessRunning)
  I [2011-03-27 22:49:45]  INFO: resque-0 [ok] memory within bounds [784kb, 784kb] (MemoryUsage)
  I [2011-03-27 22:49:45]  INFO: resque-0 [ok] process is running (ProcessRunning)
  </code></pre>
  
  <p>Then I'll get an extra process:</p>
  
  <pre><code>$ ps x | grep resque
   7187   ??  Ss     0:00.02 sh -c cd /Volumes/Users/sven/Development/projects/travis &amp;&amp; rake resque:work
   7188   ??  S      0:05.11 resque-1.13.0: Waiting for builds
   7183 s001  S+     0:01.18 /Volumes/Users/sven/.rvm/rubies/ruby-1.8.7-p302/bin/ruby /Volumes/Users/sven/.rvm/gems/ruby-1.8.7-p302/bin/god -c config/resque.god -D
  </code></pre>
  
  <p>God only seems to log the pid of the first one:</p>
  
  <pre><code>$ cat ~/.god/pids/resque-0.pid
  7187
  </code></pre>
  
  <p>When I then stop the resque watch via god:</p>
  
  <pre><code>$ god stop resque
  Sending 'stop' command
  
  The following watches were affected:
    resque-0
  </code></pre>
  
  <p>God gives this log output:</p>
  
  <pre><code>I [2011-03-27 22:51:22]  INFO: resque-0 stop: default lambda killer
  I [2011-03-27 22:51:22]  INFO: resque-0 sent SIGTERM
  I [2011-03-27 22:51:23]  INFO: resque-0 process stopped
  I [2011-03-27 22:51:23]  INFO: resque-0 move 'up' to 'unmonitored'
  I [2011-03-27 22:51:23]  INFO: resque-0 moved 'up' to 'unmonitored'
  </code></pre>
  
  <p>But it does not actually terminate both of the processes, leaving the actual worker process alive:</p>
  
  <pre><code>$ ps x | grep resque
   6864   ??  S      0:05.15 resque-1.13.0: Waiting for builds
   6858 s001  S+     0:01.36 /Volumes/Users/sven/.rvm/rubies/ruby-1.8.7-p302/bin/ruby /Volumes/Users/sven/.rvm/gems/ruby-1.8.7-p302/bin/god -c config/resque.god -D
  </code></pre>