From a979a80bed70e34c043826607f7cf2f7cd5dfec6 Mon Sep 17 00:00:00 2001 From: Ingo Ratsdorf Date: Sat, 11 Oct 2025 10:39:03 +1300 Subject: [PATCH 1/8] Updates to installer service At system restart, the api and log mounts are not there and thus the UI does not start due to failures. Introducing a pre-start service section to set those up --- install/ubuntu24/pre-start.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 install/ubuntu24/pre-start.sh diff --git a/install/ubuntu24/pre-start.sh b/install/ubuntu24/pre-start.sh new file mode 100755 index 000000000..09c0e467e --- /dev/null +++ b/install/ubuntu24/pre-start.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +# 🛑 Important: This is only used for the bare-metal install 🛑 + +# DO NOT CHANGE ANYTHING BELOW THIS LINE! +INSTALL_DIR=/app +INSTALL_SYSTEM_NAME=ubuntu24 +INSTALLER_DIR=${INSTALL_DIR}/install/$INSTALL_SYSTEM_NAME +SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# DO NOT CHANGE ANYTHING ABOVE THIS LINE! + +# unmounting in case already mounted +umount "${INSTALL_DIR}/log" 2>/dev/null +umount "${INSTALL_DIR}/api" 2>/dev/null + +rm -R "${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" +mount -t tmpfs -o noexec,nosuid,nodev tmpfs "${INSTALL_DIR}/api" + + +# 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" From 75e17997bc8076405f34242c413f998b4fbb21b0 Mon Sep 17 00:00:00 2001 From: Ingo Ratsdorf Date: Sat, 11 Oct 2025 10:39:45 +1300 Subject: [PATCH 2/8] updates --- install/ubuntu24/netalertx.service | 1 + 1 file changed, 1 insertion(+) diff --git a/install/ubuntu24/netalertx.service b/install/ubuntu24/netalertx.service index 3540956ec..3df667040 100755 --- 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/ash -c "${INSTALLER_DIR}/pre-start.sh" ExecStart=/usr/bin/python3 "${INSTALL_DIR}/server" Restart=on-failure Type=simple From d13ca83e4a74c3b2eddd3089eefd96c7b1619fcd Mon Sep 17 00:00:00 2001 From: Ingo Ratsdorf Date: Sat, 11 Oct 2025 11:10:55 +1300 Subject: [PATCH 3/8] Fixes Updates fo file executable bits and using bash for source command and automatically getting environment variables --- install/ubuntu24/netalertx.conf | 0 install/ubuntu24/netalertx.service | 2 +- install/ubuntu24/pre-start.sh | 15 ++++++++------- install/ubuntu24/requirements.txt | 0 4 files changed, 9 insertions(+), 8 deletions(-) mode change 100755 => 100644 install/ubuntu24/netalertx.conf mode change 100755 => 100644 install/ubuntu24/netalertx.service mode change 100755 => 100644 install/ubuntu24/requirements.txt 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 3df667040..8c90cb370 --- a/install/ubuntu24/netalertx.service +++ b/install/ubuntu24/netalertx.service @@ -4,7 +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/ash -c "${INSTALLER_DIR}/pre-start.sh" +ExecStartPre=/usr/bin/bash -c "${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 index 09c0e467e..9d51ae969 100755 --- a/install/ubuntu24/pre-start.sh +++ b/install/ubuntu24/pre-start.sh @@ -1,13 +1,14 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # 🛑 Important: This is only used for the bare-metal install 🛑 -# DO NOT CHANGE ANYTHING BELOW THIS LINE! -INSTALL_DIR=/app -INSTALL_SYSTEM_NAME=ubuntu24 -INSTALLER_DIR=${INSTALL_DIR}/install/$INSTALL_SYSTEM_NAME -SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -# DO NOT CHANGE ANYTHING ABOVE THIS LINE! +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 diff --git a/install/ubuntu24/requirements.txt b/install/ubuntu24/requirements.txt old mode 100755 new mode 100644 From eb170a073dc22cdea3743282d2f318bad3565606 Mon Sep 17 00:00:00 2001 From: Ingo Ratsdorf Date: Sat, 11 Oct 2025 18:38:53 +1300 Subject: [PATCH 4/8] Deleted api and log creation from install script This is now part of the pre-start script --- install/ubuntu24/install.sh | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/install/ubuntu24/install.sh b/install/ubuntu24/install.sh index 8327d5179..b0c5aaa6d 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 moints are not there yet # DANGER ZONE: ALWAYS_FRESH_INSTALL From e1dd23cad8a5d054e51ef13643eb950cb4e4e208 Mon Sep 17 00:00:00 2001 From: Ingo Ratsdorf Date: Sat, 11 Oct 2025 22:32:51 +1300 Subject: [PATCH 5/8] Update install/ubuntu24/install.sh Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- install/ubuntu24/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/ubuntu24/install.sh b/install/ubuntu24/install.sh index b0c5aaa6d..0fa49e75b 100755 --- a/install/ubuntu24/install.sh +++ b/install/ubuntu24/install.sh @@ -252,7 +252,7 @@ fi # 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 moints are not there yet +# Otherwise the system does not work as the tmp mount points are not there yet # DANGER ZONE: ALWAYS_FRESH_INSTALL From d48601813030ebab248878dd4604e965d585634a Mon Sep 17 00:00:00 2001 From: Ingo Ratsdorf Date: Sat, 11 Oct 2025 22:33:31 +1300 Subject: [PATCH 6/8] Update install/ubuntu24/netalertx.service Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- install/ubuntu24/netalertx.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/ubuntu24/netalertx.service b/install/ubuntu24/netalertx.service index 8c90cb370..94bf444c6 100644 --- a/install/ubuntu24/netalertx.service +++ b/install/ubuntu24/netalertx.service @@ -4,7 +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 -c "${INSTALLER_DIR}/pre-start.sh" +ExecStartPre=/usr/bin/bash "${INSTALLER_DIR}/pre-start.sh" ExecStart=/usr/bin/python3 "${INSTALL_DIR}/server" Restart=on-failure Type=simple From de07fa2345b3f53e124dae163d00c81d0cc19f89 Mon Sep 17 00:00:00 2001 From: Ingo Ratsdorf Date: Sat, 11 Oct 2025 22:34:53 +1300 Subject: [PATCH 7/8] Update install/ubuntu24/pre-start.sh Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- install/ubuntu24/pre-start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/ubuntu24/pre-start.sh b/install/ubuntu24/pre-start.sh index 9d51ae969..34978a9ee 100755 --- a/install/ubuntu24/pre-start.sh +++ b/install/ubuntu24/pre-start.sh @@ -14,7 +14,7 @@ fi umount "${INSTALL_DIR}/log" 2>/dev/null umount "${INSTALL_DIR}/api" 2>/dev/null -rm -R "${INSTALL_DIR}/log/*" "${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" From 7e3381b9a8eacc41e1eb86e13a71f8ca685c6f0e Mon Sep 17 00:00:00 2001 From: Ingo Ratsdorf Date: Sat, 11 Oct 2025 22:36:09 +1300 Subject: [PATCH 8/8] Update install/ubuntu24/pre-start.sh Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- install/ubuntu24/pre-start.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/install/ubuntu24/pre-start.sh b/install/ubuntu24/pre-start.sh index 34978a9ee..46785e043 100755 --- a/install/ubuntu24/pre-start.sh +++ b/install/ubuntu24/pre-start.sh @@ -18,8 +18,14 @@ 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" -mount -t tmpfs -o noexec,nosuid,nodev tmpfs "${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