在 Mac OS X Server 10.6 上启动时启动 Apache 2

在 Mac OS X Server 10.6 上启动时启动 Apache 2

在 Mac OS X Server 10.6 上编译、安装和配置 Apache 2.2.15 后,一切顺利。手动启动时服务器运行良好,没有配置问题。

然后我添加了一个 launchd 系统范围守护程序(位于 /Library/LaunchDaemons/ 中),加载它并重新启动。这似乎再次正常工作。

但是我猜是因为 mod_unique_id 的问题,Apache 无法在启动时启动。以下是 apache 错误日志条目:

[Tue Jun 29 09:01:29 2010] [alert] (EAI 8)nodename nor servname provided, or not known: mod_unique_id: unable to find IPv4 address of "my.server.net" Configuration Failed

在我看来,launchd 在启动过程中过早地触发了该作业,此时反向 DNS 查找尚未完成或正确传播。如果我通过 ssh 手动启动 Apache,它会启动而不会出现错误。(服务器有一个静态 IP,并设置了完全合格的域名。)

以下是我的 system.log 中的几行:

Jun 29 09:01:29 org.apache.httpd[88]: httpd: apr_sockaddr_info_get() failed for my.server.com
Jun 29 09:01:29 org.apache.httpd[88]: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Jun 29 09:01:29 emond[78]: SetUpLogs: uid = 0 gid = 0
Jun 29 09:01:29 emond[78]: SetUpLogs: opening /Library/Logs/EventMonitor/EventMonitor.error.log
Jun 29 09:01:29 sandboxd[100]: kadmind(54) deny network-bind 0.0.0.0:654
Jun 29 09:01:29 sandboxd[100]: kadmind(54) deny network-bind 0.0.0.0:0
Jun 29 09:01:30 loginwindow: Login Window Application Started
Jun 29 09:01:30 com.apple.launchd (org.apache.httpd): Exited with exit code: 1
Jun 29 09:01:30 configd: network configuration changed.

这里的日志非常清楚,Apache 启动后在网络配置有效 IP 和 DNS 名称之前无法启动。但这并不一致,在另一次启动中,先完成网络配置,但问题仍然存在。

我尝试将 httpd.conf 中的变量设置ServerName为服务器的 IP 或 FQDN,但没有帮助。

我有点迷茫,所以我来这里了。网上搜索了很多,也没找到答案。

我错过了什么?

答案1

你可以通过添加如下内容来告诉 launchd 在守护进程崩溃时重新启动它:

<key>KeepAlive</key>
<true/>

到 launchd .plist 文件。注意:确保您使用-D FOREGROUND选项运行 httpd,以便 launchd 可以正确跟踪其状态,即您应该像这样运行它:

<key>ProgramArguments</key>
<array>
    <string>/path/to/httpd</string>
    <string>-D</string>
    <string>FOREGROUND</string>
</array>

此外,您可能希望将项目的标签(和文件名)更改为 org.apache.httpd 以外的其他名称;/System/Library/LaunchDaemons 中已经有一个该标签的守护进程,我不确定是否存在标签冲突的可能性。

相关内容