Monit & Rails sunspot_solr
<p>I've setup monit to monitor my sunspot_solr process, which seems to work at first.  If I restart the monit service with <code>sudo service monit restart</code> my sunspot process starts:</p>

<pre><code> ps aux | grep sunspot
</code></pre>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>root      4086  0.0  0.0   9940  1820 ?        Ss   12:41   0:00 bash ./solr start -f -s /ebs/staging/shared/bundle/ruby/2.3.0/gems/sunspot_solr-2.2.4/solr/solr
root      4137 45.1  4.8 1480560 185632 ?      Sl   12:41   0:09 java -server -Xss256k -Xms512m -Xmx512m -XX:NewRatio=3 -XX:SurvivorRatio=4 -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=8 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:ConcGCThreads=4 -XX:ParallelGCThreads=4 -XX:+CMSScavengeBeforeRemark -XX:PretenureSizeThreshold=64m -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=50 -XX:CMSMaxAbortablePrecleanTime=6000 -XX:+CMSParallelRemarkEnabled -XX:+ParallelRefProcEnabled -XX:CMSFullGCsBeforeCompaction=1 -XX:CMSTriggerPermRatio=80 -verbose:gc -XX:+PrintHeapAtGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:/ebs/staging/shared/bundle/ruby/2.3.0/gems/sunspot_solr-2.2.4/solr/server/logs/solr_gc.log -Djetty.port=8983 -DSTOP.PORT=7983 -DSTOP.KEY=solrrocks -Duser.timezone=UTC -Djetty.home=/ebs/staging/shared/bundle/ruby/2.3.0/gems/sunspot_solr-2.2.4/solr/server -Dsolr.solr.home=/ebs/staging/shared/bundle/ruby/2.3.0/gems/sunspot_solr-2.2.4/solr/solr -Dsolr.install.dir=/ebs/staging/shared/bundle/ruby/2.3.0/gems/sunspot_solr-2.2.4/solr -jar start.jar --module=http
ubuntu    4192  0.0  0.0  10460   936 pts/3    S+   12:41   0:00 grep --color=auto sunspot</code></pre>
</div>
</div>
</p>

<p>However, I'm also running <code>tail -f /var/logs/monit.log</code> and see this at the same time:</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>[CST Mar  3 12:42:54] error    : 'sunspot_solr' process is not running
[CST Mar  3 12:42:54] info     : 'sunspot_solr' trying to restart
[CST Mar  3 12:42:54] info     : 'sunspot_solr' start: /usr/bin/sudo
[CST Mar  3 12:43:25] error    : 'sunspot_solr' failed to start</code></pre>
</div>
</div>
</p>

<p>Plus, to make sure monit can actually restart the sunspot_solr process, I run <code>sudo kill -9 &lt;the pid&gt;</code> and monit can't restart sunspot_solr:</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>[CST Mar  3 12:44:25] error    : 'sunspot_solr' process is not running
[CST Mar  3 12:44:25] info     : 'sunspot_solr' trying to restart
[CST Mar  3 12:44:25] info     : 'sunspot_solr' start: /usr/bin/sudo
[CST Mar  3 12:44:55] error    : 'sunspot_solr' failed to start</code></pre>
</div>
</div>
</p>

<p>Obviously something is wrong with my <code>monit-solr_sunspot.conf</code> file, but after messing around with it for a few hours now, I'm stumped:</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>check process sunspot_solr with pidfile /ebs/staging/shared/pids/sunspot-solr.pid
  start program = "/usr/bin/sudo -H -u root /bin/bash -l -c 'cd /ebs/staging/releases/20160226191542; bundle exec sunspot-solr start -- -p 8983 -d /ebs/staging/shared/solr/data --pid-dir=/ebs/staging/shared/pids'"
  stop program = "/usr/bin/sudo -H -u root /bin/bash -l -c 'cd /ebs/staging/releases/20160226191542; bundle exec sunspot-solr stop -- -p 8983 -d /ebs/staging/shared/solr/data --pid-dir=/ebs/staging/shared/pids'"</code></pre>
</div>
</div>
</p>

<p>I've adapted this monit script to suit my needs: <a href="https://gist.github.com/pcolazurdo/4532625" rel="nofollow">Sample sunspot-solr.monit</a> but am still having no luck!</p>

<p><strong>UPDATE</strong>
I've gotten monit to successfully restart sunspot_solr if I kill it, however it still produces the error that it failed to restart in the <code>monit.log</code> file.</p>