Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions install/ubuntu24/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +253 to +255
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Pre-start move looks good; verify systemd variable expansion and env wiring.

Ensure netalertx.service either:

  • uses an absolute path in ExecStartPre, or
  • uses /usr/bin/bash -lc '<cmd>' (or -c) with EnvironmentFile=/etc/default/netalertx so ${INSTALLER_DIR} expands. Plain ExecStartPre=/usr/bin/bash ${INSTALLER_DIR}/pre-start.sh won’t expand ${…} under systemd.

Run:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== netalertx.service ExecStartPre and env =="
rg -nC3 -e '^(Environment(File)?=|ExecStartPre=)' install/ubuntu24/netalertx.service || true

echo
echo "== Full ExecStartPre lines =="
rg -n 'ExecStartPre=' install/ubuntu24/netalertx.service

echo
echo "== pre-start.sh shebang and header =="
sed -n '1,25p' install/ubuntu24/pre-start.sh || true

Length of output: 1252


Fix ExecStartPre in netalertx.service to expand ${INSTALLER_DIR}

In install/ubuntu24/netalertx.service, replace

ExecStartPre=/usr/bin/bash "${INSTALLER_DIR}/pre-start.sh"

with

ExecStartPre=/usr/bin/bash -c '$INSTALLER_DIR/pre-start.sh'

so the shell expands the environment variable before running the script.

🤖 Prompt for AI Agents
In install/ubuntu24/install.sh around lines 253 to 255, the systemd unit's
ExecStartPre currently uses a quoted literal path that prevents ${INSTALLER_DIR}
expansion; update the unit generation to use ExecStartPre=/usr/bin/bash -c
'$INSTALLER_DIR/pre-start.sh' (i.e. invoke bash -c with the single-quoted
command so the shell expands the environment variable and runs the pre-start.sh
from the installer directory).



# DANGER ZONE: ALWAYS_FRESH_INSTALL
Expand Down
Empty file modified install/ubuntu24/netalertx.conf
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions install/ubuntu24/netalertx.service
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions install/ubuntu24/pre-start.sh
Original file line number Diff line number Diff line change
@@ -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"
Empty file modified install/ubuntu24/requirements.txt
100755 → 100644
Empty file.