title: Running Jconsole from a service: CentOS
body: <p>I installed Tomcat on my CentOS 6.3 machine and I made it a service by creating the <code>/etc/init.d/tomcat</code> file.
  It works with the basic start, stop, restart and status functionality just fine.</p>
  
  <p>I use jconsole on the servers often, so I thought it would be nice to build this functionality into the service (by running <code>service tomcat monitor</code>) instead of having to run <code>ps aux|grep java</code> and then running the <code>jconsole &lt;Java PID&gt;</code> .</p>
  
  <p>Here is my service script (Just the monitor section):</p>
  
  <pre><code>monitor)
          # Check for Tomcat PID (greps are separated to prevent returning the single grep PID)
          FOUND_PID=$(ps aux |grep  $JAVA_HOME/bin/ | grep java |awk -F' ' '{print $2}')
          if [[ $FOUND_PID ]]
          then
                  echo -e $JAVA_HOME/bin/jconsole $FOUND_PID
                  $JAVA_HOME/bin/jconsole $FOUND_PID
          else
                  echo -e "Failed: Tomcat is not currently running";
          fi
  ;;
  </code></pre>
  
  <p>Everything inside of the monitor section works when I run the bash script directly it works, but when the service calls it, it just hangs at the jconsole line and doesn't do anything.  </p>
  
  <p>And when I run <code>service tomcat monitor</code>, I do get the correct path output, so I know that the path is correct.</p>
  
  <p>Is there a way to get the jconsole to work when called from the services script?</p>