From a688bc65104e7d8998ffdb321d67a9f33df6997e Mon Sep 17 00:00:00 2001 From: Gabriel Assis Bezerra Date: Tue, 27 May 2014 20:58:22 +0000 Subject: [PATCH] Fix the way Apache site configuration files are used, to improve OS portability On Ubuntu 14.04, the site configuration file must have a .conf suffix for a2ensite and a2dissite to recognise it. a2ensite and a2dissite ignore the .conf suffix used as parameter. The default sites' files are 000-default.conf and default-ssl.conf. On Ubuntu 12.04, the site configuration file may have any format, as long as it is in /etc/apache2/sites-available/. a2ensite and a2dissite need the entire file name to work. The default sites' files are default and default-ssl. On Fedora, any file in /etc/httpd/conf.d/ whose name ends with .conf is enabled. On RHEL and CentOS, things should hopefully work as in Fedora. This change puts all distribution-related site configuration file name differences in lib/apache and the other services gets the file name for its sites using the new exported function apache_site_config_for . It also makes Fedora disabled sites use the .conf.disabled suffix instead of removing the .conf from the file name. The table below summarizes what should happen on each distribution: +----------------------+--------------------+--------------------------+--------------------------+ | Distribution | File name | Site enabling command | Site disabling command | +----------------------+--------------------+--------------------------+--------------------------+ | Ubuntu 12.04 | site | a2ensite site | a2dissite site | | Ubuntu 14.04 | site.conf | a2ensite site | a2dissite site | | Fedora, RHEL, CentOS | site.conf.disabled | mv site.conf{.disabled,} | mv site.conf{,.disabled} | +----------------------+--------------------+--------------------------+--------------------------+ Change-Id: Ia2ba3cb7caccb6e9b65380f9d51d9d21180b894e Closes-bug: #1313765 --- lib/apache | 50 ++++++++++++++++++++++++++++++++++-- lib/horizon | 4 +-- lib/keystone | 9 ++++--- lib/neutron_thirdparty/trema | 8 +++--- lib/swift | 19 +++++++------- 5 files changed, 69 insertions(+), 21 deletions(-) diff --git a/lib/apache b/lib/apache index 2d5e39a65d..55083e73e5 100644 --- a/lib/apache +++ b/lib/apache @@ -11,6 +11,7 @@ # - is_apache_enabled_service # - install_apache_wsgi # - config_apache_wsgi +# - apache_site_config_for # - enable_apache_site # - disable_apache_site # - start_apache_server @@ -78,6 +79,51 @@ function install_apache_wsgi { fi } +# apache_site_config_for() - The filename of the site's configuration file. +# This function uses the global variables APACHE_NAME and APACHE_CONF_DIR. +# +# On Ubuntu 14.04, the site configuration file must have a .conf suffix for a2ensite and a2dissite to +# recognise it. a2ensite and a2dissite ignore the .conf suffix used as parameter. The default sites' +# files are 000-default.conf and default-ssl.conf. +# +# On Ubuntu 12.04, the site configuration file may have any format, as long as it is in +# /etc/apache2/sites-available/. a2ensite and a2dissite need the entire file name to work. The default +# sites' files are default and default-ssl. +# +# On Fedora, any file in /etc/httpd/conf.d/ whose name ends with .conf is enabled. +# +# On RHEL and CentOS, things should hopefully work as in Fedora. +# +# The table below summarizes what should happen on each distribution: +# +----------------------+--------------------+--------------------------+--------------------------+ +# | Distribution | File name | Site enabling command | Site disabling command | +# +----------------------+--------------------+--------------------------+--------------------------+ +# | Ubuntu 12.04 | site | a2ensite site | a2dissite site | +# | Ubuntu 14.04 | site.conf | a2ensite site | a2dissite site | +# | Fedora, RHEL, CentOS | site.conf.disabled | mv site.conf{.disabled,} | mv site.conf{,.disabled} | +# +----------------------+--------------------+--------------------------+--------------------------+ +function apache_site_config_for { + local site=$@ + if is_ubuntu; then + local apache_version=$(sudo /usr/sbin/apache2ctl -v | awk '/Server version/ {print $3}' | cut -f2 -d/) + if [[ "$apache_version" =~ ^2\.2\. ]]; then + # Ubuntu 12.04 - Apache 2.2 + echo /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site} + else + # Ubuntu 14.04 - Apache 2.4 + echo /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf + fi + elif is_fedora; then + # fedora conf.d is only imported if it ends with .conf so this is approx the same + local enabled_site_file="/etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf" + if [ -f $enabled_site_file ]; then + echo ${enabled_site_file} + else + echo ${enabled_site_file}.disabled + fi + fi +} + # enable_apache_site() - Enable a particular apache site function enable_apache_site { local site=$@ @@ -85,7 +131,7 @@ function enable_apache_site { sudo a2ensite ${site} elif is_fedora; then # fedora conf.d is only imported if it ends with .conf so this is approx the same - sudo mv /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site} /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf + sudo mv /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf.disabled /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf fi } @@ -95,7 +141,7 @@ function disable_apache_site { if is_ubuntu; then sudo a2dissite ${site} elif is_fedora; then - sudo mv /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site} + sudo mv /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf.disabled fi } diff --git a/lib/horizon b/lib/horizon index 9ce485317c..9e4f2f95c8 100644 --- a/lib/horizon +++ b/lib/horizon @@ -122,11 +122,11 @@ function init_horizon { HORIZON_REQUIRE='Require all granted' fi - local horizon_conf=/etc/$APACHE_NAME/$APACHE_CONF_DIR/horizon.conf + local horizon_conf=$(apache_site_config_for horizon) if is_ubuntu; then disable_apache_site 000-default sudo touch $horizon_conf - enable_apache_site horizon.conf + enable_apache_site horizon elif is_fedora; then sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf elif is_suse; then diff --git a/lib/keystone b/lib/keystone index f8e92f4449..c4266b9c01 100644 --- a/lib/keystone +++ b/lib/keystone @@ -87,6 +87,9 @@ if is_ssl_enabled_service "key"; then KEYSTONE_SERVICE_PROTOCOL="https" fi +# Apache configuration file for keystone +KEYSTONE_APACHE_CONF_FILE=$(apache_site_config_for keystone) + # Functions # --------- @@ -103,7 +106,7 @@ function cleanup_keystone { function _cleanup_keystone_apache_wsgi { sudo rm -f $KEYSTONE_WSGI_DIR/*.wsgi disable_apache_site keystone - sudo rm -f /etc/$APACHE_NAME/$APACHE_CONF_DIR/keystone + sudo rm -f $KEYSTONE_APACHE_CONF_FILE } # _config_keystone_apache_wsgi() - Set WSGI config files of Keystone @@ -114,7 +117,7 @@ function _config_keystone_apache_wsgi { sudo cp $KEYSTONE_DIR/httpd/keystone.py $KEYSTONE_WSGI_DIR/main sudo cp $KEYSTONE_DIR/httpd/keystone.py $KEYSTONE_WSGI_DIR/admin - sudo cp $FILES/apache-keystone.template /etc/$APACHE_NAME/$APACHE_CONF_DIR/keystone + sudo cp $FILES/apache-keystone.template $KEYSTONE_APACHE_CONF_FILE sudo sed -e " s|%PUBLICPORT%|$KEYSTONE_SERVICE_PORT|g; s|%ADMINPORT%|$KEYSTONE_AUTH_PORT|g; @@ -122,7 +125,7 @@ function _config_keystone_apache_wsgi { s|%PUBLICWSGI%|$KEYSTONE_WSGI_DIR/main|g; s|%ADMINWSGI%|$KEYSTONE_WSGI_DIR/admin|g; s|%USER%|$STACK_USER|g - " -i /etc/$APACHE_NAME/$APACHE_CONF_DIR/keystone + " -i $KEYSTONE_APACHE_CONF_FILE enable_apache_site keystone } diff --git a/lib/neutron_thirdparty/trema b/lib/neutron_thirdparty/trema index f829aa82ff..3e59ef2b28 100644 --- a/lib/neutron_thirdparty/trema +++ b/lib/neutron_thirdparty/trema @@ -28,7 +28,7 @@ TREMA_TMP_DIR=$TREMA_DATA_DIR/trema TREMA_LOG_LEVEL=${TREMA_LOG_LEVEL:-info} TREMA_SS_CONFIG=$TREMA_SS_ETC_DIR/sliceable.conf -TREMA_SS_APACHE_CONFIG=/etc/apache2/sites-available/sliceable_switch.conf +TREMA_SS_APACHE_CONFIG=$(apache_site_config_for sliceable_switch) # configure_trema - Set config files, create data dirs, etc function configure_trema { @@ -61,8 +61,9 @@ function init_trema { sudo cp $TREMA_SS_DIR/apache/sliceable_switch $TREMA_SS_APACHE_CONFIG sudo sed -i -e "s|/home/sliceable_switch/script|$TREMA_SS_SCRIPT_DIR|" \ $TREMA_SS_APACHE_CONFIG + # TODO(gabriel-bezerra): use some function from lib/apache to enable these modules sudo a2enmod rewrite actions - sudo a2ensite sliceable_switch.conf + enable_apache_site sliceable_switch cp $TREMA_SS_DIR/sliceable_switch_null.conf $TREMA_SS_CONFIG sed -i -e "s|^\$apps_dir.*$|\$apps_dir = \"$TREMA_DIR/apps\"|" \ @@ -98,8 +99,7 @@ function install_trema { } function start_trema { - # APACHE_NAME is defined in init_horizon (in lib/horizon) - restart_service $APACHE_NAME + restart_apache_server sudo LOGGING_LEVEL=$TREMA_LOG_LEVEL TREMA_TMP=$TREMA_TMP_DIR \ trema run -d -c $TREMA_SS_CONFIG diff --git a/lib/swift b/lib/swift index 1e24c2cbb8..c47b09f6d7 100644 --- a/lib/swift +++ b/lib/swift @@ -152,7 +152,7 @@ function _cleanup_swift_apache_wsgi { for type in object container account; do site_name=${type}-server-${node_number} disable_apache_site ${site_name} - sudo rm -f /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site_name} + sudo rm -f $(apache_site_config_for ${site_name}) done done } @@ -160,18 +160,17 @@ function _cleanup_swift_apache_wsgi { # _config_swift_apache_wsgi() - Set WSGI config files of Swift function _config_swift_apache_wsgi { sudo mkdir -p ${SWIFT_APACHE_WSGI_DIR} - local apache_vhost_dir=/etc/${APACHE_NAME}/$APACHE_CONF_DIR local proxy_port=${SWIFT_DEFAULT_BIND_PORT:-8080} # copy proxy vhost and wsgi file - sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template ${apache_vhost_dir}/proxy-server + sudo cp ${SWIFT_DIR}/examples/apache2/proxy-server.template $(apache_site_config_for proxy-server) sudo sed -e " /^#/d;/^$/d; s/%PORT%/$proxy_port/g; s/%SERVICENAME%/proxy-server/g; s/%APACHE_NAME%/${APACHE_NAME}/g; s/%USER%/${STACK_USER}/g; - " -i ${apache_vhost_dir}/proxy-server + " -i $(apache_site_config_for proxy-server) enable_apache_site proxy-server sudo cp ${SWIFT_DIR}/examples/wsgi/proxy-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/proxy-server.wsgi @@ -186,13 +185,13 @@ function _config_swift_apache_wsgi { container_port=$[CONTAINER_PORT_BASE + 10 * ($node_number - 1)] account_port=$[ACCOUNT_PORT_BASE + 10 * ($node_number - 1)] - sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template ${apache_vhost_dir}/object-server-${node_number} + sudo cp ${SWIFT_DIR}/examples/apache2/object-server.template $(apache_site_config_for object-server-${node_number}) sudo sed -e " s/%PORT%/$object_port/g; s/%SERVICENAME%/object-server-${node_number}/g; s/%APACHE_NAME%/${APACHE_NAME}/g; s/%USER%/${STACK_USER}/g; - " -i ${apache_vhost_dir}/object-server-${node_number} + " -i $(apache_site_config_for object-server-${node_number}) enable_apache_site object-server-${node_number} sudo cp ${SWIFT_DIR}/examples/wsgi/object-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi @@ -201,14 +200,14 @@ function _config_swift_apache_wsgi { s/%SERVICECONF%/object-server\/${node_number}.conf/g; " -i ${SWIFT_APACHE_WSGI_DIR}/object-server-${node_number}.wsgi - sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template ${apache_vhost_dir}/container-server-${node_number} + sudo cp ${SWIFT_DIR}/examples/apache2/container-server.template $(apache_site_config_for container-server-${node_number}) sudo sed -e " /^#/d;/^$/d; s/%PORT%/$container_port/g; s/%SERVICENAME%/container-server-${node_number}/g; s/%APACHE_NAME%/${APACHE_NAME}/g; s/%USER%/${STACK_USER}/g; - " -i ${apache_vhost_dir}/container-server-${node_number} + " -i $(apache_site_config_for container-server-${node_number}) enable_apache_site container-server-${node_number} sudo cp ${SWIFT_DIR}/examples/wsgi/container-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi @@ -217,14 +216,14 @@ function _config_swift_apache_wsgi { s/%SERVICECONF%/container-server\/${node_number}.conf/g; " -i ${SWIFT_APACHE_WSGI_DIR}/container-server-${node_number}.wsgi - sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template ${apache_vhost_dir}/account-server-${node_number} + sudo cp ${SWIFT_DIR}/examples/apache2/account-server.template $(apache_site_config_for account-server-${node_number}) sudo sed -e " /^#/d;/^$/d; s/%PORT%/$account_port/g; s/%SERVICENAME%/account-server-${node_number}/g; s/%APACHE_NAME%/${APACHE_NAME}/g; s/%USER%/${STACK_USER}/g; - " -i ${apache_vhost_dir}/account-server-${node_number} + " -i $(apache_site_config_for account-server-${node_number}) enable_apache_site account-server-${node_number} sudo cp ${SWIFT_DIR}/examples/wsgi/account-server.wsgi.template ${SWIFT_APACHE_WSGI_DIR}/account-server-${node_number}.wsgi