MacPorts Apache2 Stopped Launching on Boot

北城余情 提交于 2019-12-04 04:50:23

I found my answer to this problem here:

https://trac.macports.org/ticket/36101

"I apparently fixed this when changing my local dnsmasq config. In /etc/hosts I added my servername (gala) to the loopback entry:

127.0.0.1 localhost gala

and then I changed ServerName in /opt/local/apache2/conf/httpd.conf to match:

ServerName gala

Apache now starts at boot for me."

Rob Wilkerson

Since I now know why Apache has stopped loading on startup, I'm going to articulate that answer and mark this question as answered. The reason Apache has stopped launching on boot is that I'm trying to share an httpd.conf file across systems. The config file needs to Include files from directories that exist within my home directory. Since the home directory is different on each machine, I was trying to reference the ${HOME} environment variable.

This works fine when manually starting after the machine is booted, but fails on startup because the environment variable isn't yet set. As mentioned above, see this question for more information.

Rob:

  1. Had the same problem: "sudo launchctl load -w ..." started Apache2 while I was logged in, but did not work during startup (the "-w" should have taken care of that). Also, as you noticed, the daemon seems to be registered with launchctl. It will show up with "sudo launchctl list" and another "sudo launchctl load ..." will result in the error message.

  2. I played with "sudo port load apache2" and "sudo port unload apache2", but could not get httpd running on reboot.

  3. In the end, I got rid of the MacPorts startup item: "sudo port unload apache2", checked with "sudo launchctl list" that org.macports.apache2 is no longer registered for startup.

  4. Afterwards, I followed the steps on http://diymacserver.com > Docs > Tiger > Starting Apache. I only had to adapt the path from /usr/local/... to /opt/local/...

Now the MacPorts Apache2 is starting fine with every reboot.

Good luck, Klaus

I found that my MacPorts apache2 was not starting on boot because of an “error” in my httpd.conf.

I was using

Listen 127.0.0.1:80
Listen 192.168.2.1:80
Listen 123.123.123.123:80 # Example IP, not the one I was really using

And in Console.app I was seeing

4/8/12 4:59:06.208 PM org.macports.apache2: (49)Can't assign requested address: make_sock: could not bind to address 192.168.2.1:80
4/8/12 4:59:06.208 PM org.macports.apache2: no listening sockets available, shutting down
4/8/12 4:59:06.208 PM org.macports.apache2: Unable to open logs

I tried adjusting permissions on all the log folders (despite the fact that logs were being written just fine when I manually started apache2) and that didn't help.

Even though the Apache Documentation for Listen clearly states

Multiple Listen directives may be used to specify a number of addresses and ports to listen to. The server will respond to requests from any of the listed addresses and ports.

I decided to try switching back to just using

Listen 80

And after doing so apache2 is starting on boot with no errors or warnings.

If you're using Subversion with Apache, you may find that Apache is not starting because the mod_dav_svn.so file has moved to /opt/local/libexec. You'll need to adjust your Apache startup files to account for the new location of this file.

In newer versions of MacPorts you can run sudo port load apache2 to instruct MacPorts to take care of the launchctl setup and automatically start the process. To stop the process run port unload.

After loading check /opt/local/apache2/logs/error_log for errors, including configuration issues.

JCobb

In addition to my previous answer I have also found that sometimes Apache fails to start because something else with the system is not yet ready.

On one OS X Server machine I also use the DNS to create a “internal only” DNS name for the machine and that name is used in my Apache configuration. Sometimes when Apache tries to start the DNS server is not yet ready and Apache fails to load because the hostname isn’t valid.

I have also seen this on other non-Server systems without local DNS as well where something else required by Apache must not be ready yet.

One thing that has worked is to edit the apache2.wrapper located at /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper that MacPorts’ daemondo uses to start up Apache.

Edit the Start() function to add a sleep command to wait a bit before launching Apache.

Original (Lines 14-17 on my machine)

Start()
{
    [ -x /opt/local/apache2/bin/apachectl ] && /opt/local/apache2/bin/apachectl start > /dev/null
}

With wait time added

Start()
{
    [ -x /opt/local/apache2/bin/apachectl ] && sleep 10 && /opt/local/apache2/bin/apachectl start > /dev/null
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!