title: Bash - start multiple services if any is running CentOS 6.8
body: <p>I want to check if one, (or all) services are running, if yes, stop it</p>
  
  <pre><code>#!/bin/bash
  
  
  # Define an array of processes to be checked.
  # If properly quoted, these may contain spaces
  
  check_process=( "nagios" "httpd" )
  
  for p in "${check_process[@]}"; do
      if pgrep "$p" &gt; /dev/null; then
          echo "Process \`$p' is running, stopping it"
          service $p stop
      else
          echo "Process \`$p' is not running"
      fi
  done
  </code></pre>
  
  <p>For httpd service all works fine, script detects correctly <code>httpd</code> service state.
  I have issues detecting <code>nagios</code> service state.
  But although <code>nagios</code> service is not running, script shows it's running</p>
  
  <pre><code>Process `nagios' is running, stopping it
  Stopping nagios:No lock file found in /usr/local/nagios/var/nagios.lock
  Process `httpd' is not running
  </code></pre>
  
  <p>Is there any more elegant way of detecting if nagios service is running without checking if <code>nagios.lock</code> file exists ?</p>
  
  <p><code>pgrep nagios</code> shows no output when service is not tunning.</p>