Browse code

Fix Apache site config handling on Fedora

Allow enable/disable_apache_sites() on Fedora to gracefully fail if the
config is not present. This is primarily an issue when the config from
a previous run is not completely cleaned out (unstack.sh vs clean.sh).

Make APACHE_CONFIG_DIR fully qualified and overrideable in local.conf.

Also fix Horizon's handling of its Apache config file to be removed
in clean.sh.

Change-Id: I78a5de579dd3b02fa2e4e7e00ac0aabe71b531ad

Dean Troyer authored on 2014/06/07 06:36:52
Showing 2 changed files
... ...
@@ -31,13 +31,13 @@ APACHE_GROUP=${APACHE_GROUP:-$(id -gn $APACHE_USER)}
31 31
 # Set up apache name and configuration directory
32 32
 if is_ubuntu; then
33 33
     APACHE_NAME=apache2
34
-    APACHE_CONF_DIR=sites-available
34
+    APACHE_CONF_DIR=${APACHE_CONF_DIR:-/etc/$APACHE_NAME/sites-available}
35 35
 elif is_fedora; then
36 36
     APACHE_NAME=httpd
37
-    APACHE_CONF_DIR=conf.d
37
+    APACHE_CONF_DIR=${APACHE_CONF_DIR:-/etc/$APACHE_NAME/conf.d}
38 38
 elif is_suse; then
39 39
     APACHE_NAME=apache2
40
-    APACHE_CONF_DIR=vhosts.d
40
+    APACHE_CONF_DIR=${APACHE_CONF_DIR:-/etc/$APACHE_NAME/vhosts.d}
41 41
 fi
42 42
 
43 43
 # Functions
... ...
@@ -108,14 +108,14 @@ function apache_site_config_for {
108 108
         local apache_version=$(sudo /usr/sbin/apache2ctl -v | awk '/Server version/ {print $3}' | cut -f2 -d/)
109 109
         if [[ "$apache_version" =~ ^2\.2\. ]]; then
110 110
             # Ubuntu 12.04 - Apache 2.2
111
-            echo /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}
111
+            echo $APACHE_CONF_DIR/${site}
112 112
         else
113 113
             # Ubuntu 14.04 - Apache 2.4
114
-            echo /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf
114
+            echo $APACHE_CONF_DIR/${site}.conf
115 115
         fi
116 116
     elif is_fedora; then
117 117
         # fedora conf.d is only imported if it ends with .conf so this is approx the same
118
-        local enabled_site_file="/etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf"
118
+        local enabled_site_file="$APACHE_CONF_DIR/${site}.conf"
119 119
         if [ -f $enabled_site_file ]; then
120 120
             echo ${enabled_site_file}
121 121
         else
... ...
@@ -130,8 +130,11 @@ function enable_apache_site {
130 130
     if is_ubuntu; then
131 131
         sudo a2ensite ${site}
132 132
     elif is_fedora; then
133
-        # fedora conf.d is only imported if it ends with .conf so this is approx the same
134
-        sudo mv /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf.disabled /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf
133
+        local enabled_site_file="$APACHE_CONF_DIR/${site}.conf"
134
+        # Do nothing if site already enabled or no site config exists
135
+        if [[ -f ${enabled_site_file}.disabled ]] && [[ ! -f ${enabled_site_file} ]]; then
136
+            sudo mv ${enabled_site_file}.disabled ${enabled_site_file}
137
+        fi
135 138
     fi
136 139
 }
137 140
 
... ...
@@ -141,7 +144,11 @@ function disable_apache_site {
141 141
     if is_ubuntu; then
142 142
         sudo a2dissite ${site}
143 143
     elif is_fedora; then
144
-        sudo mv /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf /etc/$APACHE_NAME/$APACHE_CONF_DIR/${site}.conf.disabled
144
+        local enabled_site_file="$APACHE_CONF_DIR/${site}.conf"
145
+        # Do nothing if no site config exists
146
+        if [[ -f ${enabled_site_file} ]]; then
147
+            sudo mv ${enabled_site_file} ${enabled_site_file}.disabled
148
+        fi
145 149
     fi
146 150
 }
147 151
 
... ...
@@ -75,6 +75,9 @@ function cleanup_horizon {
75 75
             sudo rm /usr/bin/node
76 76
         fi
77 77
     fi
78
+
79
+    local horizon_conf=$(apache_site_config_for horizon)
80
+    sudo rm -f $horizon_conf
78 81
 }
79 82
 
80 83
 # configure_horizon() - Set config files, create data dirs, etc