Apache跨平台重啟

Apache跨平台重啟

我想要一個可以在任何 *nix 作業系統上重新啟動 Apache 的命令。目前我正在使用 Ubuntu,它有

  • /usr/sbin/apache2ctl
  • /usr/sbin/service
  • apachectl
  • httpd

和 Scientific Linux CERN 5,它具有

  • /usr/sbin/apachectl
  • /etc/init.d/httpd
  • apache2ctl
  • service

我想避免使用像這樣的黑客which service 2>/dev/null || which /etc/init.d/httpd

答案1

apachectl / apache2ctl 是 apache 內建的用於控制 apache 的工具,它可能是在您的情況下使用的正確工具,因為它隨 apache 一起提供,它將是所有作業系統上的工具。
apachectl 通常適用於 Apache 1.x,apache2ctl 通常適用於 Apache 2.x。
如果 SLC5 附帶 Apache 2.x,那會很奇怪,但您可以在腳本中同時執行 apachectl 和 apache2ctl。

答案2

您可以使用腳本來檢查安裝了哪個 apachectl,然後執行相應的腳本。

#!/bin/bash

if [ -e /usr/sbin/apacche2ctl ]
then
    /usr/sbin/apache2ctl restart
elif [ -e /usr/sbin/apachectl ]
then
    /usr/sbin/apachectl restart
else
    echo "No Apache control program found"
fi

相關內容