Bug 100350 - www/apache20 profiles not working at system startup/shutdown time due to unexpected $0 value
Summary: www/apache20 profiles not working at system startup/shutdown time due to unex...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-apache (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-15 19:50 UTC by Mike Andrews
Modified: 2019-01-04 14:37 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Andrews 2006-07-15 19:50:13 UTC
When using the latest apache20 port (from July 14 2006 portsnap) and the profiles
feature to run multiple httpd's on one system (or even just a single profile),
such as the following in /etc/rc.conf:

	apache2_enable="YES"
	apache2_profiles="0DEV"
	apache2_0DEV_flags="-DServer0DEV"
	apache2_0DEV_configfile="/usr/local/etc/apache2/httpd2-test.conf"

Manually using "/usr/local/etc/rc.d/apache2.sh start 0DEV" (or stop or reload
or restart) works fine.

Manually using "/usr/local/etc/rc.d/apache2.sh start" (or stop or reload but
NOT restart) works fine.  restart not working may be related to ports/86402
but that's not that this PR is about :)

At system boot time though, it fails to start Apache with the following error:

	===> apache2 profile: 0DEV
	/usr/local/etc/rc.d/apache2.sh: /etc/rc: Permission denied

On line 73 of /usr/local/etc/rc.d/apache2.sh is a line "$0 $1 $profile" that's
used to re-run apache2.sh for each individual profile.  If I put $0 into the
"echo" line above it, it says $0 is "/etc/rc.d" so it fails when it tries to
re-run the wrong script.  The upshot is I have to manually restart Apache after
a reboot.

At system shutdown $0 gets mangled into "/etc/rc.shutdown" instead of
"/usr/local/etc/rc.d/apache2.sh" the same way.

If I create a simple /usr/local/etc/rc.d/test.sh script containing just

#!/bin/sh
echo Hello, I seem to be $0

then it prints /usr/local/etc/rc.d/test.sh as expected.  Putting that as
the first line in /usr/local/etc/rc.d/apache.2.sh prints /etc/rc at startup,
/etc/rc.shutdown at shutdown and /usr/local/etc/rc.d/apache2.sh when run
manually.  'm not sure why that one is different.  It does run earlier than
some of the others.

With no profiles enabled everything works fine because it never needs to
reference $0 in that case.

Fix: 

Using $_file instead of $0 works for system boot but breaks the manual case.
Perhaps using $_file if it exists and $0 when it doesn't?

There is the possibility that I've done something stupid to my /etc/rc.conf,
(like not using the apache20 profile variables correctly) or that I have another
port whose rc.d script is trashing $0 somehow, or that I just plain don't understand
the rc system.  :)
How-To-Repeat: 
Install www/apache20 on a system (or jail), add the above variables to
/etc/rc.conf, and restart the system (or jail); if a jail then check
/var/log/console.log for the above error messages.
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2006-07-15 19:50:21 UTC
Responsible Changed
From-To: freebsd-ports-bugs->clement

Over to maintainer
Comment 2 Vick Khera 2007-10-10 18:59:33 UTC
FWIW, I'm experiencing the same error today on 6.2/amd64 with the  
lastest apache 2.0.59 port.
Comment 3 Mike Andrews 2007-10-11 06:09:53 UTC
Late followup: the www/apache22 port doesn't seem to have this problem. 
  I don't know if the www/apache20 port has been fixed or not.
Comment 4 Philip M. Gollucci freebsd_committer freebsd_triage 2008-12-27 20:29:02 UTC
Responsible Changed
From-To: clement->apache

apache team
Comment 5 Philip M. Gollucci freebsd_committer freebsd_triage 2009-04-22 05:57:22 UTC
State Changed
From-To: open->feedback

Try this diff 
http://people.freebsd.org/~pgollucci/www_apache20-2.0.63.diff
Comment 6 Philip M. Gollucci freebsd_committer freebsd_triage 2009-06-10 07:18:02 UTC
State Changed
From-To: feedback->closed

feed back timeout (1.5 months from committers)