3

我最近将我的 Mac 操作系统从 Lion 升级到了 Lion Server,这改变了在 Apache 启动时读取 httpd.conf 设置的方式。特别是,WEBSHARING_ON 和 MACOSXSERVER 等环境变量由 Server.app 进程设置,以便在启动 Apache 时读取额外的模块和文件。

所以现在,要重新启动 Apache 服务器并加载所有正确的设置和模块,我必须使用以下命令:-

sudo serveradmin stop web && sudo serveradmin start web

以前,我会跑:-

sudo apachectl -S
sudo apachectl graceful

到目前为止,我更喜欢后一种方法。一方面,命令返回得更快,而且我还想象 apache / httpd 服务器进程并没有完全终止,只是重新加载了设置。

那么,有没有办法在 Lion Server 中优雅地重启 Apache?

4

1 回答 1

2

快速回答是否定的。
'apachectl' 程序实际上只是一个 shell 脚本,所以(在意识到这一点之后)很容易看到它在做什么,以及为什么它没有按照我的预期做。

在 Mac 上重新启动 Apache(优雅地或以其他方式)时,相关的 launchctl 作业只是卸载并重新加载,我想这与Apache 对优雅重启的官方描述不同:

USR1 或优雅信号导致父进程建议子进程在当前请求后退出(或者如果他们没有提供任何服务则立即退出)

没有显示配置的虚拟服务器的原因apachectl -S是因为该命令不是由launchctl运行的,因此没有加载/System/Library/LaunchDaemons/org.apache.httpd.plist中设置的环境变量。

因此,apachectl gracefulapachectl restart其他人确实加载了正确的变量,因此可以正确读取配置文件,但并非所有命令都默认执行。

为了克服这个问题,我手动编辑了 /usr/sbin/apachectl,如下所示。我所做的只是在适当的地方添加“-D MACOSXSERVER -D WEBSERVICE_ON”。

case $ARGV in
start)
    run_launchctl load -w $LAUNCHD_JOB
    ERROR=$?
    ;;
stop|graceful-stop)
    run_launchctl unload -w $LAUNCHD_JOB
    ERROR=$?
    ;;
restart|graceful)
    run_launchctl unload -w $LAUNCHD_JOB 2> /dev/null
    run_launchctl load -w $LAUNCHD_JOB
    ERROR=$?
    ;;
startssl|sslstart|start-SSL)
    echo The startssl option is no longer supported.
    echo Please edit httpd.conf to include the SSL configuration settings
    echo and then use "apachectl start".
    ERROR=2
    ;;
configtest)
    $HTTPD -t -D MACOSXSERVER -D WEBSERVICE_ON
    ERROR=$?
    ;;
status|fullstatus)
    echo Go to $STATUSURL in the web browser of your choice.
    echo Note that mod_status must be enabled for this to work.
    ;;
*)
    $HTTPD $ARGV -D MACOSXSERVER -D WEBSERVICE_ON
    ERROR=$?
esac
于 2012-07-16T14:03:44.397 回答