Prepare SQLite3 DB file before proxy start
This commit is contained in:
parent
6b7fd47301
commit
e308b79a78
|
|
@ -44,6 +44,7 @@ COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/sbin/zabbix_proxy /u
|
|||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/general/bin/zabbix_get /usr/bin/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/general/bin/zabbix_sender /usr/bin/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/conf/ ${ZABBIX_CONF_DIR}/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/database/sqlite3/ /usr/share/doc/zabbix-proxy-sqlite3/
|
||||
|
||||
RUN set -eux && \
|
||||
INSTALL_PKGS="bash \
|
||||
|
|
@ -64,6 +65,7 @@ RUN set -eux && \
|
|||
net-snmp-agent-libs \
|
||||
openipmi-libs \
|
||||
pcre2 \
|
||||
sqlite \
|
||||
sqlite-libs \
|
||||
unixodbc \
|
||||
zlib" && \
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/sbin/zabbix_proxy /u
|
|||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/general/bin/zabbix_get /usr/bin/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/general/bin/zabbix_sender /usr/bin/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/conf/ ${ZABBIX_CONF_DIR}/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/database/sqlite3/ /usr/share/doc/zabbix-proxy-sqlite3/
|
||||
|
||||
RUN --mount=type=tmpfs,target=/var/lib/dnf/ \
|
||||
--mount=type=tmpfs,target=/var/cache/yum/ \
|
||||
|
|
@ -65,8 +66,11 @@ RUN --mount=type=tmpfs,target=/var/lib/dnf/ \
|
|||
openssl \
|
||||
openssl-libs \
|
||||
pcre2 \
|
||||
sqlite \
|
||||
sqlite-libs \
|
||||
shadow-utils \
|
||||
zlib \
|
||||
gzip \
|
||||
unixODBC" && \
|
||||
microdnf -y install \
|
||||
--disablerepo="*" \
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/sbin/zabbix_proxy /u
|
|||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/general/bin/zabbix_get /usr/bin/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/general/bin/zabbix_sender /usr/bin/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/conf/ ${ZABBIX_CONF_DIR}/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/database/sqlite3/ /usr/share/doc/zabbix-proxy-sqlite3/
|
||||
|
||||
RUN --mount=type=tmpfs,target=/var/lib/dnf/ \
|
||||
--mount=type=tmpfs,target=/var/cache/yum/ \
|
||||
|
|
@ -65,7 +66,10 @@ RUN --mount=type=tmpfs,target=/var/lib/dnf/ \
|
|||
openssl \
|
||||
openssl-libs \
|
||||
pcre2 \
|
||||
sqlite \
|
||||
sqlite-libs \
|
||||
zlib \
|
||||
gzip \
|
||||
unixODBC" && \
|
||||
microdnf -y install \
|
||||
--disablerepo="*" \
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/sbin/zabbix_proxy /u
|
|||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/general/bin/zabbix_get /usr/bin/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/general/bin/zabbix_sender /usr/bin/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/conf/ ${ZABBIX_CONF_DIR}/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/database/sqlite3/ /usr/share/doc/zabbix-proxy-sqlite3/
|
||||
|
||||
RUN --mount=type=tmpfs,target=/var/lib/dnf/ \
|
||||
--mount=type=tmpfs,target=/var/cache/yum/ \
|
||||
|
|
@ -84,8 +85,10 @@ RUN --mount=type=tmpfs,target=/var/lib/dnf/ \
|
|||
net-snmp-agent-libs \
|
||||
OpenIPMI-libs \
|
||||
pcre2 \
|
||||
sqlite \
|
||||
sqlite-libs \
|
||||
unixODBC \
|
||||
gzip \
|
||||
zlib" && \
|
||||
curl --tlsv1.2 -sSf -L https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm -o /tmp/epel-release-latest-10.noarch.rpm && \
|
||||
rpm -ivh /tmp/epel-release-latest-10.noarch.rpm && \
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/sbin/zabbix_proxy /u
|
|||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/general/bin/zabbix_get /usr/bin/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/general/bin/zabbix_sender /usr/bin/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/conf/ ${ZABBIX_CONF_DIR}/
|
||||
COPY --from=builder /tmp/zabbix-${ZBX_VERSION}-output/proxy/database/sqlite3/ /usr/share/doc/zabbix-proxy-sqlite3/
|
||||
|
||||
RUN --mount=type=cache,target=/var/cache/apt/,sharing=locked \
|
||||
--mount=type=cache,target=/var/lib/apt/,sharing=locked \
|
||||
|
|
@ -59,6 +60,7 @@ RUN --mount=type=cache,target=/var/cache/apt/,sharing=locked \
|
|||
ca-certificates \
|
||||
fping \
|
||||
openssl \
|
||||
sqlite3 \
|
||||
libc6 \
|
||||
libcares2 \
|
||||
libcurl4t64 \
|
||||
|
|
|
|||
|
|
@ -7,13 +7,15 @@ source "${ENTRYPOINT_LIBS}/openssl.sh"
|
|||
readonly ZABBIX_INTERNAL_ENC_DIR="${ZABBIX_USER_HOME_DIR}/enc_internal"
|
||||
|
||||
proxy_config() {
|
||||
local default_host_name="${1:-}"
|
||||
|
||||
: "${ZBX_SERVER_HOST:=zabbix-server}"
|
||||
export ZBX_SERVER_HOST
|
||||
|
||||
if [ -z "${ZBX_HOSTNAME:-}" ] && [ -n "${ZBX_HOSTNAMEITEM:-}" ]; then
|
||||
export ZBX_HOSTNAME=""
|
||||
else
|
||||
export ZBX_HOSTNAME="${ZBX_HOSTNAME:-zabbix-proxy-mysql}"
|
||||
export ZBX_HOSTNAME="${ZBX_HOSTNAME:-$default_host_name}"
|
||||
fi
|
||||
|
||||
: "${ZBX_ENABLE_SNMP_TRAPS:=false}"
|
||||
|
|
|
|||
36
templates/entrypoints/lib/sqlite3.sh
Normal file
36
templates/entrypoints/lib/sqlite3.sh
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# shellcheck shell=bash
|
||||
|
||||
source "${ENTRYPOINT_LIBS}/logging.sh"
|
||||
|
||||
create_db_schema() {
|
||||
local db_schema_file="${1:-}"
|
||||
|
||||
if ! command -v sqlite3 >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -z "${ZBX_DB_NAME:-}" ]; then
|
||||
error "Missing variable! ZBX_DB_NAME must be set"
|
||||
fi
|
||||
|
||||
local db_dir
|
||||
db_dir="$(dirname "${ZBX_DB_NAME}")"
|
||||
|
||||
if [ ! -d "${db_dir}" ]; then
|
||||
info "** SQLite database directory '${db_dir}' does not exist. Creating..."
|
||||
mkdir -p "${db_dir}"
|
||||
fi
|
||||
|
||||
if [ ! -f "${ZBX_DB_NAME}" ]; then
|
||||
info "** SQLite database '${ZBX_DB_NAME}' does not exist. Creating..."
|
||||
|
||||
zcat "${db_schema_file}" | sqlite3 "${ZBX_DB_NAME}" >/dev/null
|
||||
sqlite3 "${ZBX_DB_NAME}" 'PRAGMA journal_mode=WAL;' >/dev/null
|
||||
else
|
||||
if ! sqlite3 "${ZBX_DB_NAME}" 'PRAGMA schema_version;' >/dev/null 2>&1; then
|
||||
error "File '${ZBX_DB_NAME}' exists but is not a valid SQLite database"
|
||||
fi
|
||||
|
||||
info "** SQLite database '${ZBX_DB_NAME}' already exists."
|
||||
fi
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ update_config() {
|
|||
unset ZBX_DB_PASSWORD
|
||||
fi
|
||||
|
||||
proxy_config
|
||||
proxy_config "zabbix-proxy-mysql"
|
||||
}
|
||||
|
||||
prepare_database() {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ set -euo pipefail
|
|||
readonly ENTRYPOINT_LIBS="/usr/lib/docker-entrypoint"
|
||||
source "${ENTRYPOINT_LIBS}/bootstrap.sh"
|
||||
|
||||
source "${ENTRYPOINT_LIBS}/sqlite3.sh"
|
||||
source "${ENTRYPOINT_LIBS}/proxy-config.sh"
|
||||
|
||||
update_config() {
|
||||
|
|
@ -18,13 +19,14 @@ update_config() {
|
|||
fi
|
||||
unset ZBX_USE_NODE_NAME_AS_DB_NAME
|
||||
|
||||
proxy_config
|
||||
proxy_config "zabbix-proxy-sqlite3"
|
||||
}
|
||||
|
||||
prepare_service() {
|
||||
info "** Preparing Zabbix proxy"
|
||||
|
||||
update_config
|
||||
create_db_schema "/usr/share/doc/zabbix-proxy-sqlite3/create.sql.gz"
|
||||
clear_zbx_env
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue