From 864d374118e3077d93db5cabe20a3ae57fd0aeea Mon Sep 17 00:00:00 2001 From: Bitnami Bot Date: Tue, 2 Jun 2020 04:25:31 +0000 Subject: [PATCH] 10.13.0-debian-10-r19 release --- .../postgresql-repmgr/10/debian-10/Dockerfile | 2 +- .../prebuildfs/opt/bitnami/scripts/libfile.sh | 19 ++ .../prebuildfs/opt/bitnami/scripts/libfs.sh | 25 +- .../prebuildfs/opt/bitnami/scripts/liblog.sh | 25 +- .../prebuildfs/opt/bitnami/scripts/libnet.sh | 14 +- .../prebuildfs/opt/bitnami/scripts/libos.sh | 57 ++++ .../opt/bitnami/scripts/libservice.sh | 49 ++- .../opt/bitnami/scripts/libwebserver.sh | 320 ++++++++++++++++++ bitnami/postgresql-repmgr/README.md | 2 +- 9 files changed, 487 insertions(+), 26 deletions(-) create mode 100644 bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libwebserver.sh diff --git a/bitnami/postgresql-repmgr/10/debian-10/Dockerfile b/bitnami/postgresql-repmgr/10/debian-10/Dockerfile index 9bae022a0f1b..34c467b003a1 100644 --- a/bitnami/postgresql-repmgr/10/debian-10/Dockerfile +++ b/bitnami/postgresql-repmgr/10/debian-10/Dockerfile @@ -22,7 +22,7 @@ RUN echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen COPY rootfs / RUN /opt/bitnami/scripts/postgresql-repmgr/postunpack.sh ENV BITNAMI_APP_NAME="postgresql-repmgr" \ - BITNAMI_IMAGE_VERSION="10.13.0-debian-10-r18" \ + BITNAMI_IMAGE_VERSION="10.13.0-debian-10-r19" \ LANG="en_US.UTF-8" \ LANGUAGE="en_US:en" \ NSS_WRAPPER_LIB="/opt/bitnami/common/lib/libnss_wrapper.so" \ diff --git a/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libfile.sh b/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libfile.sh index 8cdb3dfd0b7f..b09575cbe4a6 100644 --- a/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libfile.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libfile.sh @@ -59,3 +59,22 @@ remove_in_file() { fi echo "$result" > "$filename" } + +######################## +# Appends text after the last line matching a pattern +# Arguments: +# $1 - file +# $2 - match regex +# $3 - contents to add +# Returns: +# None +######################### +append_file_after_last_match() { + local file="${1:?missing file}" + local match_regex="${2:?missing pattern}" + local value="${3:?missing value}" + + # We read the file in reverse, replace the first match (0,/pattern/s) and then reverse the results again + result="$(tac "$file" | sed -E "0,/($match_regex)/s||${value}\n\1|" | tac)" + echo "$result" > "$file" +} diff --git a/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libfs.sh b/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libfs.sh index fac947bc44f2..251a47dc7052 100644 --- a/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libfs.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libfs.sh @@ -44,10 +44,10 @@ ensure_dir_exists() { ######################## # Checks whether a directory is empty or not -# Arguments: +# arguments: # $1 - directory -# Returns: -# Boolean +# returns: +# boolean ######################### is_dir_empty() { local dir="${1:?missing directory}" @@ -59,6 +59,25 @@ is_dir_empty() { fi } +######################## +# Checks whether a file can be written to or not +# arguments: +# $1 - file +# returns: +# boolean +######################### +is_file_writable() { + local file="${1:?missing file}" + local dir + dir="$(dirname "$file")" + + if [[ ( -f "$file" && -w "$file" ) || ( ! -f "$file" && -d "$dir" && -w "$dir" ) ]]; then + true + else + false + fi +} + ######################## # Configure permisions and ownership recursively # Globals: diff --git a/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/liblog.sh b/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/liblog.sh index 1285b05ba344..60ec4cbfc32a 100644 --- a/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/liblog.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/liblog.sh @@ -21,7 +21,7 @@ CYAN='\033[38;5;6m' ######################### stderr_print() { # 'is_boolean_yes' is defined in libvalidations.sh, but depends on this file so we cannot source it - local -r bool="${BITNAMI_QUIET:-false}" + local bool="${BITNAMI_QUIET:-false}" # comparison is performed without regard to the case of alphabetic characters shopt -s nocasematch if ! [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then @@ -80,10 +80,31 @@ error() { ######################### debug() { # 'is_boolean_yes' is defined in libvalidations.sh, but depends on this file so we cannot source it - local -r bool="${BITNAMI_DEBUG:-false}" + local bool="${BITNAMI_DEBUG:-false}" # comparison is performed without regard to the case of alphabetic characters shopt -s nocasematch if [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then log "${MAGENTA}DEBUG${RESET} ==> ${*}" fi } + +######################## +# Indent a string +# Arguments: +# $1 - string +# $2 - number of indentation characters (default: 4) +# $3 - indentation character (default: " ") +# Returns: +# None +######################### +indent() { + local string="${1:-}" + local num="${2:?missing num}" + local char="${3:-" "}" + # Build the indentation unit string + local indent_unit="" + for ((i = 0; i < num; i++)); do + indent_unit="${indent_unit}${char}" + done + echo "$string" | sed "s/^/${indent_unit}/" +} diff --git a/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libnet.sh b/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libnet.sh index 6cb749858648..f6380b714583 100644 --- a/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libnet.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libnet.sh @@ -22,7 +22,7 @@ dns_lookup() { } ######################### -## Wait for a hostname and return the IP +# Wait for a hostname and return the IP # Arguments: # $1 - hostname # $2 - number of retries @@ -35,13 +35,13 @@ wait_for_dns_lookup() { local retries="${2:-5}" local seconds="${3:-1}" check_host() { - if [[ $(dns_lookup "$hostname") == "" ]]; then - false - else - true - fi + if [[ $(dns_lookup "$hostname") == "" ]]; then + false + else + true + fi } - # Wait 10 minutes for the host to be ready + # Wait for the host to be ready retry_while "check_host ${hostname}" "$retries" "$seconds" dns_lookup "$hostname" } diff --git a/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libos.sh b/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libos.sh index dac6c18b8854..fab3aed61bd5 100644 --- a/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libos.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libos.sh @@ -204,3 +204,60 @@ retry_while() { done return $return_value } + +######################## +# Generate a random string +# Arguments: +# -t|--type - String type (ascii, alphanumeric, numeric), defaults to ascii +# -c|--count - Number of characters, defaults to 32 +# Arguments: +# None +# Returns: +# None +# Returns: +# String +######################### +generate_random_string() { + local type="ascii" + local count="32" + local filter + local result + # Validate arguments + while [[ "$#" -gt 0 ]]; do + case "$1" in + -t|--type) + shift + type="$1" + ;; + -c|--count) + shift + count="$1" + ;; + *) + echo "Invalid command line flag $1" >&2 + return 1 + ;; + esac + shift + done + # Validate type + case "$type" in + ascii) + filter="[:print:]" + ;; + alphanumeric) + filter="a-zA-Z0-9" + ;; + numeric) + filter="0-9" + ;; + *) + echo "Invalid type ${type}" >&2 + return 1 + esac + # Obtain count + 10 lines from /dev/urandom to ensure that the resulting string has the expected size + # Note there is a very small chance of strings starting with EOL character + # Therefore, the higher amount of lines read, this will happen less frequently + result="$(head -n "$((count + 10))" /dev/urandom | tr -dc "$filter" | head -c "$count")" + echo "$result" +} diff --git a/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libservice.sh b/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libservice.sh index d5382a7cecc2..cd68366f90ac 100644 --- a/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libservice.sh +++ b/bitnami/postgresql-repmgr/10/debian-10/prebuildfs/opt/bitnami/scripts/libservice.sh @@ -2,6 +2,11 @@ # # Library for managing services +# shellcheck disable=SC1091 + +# Load Generic Libraries +. /opt/bitnami/scripts/libvalidations.sh + # Functions ######################## @@ -70,18 +75,38 @@ stop_service_using_pid() { # $2 - Pid file # $3 - Start command # $4 - Stop command +# Flags: +# --disabled - Whether to disable the monit configuration # Returns: # None ######################### generate_monit_conf() { - local -r service_name="${1:?service name is missing}" - local -r pid_file="${2:?pid file is missing}" - local -r start_command="${3:?start command is missing}" - local -r stop_command="${4:?stop command is missing}" - local -r monit_conf_dir="/etc/monit/conf.d" + local service_name="${1:?service name is missing}" + local pid_file="${2:?pid file is missing}" + local start_command="${3:?start command is missing}" + local stop_command="${4:?stop command is missing}" + local monit_conf_dir="/etc/monit/conf.d" + local disabled="no" + # Parse optional CLI flags + shift 4 + while [[ "$#" -gt 0 ]]; do + case "$1" in + --disabled) + shift + disabled="$1" + ;; + *) + echo "Invalid command line flag ${1}" >&2 + return 1 + ;; + esac + shift + done + + is_boolean_yes "$disabled" && conf_suffix=".disabled" mkdir -p "$monit_conf_dir" - cat >"${monit_conf_dir}/${service_name}.conf" <"${monit_conf_dir}/${service_name}.conf${conf_suffix:-}" <"${logrotate_conf_dir}/${service_name}" </dev/null; then + print_validation_error "Could not load the $(web_server_type) web server library from /opt/bitnami/scripts. Check that it exists and is readable." + fi + + return "$error_code" +} + +######################## +# Check whether the web server is running +# Globals: +# * +# Arguments: +# None +# Returns: +# true if the web server is running, false otherwise +######################### +is_web_server_running() { + "is_$(web_server_type)_running" +} + +######################## +# Start web server +# Globals: +# * +# Arguments: +# None +# Returns: +# None +######################### +web_server_start() { + "${BITNAMI_ROOT_DIR}/scripts/$(web_server_type)/start.sh" +} + +######################## +# Stop web server +# Globals: +# * +# Arguments: +# None +# Returns: +# None +######################### +web_server_stop() { + "${BITNAMI_ROOT_DIR}/scripts/$(web_server_type)/stop.sh" +} + +######################## +# Restart web server +# Globals: +# * +# Arguments: +# None +# Returns: +# None +######################### +web_server_restart() { + "${BITNAMI_ROOT_DIR}/scripts/$(web_server_type)/restart.sh" +} + +######################## +# Reload web server +# Globals: +# * +# Arguments: +# None +# Returns: +# None +######################### +web_server_reload() { + "${BITNAMI_ROOT_DIR}/scripts/$(web_server_type)/reload.sh" +} + +######################## +# Ensure a web server application configuration exists (i.e. Apache virtual host format or NGINX server block) +# It serves as a wrapper for the specific web server function +# Globals: +# * +# Arguments: +# $1 - App name +# Flags: +# --hosts - Hosts to enable +# --type - Application type, which has an effect on which configuration template to use +# --allow-remote-connections - Whether to allow remote connections or to require local connections +# --disabled - Whether to render the file with a .disabled prefix +# --enable-https - Enable app configuration on HTTPS port +# --http-port - HTTP port number +# --https-port - HTTPS port number +# --document-root - Path to document root directory +# Apache-specific flags: +# --apache-additional-configuration - Additional vhost configuration (no default) +# --apache-allow-override - Whether to allow .htaccess files (only allowed when --move-htaccess is set to 'no') +# --apache-extra-directory-configuration - Extra configuration for the document root directory +# --apache-move-htaccess - Move .htaccess files to a common place so they can be loaded during Apache startup +# NGINX-specific flags: +# --nginx-additional-configuration - Additional server block configuration (no default) +# Returns: +# true if the configuration was enabled, false otherwise +######################## +ensure_web_server_app_configuration_exists() { + local app="${1:?missing app}" + local -a args=() + # Validate arguments + shift + while [[ "$#" -gt 0 ]]; do + case "$1" in + # Common flags + --hosts \ + | --type \ + | --allow-remote-connections \ + | --disabled \ + | --enable-https \ + | --http-port \ + | --https-port \ + | --document-root \ + ) + args+=("$1" "$2") + shift + ;; + + # Specific Apache flags + --apache-additional-configuration \ + | --apache-allow-override \ + | --apache-extra-directory-configuration \ + | --apache-move-htaccess \ + ) + [[ "$(web_server_type)" == "apache" ]] && args+=("${1//apache-/}" "$2") + shift + ;; + + # Specific NGINX flags + --nginx-additional-configuration) + [[ "$(web_server_type)" == "nginx" ]] && args+=("${1//nginx-/}" "$2") + shift + ;; + + *) + echo "Invalid command line flag $1" >&2 + return 1 + ;; + esac + shift + done + "ensure_$(web_server_type)_app_configuration_exists" "$app" "${args[@]}" +} + +######################## +# Ensure a web server application configuration does not exist anymore (i.e. Apache virtual host format or NGINX server block) +# It serves as a wrapper for the specific web server function +# Globals: +# * +# Arguments: +# $1 - App name +# Returns: +# true if the configuration was disabled, false otherwise +######################## +ensure_web_server_app_configuration_not_exists() { + local app="${1:?missing app}" + "ensure_$(web_server_type)_app_configuration_not_exists" "$app" +} + +######################## +# Ensure the web server loads the configuration for an application in a URL prefix +# It serves as a wrapper for the specific web server function +# Globals: +# * +# Arguments: +# $1 - App name +# Flags: +# --allow-remote-connections - Whether to allow remote connections or to require local connections +# --document-root - Path to document root directory +# --prefix - URL prefix from where it will be accessible (i.e. /myapp) +# --type - Application type, which has an effect on what configuration template will be used +# Apache-specific flags: +# --apache-additional-configuration - Additional vhost configuration (no default) +# --apache-allow-override - Whether to allow .htaccess files (only allowed when --move-htaccess is set to 'no') +# --apache-extra-directory-configuration - Extra configuration for the document root directory +# --apache-move-htaccess - Move .htaccess files to a common place so they can be loaded during Apache startup +# NGINX-specific flags: +# --nginx-additional-configuration - Additional server block configuration (no default) +# Returns: +# true if the configuration was enabled, false otherwise +######################## +ensure_web_server_prefix_configuration_exists() { + local app="${1:?missing app}" + local -a args=() + # Validate arguments + shift + while [[ "$#" -gt 0 ]]; do + case "$1" in + # Common flags + --allow-remote-connections \ + | --document-root \ + | --prefix \ + | --type \ + ) + args+=("$1" "$2") + shift + ;; + + # Specific Apache flags + --apache-additional-configuration \ + | --apache-allow-override \ + | --apache-extra-directory-configuration \ + | --apache-move-htaccess \ + ) + [[ "$(web_server_type)" == "apache" ]] && args+=("${1//apache-/}" "$2") + shift + ;; + + # Specific NGINX flags + --nginx-additional-configuration) + [[ "$(web_server_type)" == "nginx" ]] && args+=("${1//nginx-/}" "$2") + shift + ;; + + *) + echo "Invalid command line flag $1" >&2 + return 1 + ;; + esac + shift + done + "ensure_$(web_server_type)_prefix_configuration_exists" "$app" "${args[@]}" +} + +######################## +# Enable loading page, which shows users that the initialization process is not yet completed +# Globals: +# * +# Arguments: +# None +# Returns: +# None +######################### +web_server_enable_loading_page() { + ensure_web_server_app_configuration_exists "__loading" --hosts "_default_" \ + --apache-additional-configuration " +# Show a HTTP 503 Service Unavailable page by default +RedirectMatch 503 ^/$ +# Show index.html if server is answering with 404 Not Found or 503 Service Unavailable status codes +ErrorDocument 404 /index.html +ErrorDocument 503 /index.html" \ + --nginx-additional-configuration " +# Show a HTTP 503 Service Unavailable page by default +location / { + return 503; +} +# Show index.html if server is answering with 404 Not Found or 503 Service Unavailable status codes +error_page 404 @installing; +error_page 503 @installing; +location @installing { + rewrite ^(.*)$ /index.html break; +}" + web_server_reload +} + +######################## +# Enable loading page, which shows users that the initialization process is not yet completed +# Globals: +# * +# Arguments: +# None +# Returns: +# None +######################### +web_server_disable_install_page() { + ensure_web_server_app_configuration_not_exists "__loading" + web_server_reload +} diff --git a/bitnami/postgresql-repmgr/README.md b/bitnami/postgresql-repmgr/README.md index 6bb0d933646c..2c92bafc0772 100644 --- a/bitnami/postgresql-repmgr/README.md +++ b/bitnami/postgresql-repmgr/README.md @@ -43,7 +43,7 @@ Learn more about the Bitnami tagging policy and the difference between rolling t * [`12-debian-10`, `12.3.0-debian-10-r19`, `12`, `12.3.0` (12/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql-repmgr/blob/12.3.0-debian-10-r19/12/debian-10/Dockerfile) * [`11-debian-10`, `11.8.0-debian-10-r18`, `11`, `11.8.0`, `latest` (11/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql-repmgr/blob/11.8.0-debian-10-r18/11/debian-10/Dockerfile) -* [`10-debian-10`, `10.13.0-debian-10-r18`, `10`, `10.13.0` (10/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql-repmgr/blob/10.13.0-debian-10-r18/10/debian-10/Dockerfile) +* [`10-debian-10`, `10.13.0-debian-10-r19`, `10`, `10.13.0` (10/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql-repmgr/blob/10.13.0-debian-10-r19/10/debian-10/Dockerfile) * [`9.6-debian-10`, `9.6.18-debian-10-r19`, `9.6`, `9.6.18` (9.6/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql-repmgr/blob/9.6.18-debian-10-r19/9.6/debian-10/Dockerfile) Subscribe to project updates by watching the [bitnami/postgresql-repmgr GitHub repo](https://github.com/bitnami/bitnami-docker-postgresql-repmgr).