title: Trying to discover what is invoking a daily Ruby job
body: <p>This'll probably be one of those face-palm experiences for me, but humility is a virtue and I'm running out of leads...  The summary of this post is that I need to discover what might be invoking a daily ruby run outside of our core website.</p>
  
  <p>We're running on Ubuntu 10.04 LTS with Ruby 1.9.3-p484/Rails 3.2.17 on Apache/Passenger with MySQL on the backend.  We use resque, god, and passenger as part of our stack.  I've been programming in Ruby for about 4-5 months from an inherited code base (so certainly am still learning), but have worked with Linux (off and on) for years.</p>
  
  <p>I have a class method of a model that seems to be invoked daily for updating our model contents (I can see it executing in the Ruby logs), but I can't tell what's invoking it.  It does not appear to be within the Apache/Passenger stack since it appears to be run under a process that appears only to execute the routine and then exit, suggesting a cron job.  I've grepped for Resque.enqueues, looked through the app/jobs directory, and reviewed the /etc/cron files.  I've even grepped the file system at a pretty high level for the name of method being called. The Gemfile doesn't suggest any other background processing facilities other than Resque.  </p>
  
  <p>I've put a "caller" line for logging that but it of course only shows the call stack within Ruby though it does corroborate that the process just exists for running the method (the PID doesn't show up with "ps aux" when I check later):</p>
  
  <pre><code>"(eval):1:in `&lt;top (required)&gt;'",
  "/var/www/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.17/lib/rails/commands/runner.rb:54:in `eval'",
  "/var/www/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.17/lib/rails/commands/runner.rb:54:in `&lt;top (required)&gt;'",
  "/var/www/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.17/lib/rails/commands.rb:64:in `require'",
  "/var/www/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.17/lib/rails/commands.rb:64:in `&lt;top (required)&gt;'",
  "./script/rails:6:in `require'", "./script/rails:6:in `&lt;main&gt;'"
  </code></pre>
  
  <p>My question is (1) is there some other scheduling facility that I should look at (perhaps a Ruby facility I'm not familiar with), or (2) is there a way for me to add a call from within Ruby (say, like I did with "caller") that would show what the invoking command is?</p>
  
  <p><strong>UPDATE (4/27/14)</strong>: 
  Based on the <code>Process.ppid</code> clue give by @BasileStarynkevitch (thank you!), I was able to find the command invoking the method I was searching using the following code</p>
  
  <pre><code>Rails.logger.warn "pid = &gt;#{Process.pid}&lt;, parent pid = &gt;#{Process.ppid}&lt;"
  _cmd = "cat /proc/#{Process.pid}/cmdline"
  Rails.logger.warn "current = &gt;#{`#{_cmd}`}&lt;" rescue nil
  _cmd = "cat /proc/#{Process.ppid}/cmdline"
  Rails.logger.warn "parent  = &gt;#{`#{_cmd}`}&lt;" rescue nil
  </code></pre>
  
  <p>The log reviewed that a Rails runner script was being started from a bash script:</p>
  
  <pre><code>Apr 27 13:12:22 svrprod rails[26730]: pid = &gt;26730&lt;, parent pid = &gt;26729&lt;
  Apr 27 13:12:22 svrprod rails[26730]: current = &gt;ruby./script/rails runner Model.method&lt;
  Apr 27 13:12:22 svrprod rails[26730]: parent  = &gt;/bin/sh -c(cd /var/www/myapp/current &amp;&amp; bash -l -c "RAILS_ENV=production ./script/rails runner 'Model.method'" &gt; /tmp/method_output 2&gt;&amp;1)&lt;
  </code></pre>
  
  <p>Unfortunately this takes me back to trying to run a grep to discover where this script is what is invoking it.  It does support the notion that cron is somehow triggering it but until I can find the script, I'm back to square one.   </p>
  
  <p><strong>UPDATE 2 (4/27/14)</strong>:
  Well, learn something new everyday.  It was a cron job, but I didn't now about <code>/var/spool/cron</code> (I was focused more on <code>/etc/cron</code>).  That was where the trigger for the <code>rails runner</code> job was from.  But I learned about <code>Process.ppid</code> and <code>rails runner</code> along with <code>/var/spool/cron</code>.  Thanks for all your help.</p>