Measure Tomcat's Shutdown Interval
<p>I am trying to measure my Tomcat server shutdown interval and write it to the log. I'm trying to use the following Python code:</p>

<pre><code>    log_times.append(datetime.now().strftime(TIME_PATTERN)) # logs start time
    subprocess.check_call(['service', 'tomcat7', 'stop'])
    pid = subprocess.Popen(['pgrep', '-utomcat7'], stdout=subprocess.PIPE).communicate()[0]
    while (pid != ''):
        log.info('pgrep found tomcat process: %s', pid)
        pid = subprocess.Popen(['pgrep', '-utomcat7'], stdout=subprocess.PIPE).communicate()[0]
    log_times.append(datetime.now().strftime(TIME_PATTERN)) # logs tomcat shutdown time
</code></pre>

<p>Is there a better \ accurate way to do this ?</p>

<p>You can  try use a bash script. For example stop_tomcat.sh:</p>

<pre><code>START=$(date +%s.%N)
service tomcat7 stop
END=$(date +%s.%N)
DIFF=$(echo "$END - $START" | bc)
echo $DIFF
</code></pre>

<p>Change permissions :</p>

<pre><code>chmod 755
</code></pre>

<p>call it from python and take it stdout :</p>

<pre><code>time = subprocess.Popen(['./stop_tomcat.sh'], stdout=subprocess.PIPE).communicate()[0]
</code></pre>

<p>More details about measuring time in bash <a href="http://unix.stackexchange.com/a/12069">http://unix.stackexchange.com/a/12069</a>. </p>

java python tomcat