|
| 1 | +config_httpd_conf() { |
| 2 | + sed -i "s/^Listen 80/Listen 0.0.0.0:8080/" ${HTTPD_MAIN_CONF_PATH}/httpd.conf |
| 3 | + sed -i "s/^User apache/User default/" ${HTTPD_MAIN_CONF_PATH}/httpd.conf |
| 4 | + sed -i "s/^Group apache/Group root/" ${HTTPD_MAIN_CONF_PATH}/httpd.conf |
| 5 | + sed -i "s%^DocumentRoot \"${HTTPD_DATA_ORIG_PATH}/html\"%#DocumentRoot \"${APP_DATA}\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf |
| 6 | + sed -i "s%^<Directory \"${HTTPD_DATA_ORIG_PATH}/html\"%<Directory \"${APP_DATA}\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf |
| 7 | + sed -i "s%^<Directory \"${HTTPD_VAR_PATH}/html\"%<Directory \"${APP_DATA}\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf |
| 8 | + sed -i "s%^ErrorLog \"logs/error_log\"%ErrorLog \"|/usr/bin/cat\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf |
| 9 | + sed -i "s%CustomLog \"logs/access_log\"%CustomLog \"|/usr/bin/cat\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf |
| 10 | + sed -i "151s%AllowOverride None%AllowOverride All%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf |
| 11 | +} |
| 12 | + |
| 13 | +config_ssl_conf() { |
| 14 | + sed -i -E "s/^Listen 443/Listen 0.0.0.0:8443/" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf |
| 15 | + sed -i -E "s/_default_:443/_default_:8443/" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf |
| 16 | + sed -i -E "s!^(\s*CustomLog)\s+\S+!\1 |/usr/bin/cat!" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf |
| 17 | + sed -i -E "s!^(\s*TransferLog)\s+\S+!\1 |/usr/bin/cat!" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf |
| 18 | + sed -i -E "s!^(\s*ErrorLog)\s+\S+!\1 |/usr/bin/cat!" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf |
| 19 | +} |
| 20 | + |
| 21 | +config_general() { |
| 22 | + config_httpd_conf |
| 23 | + config_ssl_conf |
| 24 | + sed -i '/php_value session.save_path/d' ${HTTPD_MAIN_CONF_D_PATH}/${PHP_HTTPD_CONF_FILE} |
| 25 | + head -n151 ${HTTPD_MAIN_CONF_PATH}/httpd.conf | tail -n1 | grep "AllowOverride All" || exit 1 |
| 26 | + echo "IncludeOptional ${APP_ROOT}/etc/conf.d/*.conf" >> ${HTTPD_MAIN_CONF_PATH}/httpd.conf |
| 27 | +} |
| 28 | + |
| 29 | +function log_info { |
| 30 | + echo "---> `date +%T` $@" |
| 31 | +} |
| 32 | + |
| 33 | +function log_and_run { |
| 34 | + log_info "Running $@" |
| 35 | + "$@" |
| 36 | +} |
| 37 | + |
| 38 | +function log_volume_info { |
| 39 | + CONTAINER_DEBUG=${CONTAINER_DEBUG:-} |
| 40 | + if [[ "${CONTAINER_DEBUG,,}" != "true" ]]; then |
| 41 | + return |
| 42 | + fi |
| 43 | + |
| 44 | + log_info "Volume info for $@:" |
| 45 | + set +e |
| 46 | + log_and_run mount |
| 47 | + while [ $# -gt 0 ]; do |
| 48 | + log_and_run ls -alZ $1 |
| 49 | + shift |
| 50 | + done |
| 51 | + set -e |
| 52 | +} |
| 53 | + |
| 54 | +# get_matched_files finds file for image extending |
| 55 | +function get_matched_files() { |
| 56 | + local custom_dir default_dir |
| 57 | + custom_dir="$1" |
| 58 | + default_dir="$2" |
| 59 | + files_matched="$3" |
| 60 | + find "$default_dir" -maxdepth 1 -type f -name "$files_matched" -printf "%f\n" |
| 61 | + [ -d "$custom_dir" ] && find "$custom_dir" -maxdepth 1 -type f -name "$files_matched" -printf "%f\n" |
| 62 | +} |
| 63 | + |
| 64 | +# process_extending_files process extending files in $1 and $2 directories |
| 65 | +# - source all *.sh files |
| 66 | +# (if there are files with same name source only file from $1) |
| 67 | +function process_extending_files() { |
| 68 | + local custom_dir default_dir |
| 69 | + custom_dir=$1 |
| 70 | + default_dir=$2 |
| 71 | + |
| 72 | + while read filename ; do |
| 73 | + echo "=> sourcing $filename ..." |
| 74 | + # Custom file is prefered |
| 75 | + if [ -f $custom_dir/$filename ]; then |
| 76 | + source $custom_dir/$filename |
| 77 | + elif [ -f $default_dir/$filename ]; then |
| 78 | + source $default_dir/$filename |
| 79 | + fi |
| 80 | + done <<<"$(get_matched_files "$custom_dir" "$default_dir" '*.sh' | sort -u)" |
| 81 | +} |
| 82 | + |
| 83 | +# process extending config files in $1 and $2 directories |
| 84 | +# - expand variables in *.conf and copy the files into /opt/app-root/etc/httpd.d directory |
| 85 | +# (if there are files with same name source only file from $1) |
| 86 | +function process_extending_config_files() { |
| 87 | + local custom_dir default_dir |
| 88 | + custom_dir=$1 |
| 89 | + default_dir=$2 |
| 90 | + |
| 91 | + while read filename ; do |
| 92 | + echo "=> sourcing $filename ..." |
| 93 | + # Custom file is prefered |
| 94 | + if [ -f $custom_dir/$filename ]; then |
| 95 | + envsubst < $custom_dir/$filename > ${HTTPD_CONFIGURATION_PATH}/$filename |
| 96 | + elif [ -f $default_dir/$filename ]; then |
| 97 | + envsubst < $default_dir/$filename > ${HTTPD_CONFIGURATION_PATH}/$filename |
| 98 | + fi |
| 99 | + done <<<"$(get_matched_files "$custom_dir" "$default_dir" '*.conf' | sort -u)" |
| 100 | +} |
| 101 | + |
| 102 | +# Copy config files from application to the location where httd expects them |
| 103 | +# Param sets the directory where to look for files |
| 104 | +# This function was taken from httpd container |
| 105 | +process_config_files() { |
| 106 | + local dir=${1:-.} |
| 107 | + if [ -d ${dir}/httpd-cfg ]; then |
| 108 | + echo "---> Copying httpd configuration files..." |
| 109 | + if [ "$(ls -A ${dir}/httpd-cfg/*.conf)" ]; then |
| 110 | + cp -v ${dir}/httpd-cfg/*.conf "${HTTPD_CONFIGURATION_PATH}"/ |
| 111 | + rm -rf ${dir}/httpd-cfg |
| 112 | + fi |
| 113 | + fi |
| 114 | +} |
| 115 | + |
| 116 | +# Copy SSL files provided in application source |
| 117 | +# This function was taken from httpd container |
| 118 | +process_ssl_certs() { |
| 119 | + local dir=${1:-.} |
| 120 | + if [ -d ${dir}/httpd-ssl/private ] && [ -d ${dir}/httpd-ssl/certs ]; then |
| 121 | + echo "---> Looking for SSL certs for httpd..." |
| 122 | + cp -r ${dir}/httpd-ssl ${APP_ROOT} |
| 123 | + local ssl_cert="$(ls -A ${APP_ROOT}/httpd-ssl/certs/*.pem | head -n 1)" |
| 124 | + local ssl_private="$(ls -A ${APP_ROOT}/httpd-ssl/private/*.pem | head -n 1)" |
| 125 | + if [ -f "${ssl_cert}" ] && [ -f "${ssl_private}" ]; then |
| 126 | + echo "---> Setting SSL certs for httpd..." |
| 127 | + sed -i -e "s|^SSLCertificateFile .*$|SSLCertificateFile ${ssl_cert}|" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf |
| 128 | + sed -i -e "s|^SSLCertificateKeyFile .*$|SSLCertificateKeyFile ${ssl_private}|" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf |
| 129 | + fi |
| 130 | + rm -rf ${dir}/httpd-ssl |
| 131 | + fi |
| 132 | +} |
| 133 | + |
| 134 | + |
0 commit comments