title: Stopping a started background service (phantomjs) in gitlab-ci
body: <p>I'm starting phantomjs with specific arguments as part of my job.</p>
  
  <p>This is running on a custom gitlab/gitlab-ci server, I'm currently not using containers, I guess that would simplify that.</p>
  
  <p>I'm starting phantomjs like this:</p>
  
  <pre><code>- "timeout 300 phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 2&gt;&amp;1 &gt;&gt; /tmp/gastonjs.log &amp;"
  </code></pre>
  
  <p>Then I'm running my behat tests, and then I'm stopping that process again:</p>
  
  <pre><code>- "pkill -f 'src/Client/main.js' || true"
  </code></pre>
  
  <p>The problem is when a behat test fails, then it doesn't execute the pkill and the test-run is stuck waiting on phantomjs to finish. I already added the timeout 300 but that means I'm still currently waiting 2min or so after a fail and it will eventually stop it while test are still running when they get slow enough.</p>
  
  <p>I haven't found a way to run some kind of post-run/cleanup command that also runs in case of fails.</p>
  
  <p>Is there a better way to do this? Can I start phantomjs in a way that gitlab-ci doesn't care that it is still running? nohup maybe? </p>