<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Shell script for Apache stop (kill command) in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983408#M754855</link>
    <description>&amp;gt; The question is [...]&lt;BR /&gt;&lt;BR /&gt;No, the question (or, at least _one_&lt;BR /&gt;question) is what your "grep" command is&lt;BR /&gt;finding in the "$ps" output.  It's not&lt;BR /&gt;unusual to find the "grep" process itself, as&lt;BR /&gt;well as the process with the PID for which&lt;BR /&gt;you are looking.  If you try to kill the&lt;BR /&gt;"grep" process instead of the Apache process,&lt;BR /&gt;you may not get the result you want.&lt;BR /&gt;&lt;BR /&gt;Whether the "$ps" sees the "grep" process&lt;BR /&gt;will depend on when the processes are&lt;BR /&gt;created, and how fast they run, and _those_&lt;BR /&gt;things may depend on the number of CPU's or&lt;BR /&gt;the patch level, or any number of other&lt;BR /&gt;things.&lt;BR /&gt;&lt;BR /&gt;This is why so many people will tell you not&lt;BR /&gt;to use "grep $pid" to find a process.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; For some reson, I do not use apachectl.&lt;BR /&gt;&lt;BR /&gt;Until you figure out what that reason might&lt;BR /&gt;be, I'd suggest using "apachectl", or, at the&lt;BR /&gt;very least, looking at it to see how it&lt;BR /&gt;works.  I have not looked at it, but if it&lt;BR /&gt;uses "grep" to look for a PID in "ps" output,&lt;BR /&gt;I'll be amazed.</description>
    <pubDate>Tue, 17 Apr 2007 23:40:21 GMT</pubDate>
    <dc:creator>Steven Schweda</dc:creator>
    <dc:date>2007-04-17T23:40:21Z</dc:date>
    <item>
      <title>Shell script for Apache stop (kill command)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983404#M754851</link>
      <description>&lt;BR /&gt;Hi All,&lt;BR /&gt;&lt;BR /&gt;We have the program kill [process number] and kill -p [process number] on HP-UX 11i and the Apache process is alive more than 10 seconds. A user saw the message like "Cannot stop Administration Server. Please kill process $hpid manually and try again."&lt;BR /&gt;&lt;BR /&gt;We are using 1.3.19-rev2 of Apache.&lt;BR /&gt;&lt;BR /&gt;Here is the extraction from our shell script.&lt;BR /&gt;&lt;BR /&gt;----------------&lt;BR /&gt;pidfile="./WebServer/logs/httpd.pid"&lt;BR /&gt;&lt;BR /&gt;if ($ps | grep "$hpid" &amp;gt;/dev/null) ; then kill $hpid ; sleep 10 ; else rm -f ./&lt;BR /&gt;WebServer/logs/httpd.pid ; fi&lt;BR /&gt;# try again with more force&lt;BR /&gt;if ($ps | grep "$hpid" &amp;gt;/dev/null) ; then kill -9 $hpid ; sleep 10 ; else rm -f&lt;BR /&gt;./WebServer/logs/httpd.pid ; fi&lt;BR /&gt;# give up.&lt;BR /&gt;if ($ps | grep "$hpid" &amp;gt;/dev/null)&lt;BR /&gt;then&lt;BR /&gt;echo&lt;BR /&gt;echo Cannot stop Administration Server. Please kill process $hpid manually and try again.&lt;BR /&gt;---------------&lt;BR /&gt;&lt;BR /&gt;We can reproduce the issue on good spec machine like (2CPU, 8GB RRAM) , but we can not reproduce 1CUP machine&lt;BR /&gt;&lt;BR /&gt;If those kind of error was barely happening on n good spec machine but we can not see the phenomenon on 1 CPU machine.&lt;BR /&gt;&lt;BR /&gt;Regards, &lt;BR /&gt;</description>
      <pubDate>Tue, 17 Apr 2007 18:46:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983404#M754851</guid>
      <dc:creator>tash S</dc:creator>
      <dc:date>2007-04-17T18:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script for Apache stop (kill command)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983405#M754852</link>
      <description>The script fragment is incomplete and several variables are undefined. Is $ps the ps command? Is $hpid a process ID number? If so, using grep is a serious error in trying to locate a process. grep knows nothing about PID -- it is a dumb match program. If the $hpid is 123 then grep will find PID=1234 and also 4123 and on and on. It will also find bill123 which is a user on the system and possible lab123b which is a group name. Never use grep for finding a PID. Just use ps to find the process by PID:&lt;BR /&gt; &lt;BR /&gt;ps -p $hpid&lt;BR /&gt; &lt;BR /&gt;will be an exact match. Using grep almost always results in multiple (and unexpected) matches. You may end up killing important processes or finding a process which is not the right one.</description>
      <pubDate>Tue, 17 Apr 2007 19:31:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983405#M754852</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2007-04-17T19:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script for Apache stop (kill command)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983406#M754853</link>
      <description>According to:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://httpd.apache.org/docs/" target="_blank"&gt;http://httpd.apache.org/docs/&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://httpd.apache.org/docs/1.3/" target="_blank"&gt;http://httpd.apache.org/docs/1.3/&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://httpd.apache.org/docs/1.3/stopping.html" target="_blank"&gt;http://httpd.apache.org/docs/1.3/stopping.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Apache 1.3 comes with an "apachectl" script:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://httpd.apache.org/docs/1.3/programs/apachectl.html" target="_blank"&gt;http://httpd.apache.org/docs/1.3/programs/apachectl.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Is there any reason not to use that one?&lt;BR /&gt;&lt;BR /&gt;It's hard to know what's wrong in your case&lt;BR /&gt;when we can't see what your "$ps" is, or what&lt;BR /&gt;is in its output.  As Mr. Hassell has&lt;BR /&gt;explained, "grep" for a process ID is almost&lt;BR /&gt;always a bad idea.  Which is probably why&lt;BR /&gt;Apache saves its own PID in its "PidFile":&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://httpd.apache.org/docs/1.3/mod/core.html#pidfile" target="_blank"&gt;http://httpd.apache.org/docs/1.3/mod/core.html#pidfile&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I run Apache on VMS where things are done&lt;BR /&gt;differently, but I'd expect "apachectl" to&lt;BR /&gt;be written better than your script appears&lt;BR /&gt;to be.</description>
      <pubDate>Tue, 17 Apr 2007 22:10:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983406#M754853</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-04-17T22:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script for Apache stop (kill command)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983407#M754854</link>
      <description>Hi All,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;We got the pidfile in the below.&lt;BR /&gt;&lt;BR /&gt;pidfile="./webserver/logs/httpd.pid"&lt;BR /&gt;&lt;BR /&gt;I do not use egrep. For some reson, I do not use apachectl.&lt;BR /&gt;&lt;BR /&gt;The question is that the time of the process to be killed 'kill -9 command' depends on the number of CPU or patch level?</description>
      <pubDate>Tue, 17 Apr 2007 23:23:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983407#M754854</guid>
      <dc:creator>tash S</dc:creator>
      <dc:date>2007-04-17T23:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script for Apache stop (kill command)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983408#M754855</link>
      <description>&amp;gt; The question is [...]&lt;BR /&gt;&lt;BR /&gt;No, the question (or, at least _one_&lt;BR /&gt;question) is what your "grep" command is&lt;BR /&gt;finding in the "$ps" output.  It's not&lt;BR /&gt;unusual to find the "grep" process itself, as&lt;BR /&gt;well as the process with the PID for which&lt;BR /&gt;you are looking.  If you try to kill the&lt;BR /&gt;"grep" process instead of the Apache process,&lt;BR /&gt;you may not get the result you want.&lt;BR /&gt;&lt;BR /&gt;Whether the "$ps" sees the "grep" process&lt;BR /&gt;will depend on when the processes are&lt;BR /&gt;created, and how fast they run, and _those_&lt;BR /&gt;things may depend on the number of CPU's or&lt;BR /&gt;the patch level, or any number of other&lt;BR /&gt;things.&lt;BR /&gt;&lt;BR /&gt;This is why so many people will tell you not&lt;BR /&gt;to use "grep $pid" to find a process.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; For some reson, I do not use apachectl.&lt;BR /&gt;&lt;BR /&gt;Until you figure out what that reason might&lt;BR /&gt;be, I'd suggest using "apachectl", or, at the&lt;BR /&gt;very least, looking at it to see how it&lt;BR /&gt;works.  I have not looked at it, but if it&lt;BR /&gt;uses "grep" to look for a PID in "ps" output,&lt;BR /&gt;I'll be amazed.</description>
      <pubDate>Tue, 17 Apr 2007 23:40:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983408#M754855</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-04-17T23:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script for Apache stop (kill command)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983409#M754856</link>
      <description>&lt;!--!*#--&gt;As you seemingly are storing the PID of the httpd parent process, which needs to be signalled, in a pidfile then you should use it.&lt;BR /&gt;However, I would urge you to use an absolute path, not a relative one as you did:&lt;BR /&gt;&lt;BR /&gt;pidfile="./webserver/logs/httpd.pid"&lt;BR /&gt;&lt;BR /&gt;Then you could test if the httpd root process is running like so:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;httpd_pid=$(cat $pidfile)&lt;BR /&gt;&lt;BR /&gt;if [[ -n $httpd_pid ]]; then&lt;BR /&gt;    if kill -0 $httpd_pid 2&amp;gt;/dev/null; then&lt;BR /&gt;        # do the shutdown&lt;BR /&gt;        # use better method than mere kill&lt;BR /&gt;        kill $httpd_pid&lt;BR /&gt;    else&lt;BR /&gt;        echo "No Apache running"&lt;BR /&gt;        exit 1&lt;BR /&gt;    fi&lt;BR /&gt;else&lt;BR /&gt;    echo "pidfile contained no PID"&lt;BR /&gt;    # implement other PID parsing here&lt;BR /&gt;    # (see below)&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;However I would suggest to use the shipped apachectl script.&lt;BR /&gt;Usually it only requires minor adaptations (if any at all), but mostly only for getting the status argument work (requires enabling mod_status in apache, and a command line user agent that can dump the HTTP response as ordinary text).&lt;BR /&gt;&lt;BR /&gt;If you absolutely have no penchant to use apachectl then you could parse the httpd parent proc's PID like this (only works this way on HP-UX, and if you don't have several separate webservers running)&lt;BR /&gt;&lt;BR /&gt;httpd_pid=$(UNIX95= ps -C httpd -o pid= -o ppid=|awk '$2==1{print$1}')&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Apr 2007 03:05:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983409#M754856</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2007-04-18T03:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script for Apache stop (kill command)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983410#M754857</link>
      <description>Hi,&lt;BR /&gt;As mentioned "apachectl stop" should be used if you intend to stop the apache server.&lt;BR /&gt;&lt;BR /&gt;... but if you intend to stop a specific process you might be interested in looking into the /sbin/init.d/template script and how it is done by the init process.&lt;BR /&gt;&lt;BR /&gt;You could use the killproc function, but as Clay wisely have stated!!! You must ensure a unique identification of you process&lt;BR /&gt;&lt;BR /&gt;/Tor-Arne</description>
      <pubDate>Thu, 19 Apr 2007 12:05:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983410#M754857</guid>
      <dc:creator>Tor-Arne Nostdal</dc:creator>
      <dc:date>2007-04-19T12:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script for Apache stop (kill command)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983411#M754858</link>
      <description>The question itself of mine was NOT the matter of the script.&lt;BR /&gt;&lt;BR /&gt;The question is why the time of the process to be killed 'kill -9 command' take a time, for example, more than 10 seconds, depends on the number of CPU or patch level?&lt;BR /&gt;&lt;BR /&gt;1 CPU case was very fast.&lt;BR /&gt;4 CPU case was that very barely it takes more than 10 seconds.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Apr 2007 21:48:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983411#M754858</guid>
      <dc:creator>tash S</dc:creator>
      <dc:date>2007-04-19T21:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script for Apache stop (kill command)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983412#M754859</link>
      <description>&amp;gt; The question itself of mine was NOT the&lt;BR /&gt;&amp;gt; matter of the script.&lt;BR /&gt;&lt;BR /&gt;Perhaps not, but the script is so badly&lt;BR /&gt;written (and described) that no one can tell&lt;BR /&gt;exactly what it is doing.  Perhaps the first&lt;BR /&gt;'kill $hpid' works perfectly, but the second&lt;BR /&gt;'$ps | grep "$hpid"' gets lucky and finds the&lt;BR /&gt;string "$hpid" somewhere else in the report.&lt;BR /&gt;&lt;BR /&gt;For example, if "hpid" were "123", and some&lt;BR /&gt;user were running a program named&lt;BR /&gt;"abc123def", then the second "$ps" (whatever&lt;BR /&gt;that might be) report could include the&lt;BR /&gt;"abc123def" job, and 'grep "$hpid"' could&lt;BR /&gt;find _that_ "123" even if process "123" were&lt;BR /&gt;dead and gone.&lt;BR /&gt;&lt;BR /&gt;It looks like a bad script, and you have not&lt;BR /&gt;explained all of its mysteries (like "$ps",&lt;BR /&gt;or "$hpid").  It could do anything.  No one&lt;BR /&gt;can tell you _why_ it does anything, because&lt;BR /&gt;no one can know _what_ it is doing.&lt;BR /&gt;&lt;BR /&gt;I have a program which adds two numbers&lt;BR /&gt;together, but it gets the wrong result.  When&lt;BR /&gt;you can tell me what's wrong with my program,&lt;BR /&gt;I'll tell you what's wrong with yours.&lt;BR /&gt;</description>
      <pubDate>Fri, 20 Apr 2007 00:13:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-for-apache-stop-kill-command/m-p/3983412#M754859</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-04-20T00:13:17Z</dc:date>
    </item>
  </channel>
</rss>

