mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
architectural change 1
This commit is contained in:
129
Dockerfile
129
Dockerfile
@@ -11,15 +11,25 @@ RUN apk add --no-cache bash shadow python3 python3-dev gcc musl-dev libffi-dev o
|
||||
# Enable venv
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
COPY . ${INSTALL_DIR}/
|
||||
RUN mkdir -p ${INSTALL_DIR}
|
||||
COPY api ${INSTALL_DIR}/api
|
||||
COPY back ${INSTALL_DIR}/back
|
||||
COPY config ${INSTALL_DIR}/config
|
||||
COPY db ${INSTALL_DIR}/db
|
||||
COPY dockerfiles ${INSTALL_DIR}/dockerfiles
|
||||
COPY front ${INSTALL_DIR}/front
|
||||
COPY server ${INSTALL_DIR}/server
|
||||
|
||||
RUN pip install openwrt-luci-rpc asusrouter asyncio aiohttp graphene flask flask-cors unifi-sm-api tplink-omada-client wakeonlan pycryptodome requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet python-nmap dnspython librouteros yattag git+https://github.com/foreign-sub/aiofreepybox.git \
|
||||
&& bash -c "find ${INSTALL_DIR} -type d -exec chmod 750 {} \;" \
|
||||
#COPY . ${INSTALL_DIR}/
|
||||
|
||||
RUN pip install openwrt-luci-rpc asusrouter asyncio aiohttp graphene flask flask-cors unifi-sm-api tplink-omada-client wakeonlan pycryptodome requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet python-nmap dnspython librouteros yattag git+https://github.com/foreign-sub/aiofreepybox.git
|
||||
|
||||
RUN bash -c "find ${INSTALL_DIR} -type d -exec chmod 750 {} \;" \
|
||||
&& bash -c "find ${INSTALL_DIR} -type f -exec chmod 640 {} \;" \
|
||||
&& bash -c "find ${INSTALL_DIR} -type f \( -name '*.sh' -o -name '*.py' -o -name 'speedtest-cli' \) -exec chmod 750 {} \;"
|
||||
|
||||
# Append Iliadbox certificate to aiofreepybox
|
||||
RUN cat ${INSTALL_DIR}/install/freebox_certificate.pem >> /opt/venv/lib/python3.12/site-packages/aiofreepybox/freebox_certificates.pem
|
||||
COPY install/freebox_certificate.pem /opt/venv/lib/python3.12/site-packages/aiofreepybox/freebox_certificates.pem
|
||||
|
||||
# second stage
|
||||
FROM alpine:3.22 AS runner
|
||||
@@ -33,11 +43,40 @@ COPY --from=builder /usr/sbin/usermod /usr/sbin/groupmod /usr/sbin/
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
# default port and listen address
|
||||
ENV PORT=20211 LISTEN_ADDR=0.0.0.0
|
||||
ENV PORT=20211 LISTEN_ADDR=0.0.0.0 GRAPHQL_PORT=20212
|
||||
|
||||
# needed for s6-overlay
|
||||
ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0
|
||||
|
||||
# NetAlertX app directories
|
||||
ENV NETALERTX_APP=/app
|
||||
ENV NETALERTX_CONFIG=${NETALERTX_APP}/config
|
||||
ENV NETALERTX_FRONT=${NETALERTX_APP}/front
|
||||
ENV NETALERTX_SERVER=${NETALERTX_APP}/server
|
||||
ENV NETALERTX_API=${NETALERTX_APP}/api
|
||||
ENV NETALERTX_DB=${NETALERTX_APP}/db
|
||||
ENV NETALERTX_BACK=${NETALERTX_APP}/back
|
||||
ENV NETALERTX_LOG=${NETALERTX_APP}/log
|
||||
ENV NETALERTX_PLUGINS_LOG=${NETALERTX_LOG}/plugins
|
||||
|
||||
# NetAlertX log files
|
||||
ENV LOG_IP_CHANGES=${NETALERTX_LOG}/IP_changes.log
|
||||
ENV LOG_APP=${NETALERTX_LOG}/app.log
|
||||
ENV LOG_APP_FRONT=${NETALERTX_LOG}/app_front.log
|
||||
ENV LOG_REPORT_OUTPUT_TXT=${NETALERTX_LOG}/report_output.txt
|
||||
ENV LOG_DB_IS_LOCKED=${NETALERTX_LOG}/db_is_locked.log
|
||||
ENV LOG_REPORT_OUTPUT_HTML=${NETALERTX_LOG}/report_output.html
|
||||
ENV LOG_STDERR=${NETALERTX_LOG}/stderr.log
|
||||
ENV LOG_APP_PHP_ERRORS=${NETALERTX_LOG}/app.php_errors.log
|
||||
ENV LOG_EXECUTION_QUEUE=${NETALERTX_LOG}/execution_queue.log
|
||||
ENV LOG_REPORT_OUTPUT_JSON=${NETALERTX_LOG}/report_output.json
|
||||
ENV LOG_STDOUT=${NETALERTX_LOG}/stdout.log
|
||||
|
||||
# Important configuration files
|
||||
ENV NGINX_CONFIG_FILE="/etc/nginx/http.d/netalertx.conf"
|
||||
ENV NETALERTX_CONFIG_FILE=${NETALERTX_CONFIG}/app.conf
|
||||
ENV NETALERTX_DB_FILE=${NETALERTX_DB}/app.db
|
||||
|
||||
# ❗ IMPORTANT - if you modify this file modify the /install/install_dependecies.sh file as well ❗
|
||||
|
||||
RUN apk update --no-cache \
|
||||
@@ -51,13 +90,85 @@ RUN apk update --no-cache \
|
||||
|
||||
COPY --from=builder --chown=nginx:www-data ${INSTALL_DIR}/ ${INSTALL_DIR}/
|
||||
|
||||
# Create required directories
|
||||
RUN mkdir -p ${INSTALL_DIR}/config ${INSTALL_DIR}/db ${INSTALL_DIR}/log/plugins
|
||||
|
||||
# Add crontab file
|
||||
COPY --chmod=600 --chown=root:root install/crontab /etc/crontabs/root
|
||||
|
||||
# Start all required services
|
||||
RUN ${INSTALL_DIR}/dockerfiles/start.sh
|
||||
# Add healthcheck script
|
||||
COPY --chmod=755 dockerfiles/healthcheck.sh /usr/local/bin/healthcheck.sh
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=2 \
|
||||
CMD curl -sf -o /dev/null ${LISTEN_ADDR}:${PORT}/php/server/query_json.php?file=app_state.json
|
||||
# Create empty log files and API files
|
||||
RUN touch ${INSTALL_DIR}/log/app.log \
|
||||
&& touch ${INSTALL_DIR}/log/execution_queue.log \
|
||||
&& touch ${INSTALL_DIR}/log/app_front.log \
|
||||
&& touch ${INSTALL_DIR}/log/app.php_errors.log \
|
||||
&& touch ${INSTALL_DIR}/log/stderr.log \
|
||||
&& touch ${INSTALL_DIR}/log/stdout.log \
|
||||
&& touch ${INSTALL_DIR}/log/db_is_locked.log \
|
||||
&& touch ${INSTALL_DIR}/log/IP_changes.log \
|
||||
&& touch ${INSTALL_DIR}/log/report_output.txt \
|
||||
&& touch ${INSTALL_DIR}/log/report_output.html \
|
||||
&& touch ${INSTALL_DIR}/log/report_output.json \
|
||||
&& touch ${INSTALL_DIR}/api/user_notifications.json
|
||||
|
||||
|
||||
|
||||
# Set up PHP-FPM directories and socket configuration
|
||||
RUN install -d -o nginx -g www-data /run/php/ \
|
||||
&& sed -i "/^;pid/c\pid = /run/php/php8.3-fpm.pid" /etc/php83/php-fpm.conf \
|
||||
&& sed -i "/^listen/c\listen = /run/php/php8.3-fpm.sock" /etc/php83/php-fpm.d/www.conf \
|
||||
&& sed -i "/^;listen.owner/c\listen.owner = nginx" /etc/php83/php-fpm.d/www.conf \
|
||||
&& sed -i "/^;listen.group/c\listen.group = www-data" /etc/php83/php-fpm.d/www.conf \
|
||||
&& sed -i "/^user/c\user = nginx" /etc/php83/php-fpm.d/www.conf \
|
||||
&& sed -i "/^group/c\group = www-data" /etc/php83/php-fpm.d/www.conf
|
||||
|
||||
# Set up s6 overlay service directories
|
||||
RUN mkdir -p /etc/s6-overlay/s6-rc.d/SetupOneshot \
|
||||
&& mkdir -p /etc/s6-overlay/s6-rc.d/crond/dependencies.d \
|
||||
&& mkdir -p /etc/s6-overlay/s6-rc.d/php-fpm/dependencies.d \
|
||||
&& mkdir -p /etc/s6-overlay/s6-rc.d/nginx/dependencies.d \
|
||||
&& mkdir -p /etc/s6-overlay/s6-rc.d/netalertx/dependencies.d
|
||||
|
||||
# Set up s6 overlay service types and scripts
|
||||
RUN echo "oneshot" > /etc/s6-overlay/s6-rc.d/SetupOneshot/type \
|
||||
&& echo "longrun" > /etc/s6-overlay/s6-rc.d/crond/type \
|
||||
&& echo "longrun" > /etc/s6-overlay/s6-rc.d/php-fpm/type \
|
||||
&& echo "longrun" > /etc/s6-overlay/s6-rc.d/nginx/type \
|
||||
&& echo "longrun" > /etc/s6-overlay/s6-rc.d/netalertx/type
|
||||
|
||||
# Create s6 overlay service scripts
|
||||
RUN echo -e "${INSTALL_DIR}/dockerfiles/init.sh" > /etc/s6-overlay/s6-rc.d/SetupOneshot/up \
|
||||
&& echo -e '#!/bin/execlineb -P\n\nif { echo\n"\n[INSTALL] Starting crond service...\n\n" }\n/usr/sbin/crond -f' > /etc/s6-overlay/s6-rc.d/crond/run \
|
||||
&& echo -e "#!/bin/execlineb -P\n/usr/sbin/php-fpm83 -F" > /etc/s6-overlay/s6-rc.d/php-fpm/run \
|
||||
&& echo -e '#!/bin/execlineb -P\nnginx -g "daemon off;"' > /etc/s6-overlay/s6-rc.d/nginx/run \
|
||||
&& echo -e '#!/bin/execlineb -P\nwith-contenv\n\nimportas -u PORT PORT\n\nif { echo\n"\n[INSTALL] 🚀 Starting app (:${PORT})\n\n" }\npython -m server' > /etc/s6-overlay/s6-rc.d/netalertx/run
|
||||
|
||||
# Set up s6 overlay dependencies
|
||||
RUN touch /etc/s6-overlay/s6-rc.d/user/contents.d/SetupOneshot \
|
||||
&& touch /etc/s6-overlay/s6-rc.d/user/contents.d/crond \
|
||||
&& touch /etc/s6-overlay/s6-rc.d/user/contents.d/php-fpm \
|
||||
&& touch /etc/s6-overlay/s6-rc.d/user/contents.d/nginx \
|
||||
&& touch /etc/s6-overlay/s6-rc.d/user/contents.d/netalertx \
|
||||
&& touch /etc/s6-overlay/s6-rc.d/crond/dependencies.d/SetupOneshot \
|
||||
&& touch /etc/s6-overlay/s6-rc.d/php-fpm/dependencies.d/SetupOneshot \
|
||||
&& touch /etc/s6-overlay/s6-rc.d/nginx/dependencies.d/SetupOneshot \
|
||||
&& touch /etc/s6-overlay/s6-rc.d/nginx/dependencies.d/php-fpm \
|
||||
&& touch /etc/s6-overlay/s6-rc.d/netalertx/dependencies.d/SetupOneshot \
|
||||
&& touch /etc/s6-overlay/s6-rc.d/netalertx/dependencies.d/nginx
|
||||
|
||||
# Set permissions for application directories
|
||||
RUN chown -R nginx:www-data ${INSTALL_DIR} \
|
||||
&& chmod 750 ${INSTALL_DIR}/config ${INSTALL_DIR}/log ${INSTALL_DIR}/db \
|
||||
&& find ${INSTALL_DIR}/config ${INSTALL_DIR}/log ${INSTALL_DIR}/db -type f -exec chmod 640 {} \; \
|
||||
&& chown nginx:nginx /run/nginx/ /var/log/nginx/ /var/lib/nginx/ /var/lib/nginx/tmp/ \
|
||||
&& chgrp www-data /var/www/localhost/htdocs/
|
||||
|
||||
# Create buildtimestamp.txt
|
||||
RUN date +%s > ${INSTALL_DIR}/front/buildtimestamp.txt
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD /usr/local/bin/healthcheck.sh
|
||||
|
||||
ENTRYPOINT ["/init"]
|
||||
|
||||
24
dockerfiles/entrypoint.sh
Normal file
24
dockerfiles/entrypoint.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "---------------------------------------------------------"
|
||||
echo "[ENTRYPOINT] Initializing container..."
|
||||
echo "---------------------------------------------------------"
|
||||
|
||||
# Run the main initialization script
|
||||
/app/dockerfiles/init.sh
|
||||
|
||||
echo "---------------------------------------------------------"
|
||||
echo "[ENTRYPOINT] Starting services..."
|
||||
echo "---------------------------------------------------------"
|
||||
|
||||
# Start all services in the background
|
||||
/app/dockerfiles/start-crond.sh &
|
||||
/app/dockerfiles/start-php-fpm.sh &
|
||||
/app/dockerfiles/start-nginx.sh &
|
||||
/app/dockerfiles/start-backend.sh &
|
||||
|
||||
# Wait for any process to exit
|
||||
wait -n
|
||||
|
||||
# Exit with status of process that exited first
|
||||
exit $?
|
||||
73
dockerfiles/healthcheck.sh
Normal file
73
dockerfiles/healthcheck.sh
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
|
||||
# NetAlertX Comprehensive Health Check Script
|
||||
# This script verifies all critical services and endpoints are functioning
|
||||
|
||||
set -e
|
||||
|
||||
EXIT_CODE=0
|
||||
|
||||
echo "[HEALTHCHECK] Starting comprehensive health check..."
|
||||
|
||||
# Function to log errors and set exit code
|
||||
log_error() {
|
||||
echo "[HEALTHCHECK] ERROR: $1" >&2
|
||||
EXIT_CODE=1
|
||||
}
|
||||
|
||||
# Function to log success
|
||||
log_success() {
|
||||
echo "[HEALTHCHECK] ✓ $1"
|
||||
}
|
||||
|
||||
# 1. Check if crond is running
|
||||
if pgrep -f "crond" > /dev/null; then
|
||||
log_success "crond is running"
|
||||
else
|
||||
log_error "crond is not running"
|
||||
fi
|
||||
|
||||
# 2. Check if php-fpm is running
|
||||
if pgrep -f "php-fpm" > /dev/null; then
|
||||
log_success "php-fpm is running"
|
||||
else
|
||||
log_error "php-fpm is not running"
|
||||
fi
|
||||
|
||||
# 3. Check if nginx is running
|
||||
if pgrep -f "nginx" > /dev/null; then
|
||||
log_success "nginx is running"
|
||||
else
|
||||
log_error "nginx is not running"
|
||||
fi
|
||||
|
||||
# 4. Check if python /app/server is running
|
||||
if pgrep -f "python.*server" > /dev/null; then
|
||||
log_success "python /app/server is running"
|
||||
else
|
||||
log_error "python /app/server is not running"
|
||||
fi
|
||||
|
||||
# 5. Check port 20211 is open and contains "netalertx"
|
||||
if curl -sf --max-time 10 "http://localhost:${PORT:-20211}" | grep -i "netalertx" > /dev/null; then
|
||||
log_success "Port ${PORT:-20211} is responding and contains 'netalertx'"
|
||||
else
|
||||
log_error "Port ${PORT:-20211} is not responding or doesn't contain 'netalertx'"
|
||||
fi
|
||||
|
||||
# 6. Check port 20212/graphql returns "graphql" in first lines
|
||||
GRAPHQL_PORT=${GRAPHQL_PORT:-20212}
|
||||
if curl -sf --max-time 10 "http://localhost:${GRAPHQL_PORT}/graphql" | head -10 | grep -i "graphql" > /dev/null; then
|
||||
log_success "Port ${GRAPHQL_PORT}/graphql is responding with GraphQL content"
|
||||
else
|
||||
log_error "Port ${GRAPHQL_PORT}/graphql is not responding or doesn't contain 'graphql'"
|
||||
fi
|
||||
|
||||
# Summary
|
||||
if [ $EXIT_CODE -eq 0 ]; then
|
||||
echo "[HEALTHCHECK] ✅ All health checks passed"
|
||||
else
|
||||
echo "[HEALTHCHECK] ❌ One or more health checks failed"
|
||||
fi
|
||||
|
||||
exit $EXIT_CODE
|
||||
6
dockerfiles/init-backend.sh
Normal file
6
dockerfiles/init-backend.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
echo "Initializing backend..."
|
||||
# Future backend initialization steps can go here.
|
||||
# For now, we'll just ensure permissions are correct.
|
||||
chown -R nginx:www-data "${NETALERTX_APP}"
|
||||
echo "Backend initialized."
|
||||
7
dockerfiles/init-crond.sh
Normal file
7
dockerfiles/init-crond.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
echo "Initializing crond..."
|
||||
# Add crontab file
|
||||
cp -f ${NETALERTX_APP}/install/crontab /etc/crontabs/root
|
||||
chmod 600 /etc/crontabs/root
|
||||
chown root:root /etc/crontabs/root
|
||||
echo "crond initialized."
|
||||
7
dockerfiles/init-nginx.sh
Normal file
7
dockerfiles/init-nginx.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
echo "Initializing nginx..."
|
||||
# Setup NGINX
|
||||
echo "Setting webserver to address ($LISTEN_ADDR) and port ($PORT)"
|
||||
envsubst '$NETALERTX_APP $LISTEN_ADDR $PORT' < "${NETALERTX_APP}/install/netalertx.template.conf" > "${NGINX_CONFIG_FILE}"
|
||||
rm -f /etc/nginx/http.d/default.conf
|
||||
echo "nginx initialized."
|
||||
22
dockerfiles/init-php-fpm.sh
Normal file
22
dockerfiles/init-php-fpm.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
echo "Initializing php-fpm..."
|
||||
# Set up PHP-FPM directories and socket configuration
|
||||
install -d -o nginx -g www-data /run/php/
|
||||
sed -i "/^;pid/c\pid = /run/php/php8.3-fpm.pid" /etc/php83/php-fpm.conf
|
||||
sed -i "/^listen/c\listen = /run/php/php8.3-fpm.sock" /etc/php83/php-fpm.d/www.conf
|
||||
sed -i "/^;listen.owner/c\listen.owner = nginx" /etc/php83/php-fpm.d/www.conf
|
||||
sed -i "/^;listen.group/c\listen.group = www-data" /etc/php83/php-fpm.d/www.conf
|
||||
sed -i "/^user/c\user = nginx" /etc/php83/php-fpm.d/www.conf
|
||||
sed -i "/^group/c\group = www-data" /etc/php83/php-fpm.d/www.conf
|
||||
|
||||
# Increase max child process count
|
||||
sed -i -e 's/pm.max_children = 5/pm.max_children = 10/' /etc/php83/php-fpm.d/www.conf
|
||||
|
||||
# Set error log path
|
||||
sed -i "/^;*error_log\s*=/c\error_log = ${LOG_APP_PHP_ERRORS}" /etc/php83/php-fpm.conf
|
||||
# If the line was not found, append it to the end of the file
|
||||
if ! grep -q '^error_log\s*=' /etc/php83/php-fpm.conf; then
|
||||
echo "error_log = ${LOG_APP_PHP_ERRORS}" >> /etc/php83/php-fpm.conf
|
||||
fi
|
||||
|
||||
echo "php-fpm initialized."
|
||||
@@ -12,14 +12,8 @@ PGID=${PGID:-${DEFAULT_GID}}
|
||||
|
||||
echo "[INSTALL] Setting up user UID and GID"
|
||||
|
||||
if ! groupmod -o -g "$PGID" www-data && [ "$PGID" != "$DEFAULT_GID" ] ; then
|
||||
echo "Failed to set user GID to ${PGID}, trying with default GID ${DEFAULT_GID}"
|
||||
groupmod -o -g "$DEFAULT_GID" www-data
|
||||
fi
|
||||
if ! usermod -o -u "$PUID" nginx && [ "$PUID" != "$DEFAULT_PUID" ] ; then
|
||||
echo "Failed to set user UID to ${PUID}, trying with default PUID ${DEFAULT_PUID}"
|
||||
usermod -o -u "$DEFAULT_PUID" nginx
|
||||
fi
|
||||
groupmod -o -g "$PGID" www-data 2>/dev/null || echo "Failed to set user GID to ${PGID}, using existing GID"
|
||||
usermod -o -u "$PUID" nginx 2>/dev/null || echo "Failed to set user UID to ${PUID}, using existing UID"
|
||||
|
||||
echo "
|
||||
---------------------------------------------------------
|
||||
@@ -29,18 +23,11 @@ User UID: $(id -u nginx)
|
||||
User GID: $(getent group www-data | cut -d: -f3)
|
||||
---------------------------------------------------------"
|
||||
|
||||
chown nginx:nginx /run/nginx/ /var/log/nginx/ /var/lib/nginx/ /var/lib/nginx/tmp/
|
||||
chgrp www-data /var/www/localhost/htdocs/
|
||||
|
||||
export INSTALL_DIR=/app # Specify the installation directory here
|
||||
|
||||
# DO NOT CHANGE ANYTHING BELOW THIS LINE!
|
||||
|
||||
CONF_FILE="app.conf"
|
||||
NGINX_CONF_FILE=netalertx.conf
|
||||
DB_FILE="app.db"
|
||||
FULL_FILEDB_PATH="${INSTALL_DIR}/db/${DB_FILE}"
|
||||
NGINX_CONFIG_FILE="/etc/nginx/http.d/${NGINX_CONF_FILE}"
|
||||
FULL_FILEDB_PATH="${NETALERTX_DB}/${DB_FILE}"
|
||||
OUI_FILE="/usr/share/arp-scan/ieee-oui.txt" # Define the path to ieee-oui.txt and ieee-iab.txt
|
||||
|
||||
INSTALL_DIR_OLD=/home/pi/pialert
|
||||
@@ -58,51 +45,49 @@ fi
|
||||
if [ "$ALWAYS_FRESH_INSTALL" = true ]; then
|
||||
echo "[INSTALL] ❗ ALERT /db and /config folders are cleared because the ALWAYS_FRESH_INSTALL is set to: $ALWAYS_FRESH_INSTALL❗"
|
||||
|
||||
# Delete content of "$INSTALL_DIR/config/"
|
||||
rm -rf "$INSTALL_DIR/config/"*
|
||||
rm -rf "$INSTALL_DIR_OLD/config/"*
|
||||
# Delete content of "$NETALERTX_CONFIG/"
|
||||
rm -rf ${NETALERTX_CONFIG}/*
|
||||
|
||||
# Delete content of "$INSTALL_DIR/db/"
|
||||
rm -rf "$INSTALL_DIR/db/"*
|
||||
rm -rf "$INSTALL_DIR_OLD/db/"*
|
||||
# Delete content of "$NETALERTX_DB/"
|
||||
rm -rf ${NETALERTX_DB}/*
|
||||
fi
|
||||
|
||||
# OVERRIDE settings: Handling APP_CONF_OVERRIDE
|
||||
# Check if APP_CONF_OVERRIDE is set
|
||||
|
||||
# remove old
|
||||
rm "${INSTALL_DIR}/config/app_conf_override.json"
|
||||
rm -f "${NETALERTX_CONFIG}/app_conf_override.json"
|
||||
|
||||
if [ -z "$APP_CONF_OVERRIDE" ]; then
|
||||
echo "APP_CONF_OVERRIDE is not set. Skipping config file creation."
|
||||
else
|
||||
# Save the APP_CONF_OVERRIDE env variable as a JSON file
|
||||
echo "$APP_CONF_OVERRIDE" > "${INSTALL_DIR}/config/app_conf_override.json"
|
||||
echo "Config file saved to ${INSTALL_DIR}/config/app_conf_override.json"
|
||||
echo "$APP_CONF_OVERRIDE" > "${NETALERTX_CONFIG}/app_conf_override.json"
|
||||
echo "Config file saved to ${NETALERTX_CONFIG}/app_conf_override.json"
|
||||
fi
|
||||
|
||||
# 🔻 FOR BACKWARD COMPATIBILITY - REMOVE AFTER 12/12/2025
|
||||
|
||||
# Check if pialert.db exists, then create a symbolic link to app.db
|
||||
if [ -f "${INSTALL_DIR_OLD}/db/${OLD_APP_NAME}.db" ]; then
|
||||
ln -s "${INSTALL_DIR_OLD}/db/${OLD_APP_NAME}.db" "${FULL_FILEDB_PATH}"
|
||||
ln -sf "${INSTALL_DIR_OLD}/db/${OLD_APP_NAME}.db" "${FULL_FILEDB_PATH}"
|
||||
fi
|
||||
|
||||
# Check if ${OLD_APP_NAME}.conf exists, then create a symbolic link to app.conf
|
||||
if [ -f "${INSTALL_DIR_OLD}/config/${OLD_APP_NAME}.conf" ]; then
|
||||
ln -s "${INSTALL_DIR_OLD}/config/${OLD_APP_NAME}.conf" "${INSTALL_DIR}/config/${CONF_FILE}"
|
||||
ln -sf "${INSTALL_DIR_OLD}/config/${OLD_APP_NAME}.conf" "${NETALERTX_CONFIG}/${CONF_FILE}"
|
||||
fi
|
||||
# 🔺 FOR BACKWARD COMPATIBILITY - REMOVE AFTER 12/12/2025
|
||||
|
||||
echo "[INSTALL] Copy starter ${DB_FILE} and ${CONF_FILE} if they don't exist"
|
||||
|
||||
# Copy starter app.db, app.conf if they don't exist
|
||||
cp -na "${INSTALL_DIR}/back/${CONF_FILE}" "${INSTALL_DIR}/config/${CONF_FILE}"
|
||||
cp -na "${INSTALL_DIR}/back/${DB_FILE}" "${FULL_FILEDB_PATH}"
|
||||
cp -n "${NETALERTX_BACK}/${CONF_FILE}" "${NETALERTX_CONFIG}/${CONF_FILE}" 2>/dev/null || true
|
||||
cp -n "${NETALERTX_BACK}/${DB_FILE}" "${FULL_FILEDB_PATH}" 2>/dev/null || true
|
||||
|
||||
# if custom variables not set we do not need to do anything
|
||||
if [ -n "${TZ}" ]; then
|
||||
FILECONF="${INSTALL_DIR}/config/${CONF_FILE}"
|
||||
FILECONF="${NETALERTX_CONFIG}/${CONF_FILE}"
|
||||
echo "[INSTALL] Setup timezone"
|
||||
sed -i "\#^TIMEZONE=#c\TIMEZONE='${TZ}'" "${FILECONF}"
|
||||
|
||||
@@ -113,14 +98,14 @@ fi
|
||||
|
||||
# if custom variables not set we do not need to do anything
|
||||
if [ -n "${LOADED_PLUGINS}" ]; then
|
||||
FILECONF="${INSTALL_DIR}/config/${CONF_FILE}"
|
||||
FILECONF="${NETALERTX_CONFIG}/${CONF_FILE}"
|
||||
echo "[INSTALL] Setup custom LOADED_PLUGINS variable"
|
||||
sed -i "\#^LOADED_PLUGINS=#c\LOADED_PLUGINS=${LOADED_PLUGINS}" "${FILECONF}"
|
||||
fi
|
||||
|
||||
echo "[INSTALL] Setup NGINX"
|
||||
echo "Setting webserver to address ($LISTEN_ADDR) and port ($PORT)"
|
||||
envsubst '$INSTALL_DIR $LISTEN_ADDR $PORT' < "${INSTALL_DIR}/install/netalertx.template.conf" > "${NGINX_CONFIG_FILE}"
|
||||
envsubst '$NETALERTX_APP $LISTEN_ADDR $PORT' < "${NETALERTX_APP}/install/netalertx.template.conf" > "${NGINX_CONFIG_FILE}"
|
||||
|
||||
# Run the hardware vendors update at least once
|
||||
echo "[INSTALL] Run the hardware vendors update"
|
||||
@@ -132,33 +117,15 @@ else
|
||||
echo "The file ieee-oui.txt does not exist. Running update_vendors..."
|
||||
|
||||
# Run the update_vendors.sh script
|
||||
if [ -f "${INSTALL_DIR}/back/update_vendors.sh" ]; then
|
||||
"${INSTALL_DIR}/back/update_vendors.sh"
|
||||
if [ -f "${NETALERTX_BACK}/update_vendors.sh" ]; then
|
||||
"${NETALERTX_BACK}/update_vendors.sh"
|
||||
else
|
||||
echo "update_vendors.sh script not found in ${INSTALL_DIR}."
|
||||
echo "update_vendors.sh script not found in ${NETALERTX_APP}."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create an empty log files
|
||||
# Create the execution_queue.log and app_front.log files if they don't exist
|
||||
touch "${INSTALL_DIR}"/log/{app.log,execution_queue.log,app_front.log,app.php_errors.log,stderr.log,stdout.log,db_is_locked.log}
|
||||
touch "${INSTALL_DIR}"/api/user_notifications.json
|
||||
|
||||
# Create plugins sub-directory if it doesn't exist in case a custom log folder is used
|
||||
mkdir -p "${INSTALL_DIR}"/log/plugins
|
||||
|
||||
echo "[INSTALL] Fixing permissions after copied starter config & DB"
|
||||
chown -R nginx:www-data "${INSTALL_DIR}"
|
||||
|
||||
chmod 750 "${INSTALL_DIR}"/{config,log,db}
|
||||
find "${INSTALL_DIR}"/{config,log,db} -type f -exec chmod 640 {} \;
|
||||
|
||||
# Check if buildtimestamp.txt doesn't exist
|
||||
if [ ! -f "${INSTALL_DIR}/front/buildtimestamp.txt" ]; then
|
||||
# Create buildtimestamp.txt
|
||||
date +%s > "${INSTALL_DIR}/front/buildtimestamp.txt"
|
||||
chown nginx:www-data "${INSTALL_DIR}/front/buildtimestamp.txt"
|
||||
fi
|
||||
echo "[INSTALL] Fixing permissions after runtime initialization"
|
||||
chown -R nginx:www-data "${NETALERTX_CONFIG}" "${NETALERTX_DB}" "${NETALERTX_LOG}"
|
||||
|
||||
echo -e "
|
||||
[ENV] PATH is ${PATH}
|
||||
|
||||
8
dockerfiles/start-backend.sh
Normal file
8
dockerfiles/start-backend.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
echo "Starting backend..."
|
||||
cd "${NETALERTX_APP}" || exit
|
||||
# Clear previous logs
|
||||
echo '' > "${LOG_STDOUT}"
|
||||
echo '' > "${LOG_STDERR}"
|
||||
# Start the backend and redirect output
|
||||
exec python3 -m server >> "${LOG_STDOUT}" 2>> "${LOG_STDERR}"
|
||||
3
dockerfiles/start-crond.sh
Normal file
3
dockerfiles/start-crond.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
echo "Starting crond..."
|
||||
exec /usr/sbin/crond -f -L /dev/stdout
|
||||
3
dockerfiles/start-nginx.sh
Normal file
3
dockerfiles/start-nginx.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
echo "Starting nginx..."
|
||||
exec nginx -g "daemon off;"
|
||||
3
dockerfiles/start-php-fpm.sh
Normal file
3
dockerfiles/start-php-fpm.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
echo "Starting php-fpm..."
|
||||
exec /usr/sbin/php-fpm83 -F
|
||||
@@ -1,49 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
export INSTALL_DIR=/app
|
||||
export APP_NAME=netalertx
|
||||
# This script is now mostly handled by the Dockerfile
|
||||
# Only runtime cleanup remains
|
||||
|
||||
# php-fpm setup
|
||||
install -d -o nginx -g www-data /run/php/
|
||||
sed -i "/^;pid/c\pid = /run/php/php8.3-fpm.pid" /etc/php83/php-fpm.conf
|
||||
sed -i "/^listen/c\listen = /run/php/php8.3-fpm.sock" /etc/php83/php-fpm.d/www.conf
|
||||
sed -i "/^;listen.owner/c\listen.owner = nginx" /etc/php83/php-fpm.d/www.conf
|
||||
sed -i "/^;listen.group/c\listen.group = www-data" /etc/php83/php-fpm.d/www.conf
|
||||
sed -i "/^user/c\user = nginx" /etc/php83/php-fpm.d/www.conf
|
||||
sed -i "/^group/c\group = www-data" /etc/php83/php-fpm.d/www.conf
|
||||
|
||||
# s6 overlay setup
|
||||
mkdir -p /etc/s6-overlay/s6-rc.d/{SetupOneshot,crond/dependencies.d,php-fpm/dependencies.d,nginx/dependencies.d,$APP_NAME/dependencies.d}
|
||||
echo "oneshot" > /etc/s6-overlay/s6-rc.d/SetupOneshot/type
|
||||
echo "longrun" > /etc/s6-overlay/s6-rc.d/crond/type
|
||||
echo "longrun" > /etc/s6-overlay/s6-rc.d/php-fpm/type
|
||||
echo "longrun" > /etc/s6-overlay/s6-rc.d/nginx/type
|
||||
echo "longrun" > /etc/s6-overlay/s6-rc.d/$APP_NAME/type
|
||||
echo -e "${INSTALL_DIR}/dockerfiles/init.sh" > /etc/s6-overlay/s6-rc.d/SetupOneshot/up
|
||||
echo -e '#!/bin/execlineb -P
|
||||
|
||||
if { echo
|
||||
"
|
||||
[INSTALL] Starting crond service...
|
||||
|
||||
" }' > /etc/s6-overlay/s6-rc.d/crond/run
|
||||
echo -e "/usr/sbin/crond -f" >> /etc/s6-overlay/s6-rc.d/crond/run
|
||||
echo -e "#!/bin/execlineb -P\n/usr/sbin/php-fpm83 -F" > /etc/s6-overlay/s6-rc.d/php-fpm/run
|
||||
echo -e '#!/bin/execlineb -P\nnginx -g "daemon off;"' > /etc/s6-overlay/s6-rc.d/nginx/run
|
||||
echo -e '#!/bin/execlineb -P
|
||||
with-contenv
|
||||
|
||||
importas -u PORT PORT
|
||||
|
||||
if { echo
|
||||
"
|
||||
[INSTALL] 🚀 Starting app (:${PORT})
|
||||
|
||||
" }' > /etc/s6-overlay/s6-rc.d/$APP_NAME/run
|
||||
echo -e "python ${INSTALL_DIR}/server" >> /etc/s6-overlay/s6-rc.d/$APP_NAME/run
|
||||
touch /etc/s6-overlay/s6-rc.d/user/contents.d/{SetupOneshot,crond,php-fpm,nginx,$APP_NAME} /etc/s6-overlay/s6-rc.d/{crond,php-fpm,nginx,$APP_NAME}/dependencies.d/SetupOneshot
|
||||
touch /etc/s6-overlay/s6-rc.d/nginx/dependencies.d/php-fpm
|
||||
touch /etc/s6-overlay/s6-rc.d/$APP_NAME/dependencies.d/nginx
|
||||
|
||||
# this removes the current file
|
||||
# Remove this script since all setup is now done at build time
|
||||
rm -f $0
|
||||
|
||||
Reference in New Issue
Block a user