apache2 not starting at boot. Even if set up in runlevels

5,384

Found the problem:

In short: my web page tried to connect to MySQL, but MySQL wasn't running at this time. Thus apache failed to start.

I changed the following line in /etc/init.d/apache2 to log startup problem to syslog:

if $APACHE2CTL start; then

to

if $APACHE2CTL  -k start -e Debug 2>&1 | logger -t "apache_start"; then

After booting check your /var/log/syslog for entries starting with apache_start.

The next problem: how can I force apache to start after mysql. See here: Force apache start after mysql


Additional info: I use Perl Catalyst Framework.

Here is the error output from apache init script:

DBI connect('database:localhost:3306','User',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at /usr/local/share/perl/5.10.1/Catalyst/Plugin/I18N/DBI.pm line 196.
Syntax error on line 10 of /etc/apache2/sites-available/mysite:
Can't call method "disconnect" on an undefined value at /usr/local/share/perl/5.10.1/Catalyst/Plugin/I18N/DBI.pm line 263, <DATA> line 998.\nCompilation failed in require at (eval 4) line 3, <DATA>  line 998.\n

I think the Syntax error is caused by the previous error. Because line 10 is:

PerlModule CatalystPageName

and works fine if mysql running.

I didn't found out yet why the localization module connects at startup. We have other webpages with same module which don't have this problem/connect at startup. Since it can't connect a following disconnect causes an exception in Perl which aborts the apache2crl start command. (That's what I guess)

Share:
5,384
Stefan Profanter
Author by

Stefan Profanter

Updated on September 18, 2022

Comments

  • Stefan Profanter
    Stefan Profanter over 1 year

    On my Ubuntu 10.04.4 server apache2 2.2.14 is installed. A few months ago starting apache2 at boot worked fine.

    Now I've found out that after a reboot apache2 doesn't start automatically anymore.

    The init.d script is present and should be the one from the default installation:

    root@ser:~# ls /etc/init.d | grep apache
    apache2
    

    the runlevel startups are also set (using update-rc.d apache2 defaults):

    root@ser:~# find /etc/rc* -name *apache*
    /etc/rc0.d/K20apache2
    /etc/rc1.d/K20apache2
    /etc/rc2.d/S20apache2
    /etc/rc3.d/S20apache2
    /etc/rc4.d/S20apache2
    /etc/rc5.d/S20apache2
    /etc/rc6.d/K20apache2
    

    Checking the status after reboot results in:

    root@ser:~# service apache2 status
    Apache is NOT running.
    

    ps aux | grep apache is also empty.

    Looking into /var/log/apache/error.log there are no entries at boot time. cat /var/log/syslog | grep apache is also empty and syslog doesn't contain any suspiscious entries.

    Starting apache after boot manually with service apache2 start works fine and doesn't output any errors.

    Update 1: The /etc/init.d/apache2 script has the following header/requirements:

    ### BEGIN INIT INFO
    # Provides:          apache2
    # Required-Start:    $local_fs $remote_fs $network $syslog
    # Required-Stop:     $local_fs $remote_fs $network $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # X-Interactive:     true
    # Short-Description: Start/stop apache2 web server
    ### END INIT INFO
    

    And the services being started are:

    root@ser:~# ls /etc/rc2.d/
    README           S10sysklogd  S20apache2 S20denyhosts  S20hashcash-milter  S20ido2db     S20modules_dep.sh  S20postfix  S20saslauthd  S20vzquota  S50rsync     S99rc.local
    S09hostname_vps  S15bind9     S20exim4      S20icinga           S20memcached  S20opendkim        S20psad     S20xinetd   S23ntp      S99ondemand
    

    How can I find out why apache2 isn't getting started at boot?

    • Stefan Profanter
      Stefan Profanter almost 11 years
      I found already the following related questions: serverfault.com/questions/472145/… and serverfault.com/questions/77164/…. Here the problem was that the runlevel scripts didn't were set up as 'S' scripts.
    • Isaac
      Isaac almost 11 years
      check the apache2 init skript: what does it list in "Required-Start:"? Are all required services started? Maybe it does not start because there is a problem elsewhere. You could also edit the init script and add debugging output to see if it gets called at all.
    • Stefan Profanter
      Stefan Profanter almost 11 years
      Added the required-start info in the post. How can I check if some of the Required services didn't start and thus apache failed to start? Is there somewhere a log entry?