<div dir="ltr">Sorry for the crude question, but why would you want to do this?<div><br></div><div>Are you trying to run to different versions of apache for testing or for some specific application need?</div><div><br></div>
<div>What advantages do two separate instances of the actual apache process present over a multiple virtual host configurations? This usually covers 99% of usage cases.</div><div><br></div><div>Just curious,</div><div><br>
</div><div>Tom.</div><div><br><div class="gmail_quote">On Tue, Oct 5, 2010 at 3:42 PM, Gabor Szabo <span dir="ltr"><<a href="mailto:szabgab@gmail.com">szabgab@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I need to run two instances of Apache on the same SuSE based server but there<br>
is something very basic I don't manage. In order to run to servers<br>
I'll need two pid files<br>
to hold the two process ids. So the first thing I tried was to change<br>
the pidfile for the existing server.<br>
<br>
I shut down Apache and the changed /etc/init.d/apache2<br>
the following line:<br>
<br>
: ${pidfile:=/var/run/httpd2.pid}<br>
<br>
to:<br>
<br>
: ${pidfile:=/var/run/httpd2b.pid}<br>
<br>
The problem is that after starting the web server using<br>
<br>
/etc/init.d/apache2 start<br>
<br>
it still created the /var/run/httpd2.pid file and NOT the<br>
/var/run/httpd2b.pid file.<br>
<br>
When I tried to stop the web server:<br>
/etc/init.d/apache2 stop<br>
I got:<br>
"Shutting down httpd2 (not running) "<br>
<br>
As an experience, then I renamed<br>
/var/run/httpd2.pid to /var/run/httpd2b.pid<br>
and tried to shut down the server again<br>
<br>
/etc/init.d/apache2 stop<br>
<br>
It printed:<br>
Shutting down httpd2 (waiting for all children to terminate)<br>
and then it got stuck for quite a while (20-30 sec maybe)<br>
In the end it stopped the server but also left the<br>
/var/run/httpd2b.pid file.<br>
<br>
I am quite lost as looking at the /etc/init.d/apache2 script I don't know<br>
where does it take the old name from. Not even where does it create<br>
the pid file.<br>
<br>
<br>
regards<br>
Gabor<br>
<br>
<br>
ps. This is the /etc/init.d/apache2 script:<br>
---------------------------------------------------<br>
#!/bin/sh<br>
#<br>
# Copyright (c) 1996, 1997, 1998 S.u.S.E. GmbH<br>
# Copyright (c) 1998, 1999, 2000, 2001 SuSE GmbH<br>
# Copyright (c) 2002, 2003, (2004?) SuSE Linux AG<br>
# Copyright (c) 2004(?), 2005, 2006, 2007, 2008 SUSE Linux Products GmbH<br>
#<br>
# Authors: Rolf Haberrecker <<a href="mailto:apache@suse.de">apache@suse.de</a>>, 2001<br>
# Peter Poeml <<a href="mailto:apache@suse.de">apache@suse.de</a>>, 2002, 2003, 2004, 2005, 2006,<br>
2007, 2008<br>
#<br>
#<br>
# /etc/init.d/apache2<br>
#<br>
### BEGIN INIT INFO<br>
# Provides: apache apache2 httpd<br>
# Required-Start: $local_fs $remote_fs $network<br>
# Should-Start: $named $time postgresql sendmail mysql ypclient dhcp radiusd<br>
# Should-Stop: $named $time postgresql sendmail mysql ypclient dhcp radiusd<br>
# Required-Stop: $local_fs $remote_fs $network<br>
# Default-Start: 3 5<br>
# Default-Stop: 0 1 2 6<br>
# Short-Description: Apache 2.2 HTTP Server<br>
# Description: Start the Apache HTTP daemon<br>
### END INIT INFO<br>
<br>
pname=apache2<br>
: ${sysconfdir:=/etc/$pname}<br>
: ${apache_link:=/usr/sbin/httpd2}<br>
: ${sysconfig_apache:=/etc/sysconfig/$pname}<br>
: ${pidfile:=/var/run/httpd2b.pid}<br>
: ${logdir:=/var/log/$pname}<br>
: ${homedir:=/var/lib/$pname}<br>
<br>
#<br>
# load the configuration<br>
#<br>
<br>
#<br>
# Note about ulimits:<br>
# if you want to set ulimits, e.g. to increase the max number of open<br>
file handle,<br>
# or to allow core files, you can do so by editing /etc/sysconfig/apache2 and<br>
# simply write the ulimit commands into that file.<br>
# Example:<br>
# ulimit -n 16384<br>
# ulimit -H -n 16384<br>
# ulimit -c unlimited<br>
# See the output of "help ulimit" in the bash, or "man 1 ulimit".<br>
#<br>
test -s /etc/rc.status && . /etc/rc.status && rc_reset<br>
<br>
. /usr/share/$pname/load_configuration<br>
export ${!APACHE_*}<br>
<br>
httpd_conf=${APACHE_HTTPD_CONF:-$sysconfdir/httpd.conf}<br>
<br>
apache_bin=$(/usr/share/$pname/find_mpm 2>/dev/null)<br>
<br>
test -L $apache_link && apache_bin=$(readlink $apache_link)<br>
<br>
if [ -z "$APACHE_MPM" ]; then<br>
APACHE_MPM=${apache_bin##*-}<br>
fi<br>
<br>
if ! [ -x $apache_bin ]; then<br>
echo >&2 ${warn}$apache_bin-$APACHE_MPM is not a valid httpd2 binary.<br>
echo >&2 Check your APACHE_MPM setting in /etc/sysconfig/$pname. $norm<br>
rc_failed 5<br>
rc_status -v1<br>
rc_exit<br>
fi<br>
<br>
# a proper home should be set, otherwise the server might end up<br>
# with HOME=/root and some script might try to use that<br>
HOME=$homedir<br>
<br>
get_server_flags()<br>
{<br>
unset server_flags<br>
case "$action" in startssl) server_flags="-DSSL";; esac<br>
for i in $APACHE_SERVER_FLAGS; do<br>
case $i in<br>
-D) ;;<br>
-D*) server_flags="$server_flags $i";;<br>
*) server_flags="$server_flags -D$i";;<br>
esac<br>
done<br>
}<br>
<br>
action="$1"<br>
case "$action" in<br>
stop|try-restart|*status*|probe)<br>
;;<br>
*)<br>
shift; get_server_flags<br>
${get_module_list_done:=false} || /usr/share/$pname/get_module_list<br>
&& export get_module_list_done=true<br>
${get_includes:=false} || /usr/share/$pname/get_includes && export<br>
get_includes_done=true<br>
;;<br>
esac<br>
<br>
#<br>
# main part<br>
#<br>
case "$action" in<br>
start*)<br>
if [ -e $pidfile ]; then<br>
$0 status &>/dev/null<br>
ret=$?<br>
if [ $ret = 1 ]; then<br>
echo "Warning: found stale pidfile (unclean shutdown?)"<br>
elif [ $ret = 0 ]; then<br>
echo "Apache is already running ($pidfile)"<br>
rc_failed $ret<br>
rc_status -v1<br>
rc_exit<br>
fi<br>
fi<br>
<br>
echo -n "Starting httpd2 (${APACHE_MPM:-${apache_bin#*-}}) "<br>
cmdline=$(echo $apache_bin -f $httpd_conf $server_flags "$@")<br>
if eval $cmdline -t > $logdir/rc$pname.out 2>&1 ; then<br>
export -n ${!APACHE_*}<br>
eval startproc -f -t ${APACHE_START_TIMEOUT:-2} $cmdline<br>
ret=$?<br>
<br>
if test -t 1 && stty -a 2>/dev/null | grep -q -- -echo\ ; then<br>
# this means that apache was still waiting for a passphrase to be entered<br>
stty echo 2>/dev/null<br>
echo;echo<br>
echo >&2 An SSL passphrase has not been entered within<br>
${APACHE_START_TIMEOUT:-<not set>} seconds.<br>
echo >&2 To increase this timeout, adjust APACHE_START_TIMEOUT in<br>
$sysconfig_apache .<br>
# this surely means that apache won't start, despite it looked good<br>
to startproc<br>
killall $apache_bin<br>
echo >&2 "Trying to start the server without SSL (-D NOSSL)."<br>
$0 start "$@" -D NOSSL<br>
# rc_failed 1<br>
# rc_status -v1<br>
# rc_exit<br>
else<br>
rc_failed $ret<br>
rc_status -v<br>
fi<br>
else<br>
if [ "$link" = "$base" ] ; then<br>
cat $logdir/rc$pname.out<br>
echo >&2<br>
echo >&2 The command line was:<br>
echo >&2 $cmdline<br>
echo >&2<br>
else<br>
echo -e -n "\nsee $logdir/rc$pname.out for details\n";<br>
fi<br>
rc_failed 1<br>
rc_status -v1<br>
fi<br>
;;<br>
stop)<br>
echo -n "Shutting down httpd2 "<br>
if [ ! -f $pidfile -a -f $pidfile.rpmsave ]; then mv<br>
$pidfile.rpmsave $pidfile; fi<br>
if ! [ -f $pidfile ]; then<br>
echo -n "(not running)"<br>
else<br>
pid=$(<$pidfile)<br>
kill -TERM $pid 2>/dev/null<br>
case $? in<br>
1) echo -n "(not running)";;<br>
0) # wait until the processes are gone (the parent is the last one)<br>
echo -n "(waiting for all children to terminate) "<br>
for ((wait=0; wait<120; wait++)); do<br>
if test -f $pidfile; then<br>
usleep 500000<br>
continue<br>
fi<br>
if ! test -f /proc/$pid/exe; then<br>
break<br>
fi<br>
if test "$(readlink /proc/$pid/exe 2>/dev/null)" = $apache_bin; then<br>
usleep 500000<br>
else<br>
break<br>
fi<br>
<br>
done<br>
;;<br>
esac<br>
fi<br>
<br>
rc_status -v<br>
;;<br>
stop-graceful)<br>
echo "Shutting down httpd2 gracefully (SIGWINCH)"<br>
if ! [ -f $pidfile ]; then<br>
echo -n "(not running)"<br>
else<br>
pid=$(<$pidfile)<br>
kill -WINCH $pid 2>/dev/null<br>
case $? in<br>
1) echo -n "(not running)";;<br>
0) # wait until the pidfile is gone. The parent<br>
stays there, but closes the listen ports.<br>
echo -n "(waiting for parent to close listen<br>
ports and remove pidfile) "<br>
for ((wait=0; wait<120; wait++)); do<br>
if test -f $pidfile; then<br>
usleep 500000<br>
continue<br>
else<br>
break<br>
fi<br>
done<br>
;;<br>
esac<br>
fi<br>
<br>
rc_status -v<br>
;;<br>
try-restart)<br>
## Do a restart only if the service was active before.<br>
## Note: try-restart is now part of LSB (as of 1.9).<br>
## RH has a similar command named condrestart.<br>
$0 status<br>
if test $? = 0; then<br>
$0 restart<br>
else<br>
rc_reset # Not running is not a failure.<br>
fi<br>
# Remember status and be quiet<br>
rc_status<br>
;;<br>
restart)<br>
$0 configtest "$@" || { rc_failed $?; rc_exit; }<br>
<br>
if $0 status &>/dev/null; then<br>
$0 stop<br>
fi<br>
$0 start "$@"<br>
# Remember status and be quiet<br>
rc_status<br>
;;<br>
restart-hup)<br>
$0 configtest "$@" || { rc_failed $?; rc_exit; }<br>
<br>
if $0 status &>/dev/null; then<br>
echo -n "Restarting httpd2 (SIGHUP)"<br>
kill -HUP $(<$pidfile) || return=$rc_failed<br>
else<br>
$0 start "$@"<br>
fi<br>
# Remember status and be quiet<br>
rc_status -v<br>
;;<br>
restart-graceful)<br>
$0 configtest "$@" || { rc_failed $?; rc_exit; }<br>
<br>
if $0 status &>/dev/null; then<br>
$0 stop-graceful "$@"<br>
$0 start "$@"<br>
else<br>
$0 start "$@"<br>
fi<br>
# Remember status and be quiet<br>
rc_status<br>
;;<br>
reload|force-reload|graceful)<br>
echo -n "Reload httpd2 (graceful restart)"<br>
cmdline=$(echo $apache_bin -f $httpd_conf $server_flags "$@")<br>
if eval $cmdline -t &> $logdir/rc$pname.out; then<br>
killproc -USR1 $apache_bin || return=$rc_failed<br>
rc_status -v<br>
else<br>
if [ "$link" = "$base" ] ; then<br>
echo -e -n "\n\n"<br>
cat $logdir/rc$pname.out<br>
echo >&2<br>
echo >&2 The command line was:<br>
echo >&2 $cmdline<br>
echo >&2<br>
else<br>
echo -e -n "\nsee $logdir/rc$pname.out for details\n";<br>
fi<br>
rc_failed 6<br>
rc_status -v1<br>
fi<br>
;;<br>
status)<br>
if [ ! -f $pidfile -a -f $pidfile.rpmsave ]; then mv<br>
$pidfile.rpmsave $pidfile; fi<br>
echo -n "Checking for httpd2: "<br>
# we don't use checkproc here since it is confused when we exchange<br>
the binaries<br>
if ! [ -f $pidfile ]; then<br>
# not running<br>
rc_failed 3<br>
elif [ -s $pidfile -a -d /proc/$(<$pidfile) ]; then<br>
# running<br>
:<br>
else<br>
# stale pid file<br>
rc_failed 1<br>
#rm -f $pidfile<br>
fi<br>
rc_status -v<br>
;;<br>
probe)<br>
## Optional: Probe for the necessity of a reload,<br>
## give out the argument which is required for a reload.<br>
<br>
for i in $httpd_conf \<br>
$APACHE_CONF_INCLUDE_FILES \<br>
$APACHE_CONF_INCLUDE_DIRS<br>
do<br>
if [ $i -nt $pidfile ]; then<br>
echo reload<br>
break<br>
fi<br>
done<br>
;;<br>
<br>
conf*|test|syntax|check)<br>
cmdline=$(echo $apache_bin -f $httpd_conf $server_flags "$@")<br>
eval $cmdline -t<br>
rc_failed $?<br>
rc_exit<br>
;;<br>
<br>
extr*)<br>
cmdline=$(echo $apache_bin -f $httpd_conf $server_flags "$@")<br>
out=$(su - nobody -c "$cmdline" 2>&1)<br>
case $out in<br>
*make_sock:\ could\ not\ bind\ to\ address*) echo Syntax: OK; rc_failed=0;;<br>
*) echo Syntax: NOT OK:; echo $out; rc_failed=1;;<br>
esac<br>
rc_exit<br>
;;<br>
<br>
server-status)<br>
apache2ctl status<br>
;;<br>
<br>
full-server-status|fullstatus)<br>
apache2ctl fullstatus<br>
;;<br>
<br>
*)<br>
cat >&2 <<-EOF<br>
Usage: $0 <command> <server flags><br>
<br>
where <command> is one of:<br>
start - start httpd<br>
startssl - start httpd with -DSSL<br>
stop - stop httpd (sending SIGTERM to parent)<br>
try-restart - stop httpd and if this succeeds (i.e. if<br>
it was running before), start it again.<br>
<br>
status - check whether httpd is running<br>
<br>
restart - stop httpd if running; start httpd<br>
restart-graceful - stop httpd gracefully if running; start httpd<br>
reload|graceful - do a graceful restart by sending a SIGUSR1, or<br>
start if not running<br>
stop-graceful - stop httpd (sending SIGWINCH to parent)<br>
<br>
configtest - do a configuration syntax test<br>
extreme-configtest - try to run httpd as nobody (detects more errors<br>
by actually loading the configuration, but cannot<br>
read SSL certificates)<br>
probe - probe for the necessity of a reload, give<br>
out the argument which is required for a reload.<br>
(by comparing conf files with pidfile timestamp)<br>
<br>
full-server-status - dump a full status screen; requires lynx or w3m<br>
and mod_status enabled<br>
server-status - dump a short status screen; requires lynx or w3m<br>
and mod_status enabled<br>
<br>
help - this screen<br>
<br>
optional server flags are passed through to httpd.<br>
<br>
EOF<br>
exit 1<br>
esac<br>
<br>
<br>
# Inform the caller not only verbosely and set an exit status.<br>
rc_exit<br>
<br>
_______________________________________________<br>
Linux-il mailing list<br>
<a href="mailto:Linux-il@cs.huji.ac.il">Linux-il@cs.huji.ac.il</a><br>
<a href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il" target="_blank">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a><br>
</blockquote></div><br></div></div>