title: running service elasticsearch start fails, but running the command manually succeeds
body: <p><strong>Context:</strong></p>
  
  <ul>
  <li>I'm testing an elasticsearch 1.7.1 configuration that's set up by chef, and testing in kitchen</li>
  <li>The chef script and configuration works because it's running in production somehow</li>
  <li>running <code>service elasticsearch start</code> as the elasticsearch user fails, but the actual call it delegates to does not.</li>
  </ul>
  
  <p>From what I've learned, chef scripts are run as root. So, when the test fails (it checks to see if elasticsearch is running by running <code>service elasticsearch status</code>), I log into the vagrant machine. As root, if I run <code>service elasticsearch start</code>, I get an OK (which is incorrect, but another <a href="https://github.com/elastic/elasticsearch/issues/8652" rel="nofollow">issue</a>) and then run a subsequent <code>service elasticsearch status</code>, I'm met with the error: <code>elasticsearch dead but pid file exists</code></p>
  
  <p>Digging further, I set debug statements on the init.d script that's run by <code>service</code> and saw that the actual command was basically a call to the <code>init.d/functions</code> function <code>daemon</code>, which just calls:</p>
  
  <p><code>runuser -s /bin/bash elasticsearch -c 'ulimit -S -c 0 &gt;/dev/null 2&gt;&amp;1 ; /usr/share/elasticsearch/bin/elasticsearch -p /var/run/elasticsearch/elasticsearch.pid -d -Des.default.path.home=/usr/share/elasticsearch -Des.default.path.logs=/var/log/elasticsearch/ -Des.default.path.data=/data/elasticsearch/data/ -Des.default.path.work=/tmp/elasticsearch -Des.default.path.conf=/etc/elasticsearch/'</code></p>
  
  <p>So I tried a <code>sudo su - elasticsearch</code> and then ran the part in quotes:</p>
  
  <pre><code>[elasticsearch@default-centos ~]$ ulimit -S -c 0 &gt;/dev/null 2&gt;&amp;1 ; 
  /usr/share/elasticsearch/bin/elasticsearch 
  -p /var/run/elasticsearch/elasticsearch.pid -d 
  -Des.default.path.home=/usr/share/elasticsearch 
  -Des.default.path.logs=/var/log/elasticsearch/ 
  -Des.default.path.data=/data/elasticsearch/data/ 
  -Des.default.path.work=/tmp/elasticsearch 
  -Des.default.path.conf=/etc/elasticsearch/
  </code></pre>
  
  <p>A subsequent <code>service elasticsearch status</code> shows that elasticsearch is running just fine! I've even set the logging to TRACE, and there's no indication that elasticsearch has crashed.</p>