Centos – httpd service will not start on boot under CentOS 6

centoshttpdstartupvagrant

I am having trouble configuring a CentOS 6 Vagrant setup to start the Apache service on boot. I have tried using chkconfig and the OS seems to just ignore it.

When I run sudo chkconfig --list httpd, I get

httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

Which I assume was the result of running the commands

sudo chkconfig httpd on
sudo chkconfig --levels 235 httpd on
sudo chkconfig --levels 345 httpd on

in different attempts to configure this thing correctly in my provisioning script. I am not using Puppet or Chef, nor do I really want to. I had this working on a different host machine, but on the second host it seems to have stopped working for some reason.

Manually starting the service with sudo service httpd start works fine, but as soon as I do a vagrant halt && vagrant up or vagrant reload the service will not start when the VM comes back up.

Frustratingly, the mysqld service, which I have configured in exactly the same way, comes up on startup perfectly fine.

My /var/log/httpd/error_log says this:

[Thu Apr 17 09:31:09 2014] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Apr 17 09:31:09 2014] [notice] Digest: generating secret for digest authentication ...
[Thu Apr 17 09:31:09 2014] [notice] Digest: done
[Thu Apr 17 09:31:09 2014] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.5.11 configured -- resuming normal operations
[Thu Apr 17 09:34:45 2014] [notice] caught SIGTERM, shutting down

Best Answer

The problem turned out to be that the VM was trying to start the Apache service before Vagrant had mounted the shared folders, and the httpd DocumentRoot was pointing to a non existent directory. I followed these instructions to set up a udev event to wait until the mount occurred before attempting to start httpd.

http://razius.com/articles/launching-services-after-vagrant-mount/