diff --git a/install/ubuntu24/install.sh b/install/ubuntu24/install.sh index 8327d5179..0fa49e75b 100755 --- a/install/ubuntu24/install.sh +++ b/install/ubuntu24/install.sh @@ -250,29 +250,9 @@ else fi fi -echo "---------------------------------------------------------" -echo "[INSTALL] Create log and api mounts" -echo "---------------------------------------------------------" -echo - -echo "[INSTALL] Cleaning up old mounts if any" -umount "${INSTALL_DIR}/log" -umount "${INSTALL_DIR}/api" - -echo "[INSTALL] Creating log and api folders if they don't exist" -mkdir -p "${INSTALL_DIR}/log" "${INSTALL_DIR}/api" - -echo "[INSTALL] Mounting log and api folders as tmpfs" -mount -t tmpfs -o noexec,nosuid,nodev tmpfs "${INSTALL_DIR}/log" -mount -t tmpfs -o noexec,nosuid,nodev tmpfs "${INSTALL_DIR}/api" - - -# Create log files if they don't exist -echo "[INSTALL] Creating 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 +# We moved the log and api folder creation to the pre-start script +# Ref pre-start.sh +# Otherwise the system does not work as the tmp mount points are not there yet # DANGER ZONE: ALWAYS_FRESH_INSTALL diff --git a/install/ubuntu24/netalertx.conf b/install/ubuntu24/netalertx.conf old mode 100755 new mode 100644 diff --git a/install/ubuntu24/netalertx.service b/install/ubuntu24/netalertx.service old mode 100755 new mode 100644 index 3540956ec..94bf444c6 --- a/install/ubuntu24/netalertx.service +++ b/install/ubuntu24/netalertx.service @@ -4,6 +4,7 @@ Description=NetAlertX - Network, presence scanner and alert framework [Service] EnvironmentFile=/etc/default/netalertx PassEnvironment=INSTALL_SYSTEM_NAME INSTALLER_DIR INSTALL_DIR PHPVERSION VIRTUAL_ENV PATH +ExecStartPre=/usr/bin/bash "${INSTALLER_DIR}/pre-start.sh" ExecStart=/usr/bin/python3 "${INSTALL_DIR}/server" Restart=on-failure Type=simple diff --git a/install/ubuntu24/pre-start.sh b/install/ubuntu24/pre-start.sh new file mode 100755 index 000000000..46785e043 --- /dev/null +++ b/install/ubuntu24/pre-start.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# 🛑 Important: This is only used for the bare-metal install 🛑 + +source /etc/default/netalertx + +if [ -z "${INSTALL_DIR}" ]; then + echo "[NetAlertX Pre-Start] INSTALL_DIR Variable is not defined or is empty." + exit 1 +fi + + +# unmounting in case already mounted +umount "${INSTALL_DIR}/log" 2>/dev/null +umount "${INSTALL_DIR}/api" 2>/dev/null + +rm -rf "${INSTALL_DIR}"/log/* "${INSTALL_DIR}"/api/* 2>/dev/null + +mkdir -p "${INSTALL_DIR}/log" "${INSTALL_DIR}/api" + +mount -t tmpfs -o noexec,nosuid,nodev tmpfs "${INSTALL_DIR}/log" || { + echo "[NetAlertX Pre-Start] Failed to mount tmpfs at ${INSTALL_DIR}/log" + exit 1 +} +mount -t tmpfs -o noexec,nosuid,nodev tmpfs "${INSTALL_DIR}/api" || { + echo "[NetAlertX Pre-Start] Failed to mount tmpfs at ${INSTALL_DIR}/api" + exit 1 +} + + +# Create 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 + + +chgrp -R www-data "${INSTALL_DIR}/log" "${INSTALL_DIR}/api" +chmod -R u+rwx,g+rwx,o=rx "${INSTALL_DIR}/api" +chmod -R u+rwX,g+rwX,o=rX "${INSTALL_DIR}/log" diff --git a/install/ubuntu24/requirements.txt b/install/ubuntu24/requirements.txt old mode 100755 new mode 100644