Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 44559 - initd script returns immediately instead of starting service (apache2)
Summary: initd script returns immediately instead of starting service (apache2)
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: x86 Linux
: High critical (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-03-13 06:43 UTC by Christian Aust
Modified: 2004-04-08 12:50 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Aust 2004-03-13 06:43:39 UTC
Apache2 used to be started with "/etc/init.d/apache2 start". While the script remained unchanged, it doesn't work any more but simply returns immediately without starting the daemon. There's no entry in any log file, not in access_log nor in error_log or /var/log/everything/current. Since I usually do not restart that service and also seldomly restart the machine, I can't tell for sure when or why it broke. I can tell that it worked some weeks ago (when I rebooted the server last time).

Reproducible: Always
Steps to Reproduce:
1. Verify apache2 is not running
2. execute /etc/init.d/apache2 start

Actual Results:  
Nothing, control returned to the shell

Expected Results:  
Apache2 should have been started.

p15140448 root # emerge info
Portage 2.0.50-r1 (default-x86-1.4, gcc-3.3.2, glibc-2.3.2-r9, 2.4.25_pre6-gss)
===============================================================
==
System uname: 2.4.25_pre6-gss i686 Intel(R) Celeron(R) CPU 2.00GHz
Gentoo Base System version 1.4.3.13
Autoconf: sys-devel/autoconf-2.58-r1
Automake: sys-devel/automake-1.7.7
ACCEPT_KEYWORDS="x86"
AUTOCLEAN="yes"
CFLAGS="-march=pentium3 -O2 -pipe -fomit-frame-pointer -falign-functions=4 -fprefetch-loop-
arrays -fforce-addr"
CHOST="i686-pc-linux-gnu"
COMPILER="gcc3"
CONFIG_PROTECT="/etc /etc/tomcat /usr/X11R6/lib/X11/xkb /usr/kde/2/share/config /usr/kde/3/
share/config /usr/share/config /var/bind /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d"
CXXFLAGS="-march=pentium3 -O2 -pipe -fomit-frame-pointer -falign-functions=4 -fprefetch-loop-
arrays -fforce-addr"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoaddcvs ccache sandbox"
GENTOO_MIRRORS="http://gentoo.mirror.sdv.fr http://gentoo.inode.at/ http://linux.rz.ruhr-uni-
bochum.de/download/gentoo-mirror/"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY=""
SYNC="rsync://rsync.de.gentoo.org/gentoo-portage"
USE="X apache2 apm avi berkdb crypt curl encode fastcgi foomaticdb gd gdbm gif gpm gtk2 imap 
imlib innodb java jikes jpeg libg++ libwww mad mcal mikmod motif mpeg mysql ncurses nls oggvorbis 
pam pdflib perl php png python quicktime readline sdl slang snmp spell sse ssl svga tcpd threads tiff 
truetype x86 xml xml2 xv zlib"
Comment 1 Martin Ehmsen (RETIRED) gentoo-dev 2004-03-13 10:58:35 UTC
I have this problem too... I have a fresh installation of apache2, haven't done anything to the config-files but editing the ServerName.
Comment 2 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2004-03-14 01:56:29 UTC
firstly, edit the start() block on /etc/init.d/apache2 so it echos out $APACHE2_OPTS right before it runs apache2. now run it to grab the output.

next, try:
apache2 -k $APACHE2_OPTS 
where APACHE2_OPTS is the options the apache config script showed you.
apache2 should die again as before.

there will be a number of items simliar to '-D PHP4' with various names.
try various combinations of them, until you isolate one that is causing the problems.

apache2 is known to not start up correctly if something is wrong with one of the modules.

if you are good with C and debugging, you might also do an strace -ff on the above command, and try to follow the output (not easy).

depending on which module is broken revdep-rebuild will probably fix it.
Comment 3 Christian Aust 2004-03-14 02:43:31 UTC
I followed robbat2's directions, used revdep-rebuild (it found some unsatisfied dependency in the libraries of Java 1.4.2_03 as far as sound is concerned). I also inserted an echo statement as the first line of /etc/init.d/apache2#start(), but it didn't even print that message (I tried that before as well). This is what I've got now:

p15140448 root # cat /etc/init.d/apache2 /etc/conf.d/apache2
#!/sbin/runscript
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/www/www.gentoo.org/raw_cvs/gentoo-x86/net-www/apache/files/2.0.48-r1/apache2.initd,v 1.3 2004/01/20 09:53:09 robbat2 Exp $

opts="${opts} reload"

[ "x${STARTUPERRORLOG}" != "x" ] && APACHE2_OPTS="${APACHE2_OPTS} -d ${STARTUPERRORLOG}"
[ "x${CONFIGFILE}" != "x" ] && APACHE2_OPTS="${APACHE2_OPTS} -f ${CONFIGFILE}"
[ "x${STARTUPERRORLOG}" != "x" ] && APACHE2_OPTS="${APACHE2_OPTS} -E ${STARTUPERRORLOG}"
# set a default for PIDFILE/RESTARTSTYLE for those that FAILED to follow
# instructiosn and update the conf.d/apache2 file.
# (bug #38787)
[ -z "${PIDFILE}" ] && PIDFILE=/var/run/apache2.pid
[ -z "${RESTARTSTYLE}" ] && RESTARTSTYLE="graceful"

checkconfig() {
        local myconf="/etc/apache2/conf/apache2.conf"
        if [ "x${CONFIGFILE}" != "x" ]; then
                if [ ${CONFIGFILE:0:1} = "/" ]; then
                        myconf="${CONFIGFILE}"
                else
                        myconf="${STARTUPERRORLOG}/${CONFIGFILE}"
                fi
        fi
        if [ ! -r "${myconf}" ]; then
                eerror "Unable to read configuration file: ${myconf}"
                return 1
        fi
    if [ -z "${PIDFILE}" ]; then
        eerror "\$PIDFILE is not set!"
        eerror "Did you etc-update /etc/conf.d/apache2?"
        return 1
    fi
    if [ -z "${RESTARTSTYLE}" ]; then
        eerror "\$RESTARTSTYLE is not set!"
        eerror "Did you etc-update /etc/conf.d/apache2?"
        return 1
    fi
        /usr/sbin/apache2 -t ${APACHE2_OPTS} 1>/dev/null 2>&1
        ret=$?
        if [ $ret -ne 0 ]; then
                eerror "Apache2 has detected a syntax error in your configuration files:"
                /usr/sbin/apache2 -t ${APACHE2_OPTS}
        fi
        return $ret
}

depend() {
        need net
        use mysql dns logger netmount
        after sshd
}

start() {
        echo "OPTS: $APACHE2_OPTS"
        checkconfig || return 1
        ebegin "Starting apache2"
        [ -f /var/log/apache2/ssl_scache ] && rm /var/log/apache2/ssl_scache
        env -i PATH=$PATH /sbin/start-stop-daemon --quiet \
                --start --startas /usr/sbin/apache2 \
                --pidfile ${PIDFILE} -- -k start ${APACHE2_OPTS}
        eend $?
}

stop() {
        ebegin "Stopping apache2"
        /usr/sbin/apache2ctl stop >/dev/null
        start-stop-daemon -o --quiet --stop --pidfile ${PIDFILE}
        eend $?
}

reload() {
        # restarting apache2 is much easier than apache1. The server handles most of the work for us. 
        # see http://httpd.apache.org/docs-2.0/stopping.html for more details
        ebegin "Restarting apache2"
        /usr/sbin/apache2 ${APACHE2_OPTS} -k ${RESTARTSTYLE}
        eend $?
}
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/www/www.gentoo.org/raw_cvs/gentoo-x86/net-www/apache/files/2.0.48-r1/apache2.confd,v 1.1 2004/01/13 01:23:23 robbat2 Exp $

# Config file for /etc/init.d/apache2

# An example from /etc/apache2/conf/modules.d/40_mod_ssl.conf:
#
# <IfDefine SSL>
#  <IfModule !mod_ssl.c>
#    LoadModule ssl_module    extramodules/mod_ssl.so
#  </IfModule>
# </IfDefine>
#
# This means that the mod_ssl.so DSO module is only loaded
# into the server when you pass "-D SSL" at startup.  To
# enable WebDAV, add "-D DAV -D DAV_FS".  If you installed
# mod_php then add "-D PHP4".  For more options, please
# read the files in the /etc/apache2/conf/modules.d directory.

APACHE2_OPTS="-D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN"

# Extended options for advanced uses of Apache ONLY
# You don't need to edit these unless you are doing crazy Apache stuff
# As not having them set correctly, or feeding in an incorrect configuration
# via them will result in Apache failing to start
# YOU HAVE BEEN WARNED.

# ServerRoot setting
#SERVERROOT=/etc/apache2

# Configuration file location
# - If this does NOT start with a '/', then it is treated relative to
# $SERVERROOT by Apache
#CONFIGFILE=conf/apache2.conf

# Location to log startup errors to
# They are normally dumped to your terminal.
#STARTUPERRORLOG="/var/log/apache2/startuperror.log"

# PID file location
# Note that this MUST match the setting in your configuration file!
PIDFILE=/var/run/apache2.pid

# Restart style
# see http://httpd.apache.org/docs-2.0/stopping.html for more details
# the default is 'graceful', the other possible value is 'restart'
# If you use 'graceful', completion of the command does NOT imply that the system
# has finished restarting. Restart is finished only when all child processes
# have finished serving their current request sets. Read the URL for details.
#RESTARTSTYLE="restart"
RESTARTSTYLE="graceful"
p15140448 root # /etc/init.d/apache2 start
p15140448 root # 

Inserting any wrong syntax in the service script will give me an error as expected, but printing messages from there doesn't, as if the start() method wouldn't even be called. How can I trace this?
Comment 4 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2004-03-14 03:46:33 UTC
1. "killall apache2"
2. "netstat -anp |grep 80" ensure nothing is listening on port 80
3. "/etc/init.d/apache2 zap"
4. "/etc/init.d/apache2 start"
this should definetly give some output

Comment 5 Christian Aust 2004-03-14 12:33:42 UTC
The script files are unchanged as of the time when I wrote my last comment. Nothing happens:

p15140448 root # killall apache2
apache2: Kein Prozess abgebrochen
p15140448 root # netstat -anp |grep 80
tcp        0      0 0.0.0.0:8010            0.0.0.0:*               LISTEN      1577/CGServer       
udp        0      0 127.0.0.1:123           0.0.0.0:*                           806/ntpd            
udp        0      0 0.0.0.0:123             0.0.0.0:*                           806/ntpd            
unix  2      [ ]         DGRAM                    1743   806/ntpd            
p15140448 root # /etc/init.d/apache2 zap
p15140448 root # /etc/init.d/apache2 start
p15140448 root # 
Comment 6 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2004-03-14 13:24:30 UTC
wtf?
that makes no sense that there is no output.

anyway, try this for now (from the results you should have got)
apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
and see if it still dies if you try various combinations of the -D params.

if it doesn't die, I'm going to pass this bug to the baselayout people that handle the init scripts.
Comment 7 Christian Aust 2004-03-14 22:31:38 UTC
Apache2 works:

p15140448 root # apache2ctl stop
p15140448 root # apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
p15140448 root # ps ax | grep apache2
17858 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17859 ?        S      0:00 /usr/bin/perl /usr/sbin/apache2splitlogfile
17860 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17861 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17862 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17863 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17864 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17865 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17866 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17867 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17868 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17869 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17870 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17871 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17872 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17873 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17874 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17875 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17888 ?        S      0:00 apache2 -k start -D SSL -D DAV -D DAV_FS -D PHP4 -D RESIN
17936 pts/0    R      0:00 grep apache2
p15140448 root # killall apache2
p15140448 root # ps ax | grep apache2
17958 pts/0    R      0:00 grep apache2
p15140448 root # 

Unfortunately, the rest of the init scripts work: xinetd, mysql, tomcat and the rest... no probs. 
Comment 8 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2004-03-14 23:40:12 UTC
that makes absolutely no sense :-(
Comment 9 Martin Ehmsen (RETIRED) gentoo-dev 2004-03-15 01:12:23 UTC
I still can't make apache2 to work. I have tried everything you suggest and it still don't give any output.
The only (maybe) usefull information I can make apache give is this:
# apache2 -k start
# echo $?
1

So apache dies with exitstatus 1...
I should probably mention that I use linux-header-2.6.3 and a nptl enabled glibc, but in the past I have had apache running on such a system.
Comment 10 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2004-03-15 14:26:53 UTC
Martin: what did you change ServerName to, and does it resolve with DNS from your machine? not /etc/hosts, it MUST resolve with DNS.

do "strace apache2 -k start" and try to follow the output.
Comment 11 Martin Ehmsen (RETIRED) gentoo-dev 2004-03-15 23:38:20 UTC
I have solved my problem, it has nothing to do with this problem, sorry but they sounded so similar and I could no find a reasonable explanation to my problem, thats why i tuned in here...
My problem was not ServerName which resolves fine in DNS (it's a public domain), but my local hostname (which differs from ServerName) that did not resolve through DNS. I don't know why Apache requires the local hostname to resolve when it is given an explicit ServerName...?
But addind a 127.0.0.1 local_hostname to /etc/hosts resolved my issue.
Comment 12 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2004-03-16 00:16:21 UTC
apache tries to find the IP for the local host
so that it can figure out what interface to listen on.
Comment 13 Christian Aust 2004-03-16 01:02:43 UTC
All that is true, but the apache conf used on my system has been working for months, and it still does if not started with the init.d scripts.
Comment 14 Christian Aust 2004-03-30 22:36:30 UTC
The runscript.sh (1.29) silently failes on line 233 ff., I've added som eerror statement:

                # Do not try to start if i have done so already on runlevel change
                if is_runlevel_start && service_failed "${myservice}"
                then
                        eerror "Previously failed to start ${myservice}"
                        exit 1
                fi

I can't find the definition of is_runlevel_start or service_failed(). Could this be a fragment of a previous crash of apache2? Where would I search for more information? Regards, Christian
Comment 15 Corey Betka 2004-04-04 11:49:38 UTC
Did you clean up the symlinks in /etc/apache2/? (lib logs modules extramodules)

This error went away for me after I did.
Comment 16 Christian Aust 2004-04-04 13:17:20 UTC
I guess the symlinks in /etc/apache2 are all right:

christian@p15140448 christian $ ls -la /etc/apache2 
insgesamt 12
drwxr-xr-x    4 root     root          240 26. M
Comment 17 Christian Aust 2004-04-04 13:17:20 UTC
I guess the symlinks in /etc/apache2 are all right:

christian@p15140448 christian $ ls -la /etc/apache2 
insgesamt 12
drwxr-xr-x    4 root     root          240 26. Mär 07:08 .
drwxr-xr-x   56 root     root         4216  3. Apr 15:34 ..
-rw-r--r--    1 root     root         2211 26. Mär 07:00 apache2-builtin-mods
drwxr-xr-x    5 root     root          456 26. Mär 07:02 conf
lrwxrwxrwx    1 root     root           34 24. Feb 16:19 extramodules -> ../../usr/lib/apache2-extramodules
lrwxrwxrwx    1 root     root           13 24. Feb 16:19 lib -> ../../usr/lib
lrwxrwxrwx    1 root     root           21 24. Feb 16:19 logs -> ../../var/log/apache2
lrwxrwxrwx    1 root     root           24 26. Mär 07:08 modules -> /usr/lib/apache2/modules
drwxr-xr-x    2 root     root           80 24. Nov 02:43 passwd

Again, this is not exactly an apache2 error, it's just that the script refused to do anything because it assumes that it already has been started. I've added an echo statement as the very first line of the start() method, and no output comes out. Please see comment #14 for details.
Comment 18 Stuart Herbert (RETIRED) gentoo-dev 2004-04-05 14:35:24 UTC
You can find more information about the is_runlevel_start and service_failed() functions by reading the files that are included at the top of the init.d script.

It's always worth adding '-x' to the #! line at the top of the script, to see what's going on, if you suspect a bug in the init script itself.

Best regards,
Stu
Comment 19 Christian Aust 2004-04-05 23:08:24 UTC
Adding -x to the top line of /sbin/runscript.sh gives me the debug information I've been asking for for more than 3 weeks now. The error is in the /etc/init.d/apache2 script, where SERVERROOT has been misplaced by STARTUPERRORLOG on lines 8 and 23. Please fix that in portage.

I'm still not shure why the error message from line 27 of the very same script didn't show up initially.
Comment 20 Stuart Herbert (RETIRED) gentoo-dev 2004-04-08 12:50:03 UTC
Hi,

Please don't mark bugs as RESOLVED FIXED until we've committed the changes to CVS.  They don't show up in my bugzilla filter once they're closed.

I've committed the fix to CVS; it should be showing up on an rsync mirror near you in about an hour.

Thanks for finding this,
Stu