Complete rewrite of the ubuntu24 installer - #1198
Conversation
Start script deleted and all packed into install script systemd service added for start and stop
adding quotes, simplifying steps, changes to chmods, unifying start/stop of services
pipefail failed ;-)
WalkthroughAdds a unified Ubuntu 24 installer Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Installer as install.sh
participant OS as Apt/OS
participant Git as Git Repo
participant Venv as Python venv (/opt/netalertx-python)
participant Nginx as NGINX
participant PHP as PHP‑FPM
participant Systemd as systemd
participant Server as NetAlertX
User->>Installer: run (must be root)
Installer->>OS: apt update & install packages
Installer->>Git: clone or git‑pull into /app
Installer->>Venv: create venv & pip install requirements.txt
Installer->>Installer: write /app/.env, create buildtimestamp, adjust TZ/PORT/LISTEN_ADDR
Installer->>Nginx: write config & symlink web UI
Installer->>PHP: adjust PHP‑FPM socket/settings
Installer->>Installer: prepare tmpfs mounts, create log files
Installer->>Systemd: install & enable netalertx.service
Installer->>PHP: start PHP‑FPM
Installer->>Nginx: start NGINX
Systemd->>Server: ExecStart -> /opt/netalertx-python/bin/python3 /app/server
Server-->>Systemd: runs (Restart on failure)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
install/ubuntu24/install.sh(1 hunks)install/ubuntu24/install.ubuntu24.sh(0 hunks)install/ubuntu24/netalertx.service(1 hunks)install/ubuntu24/requirements.txt(1 hunks)install/ubuntu24/start.ubuntu24.sh(0 hunks)
💤 Files with no reviewable changes (2)
- install/ubuntu24/install.ubuntu24.sh
- install/ubuntu24/start.ubuntu24.sh
🧰 Additional context used
🪛 Shellcheck (0.11.0)
install/ubuntu24/install.sh
[warning] 125-125: Use "${var:?}" to ensure this never expands to /* .
(SC2115)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: docker_dev
|
|
||
| [Service] | ||
| EnvironmentFile=/app/.env | ||
| ExecStart=/opt/netalertx-python/bin/python /app/server/ |
There was a problem hiding this comment.
Fix ExecStart to launch the real application entry point
ExecStart is pointing Python at /app/server/, but Python cannot execute a directory, so the unit will exit immediately with “Is a directory.” Please call the actual script (or python -m …) and add WorkingDirectory if the code expects to run from /app/server.
🤖 Prompt for AI Agents
In install/ubuntu24/netalertx.service around line 7, ExecStart currently points
to the directory "/app/server/" which causes systemd to fail with “Is a
directory.” Update ExecStart to call the real entrypoint (for example the
absolute path to your script like /app/server/main.py or use the module form -m
your_package) and add a WorkingDirectory=/app/server if the app expects to run
from that directory; ensure the referenced script is executable and use the full
python virtualenv interpreter path (/opt/netalertx-python/bin/python) in
ExecStart.
There was a problem hiding this comment.
@ingoratsdorf Thank you for acknowledging the feedback! If you need any help implementing the fix for the systemd service file - such as identifying the correct entry point script or setting up the WorkingDirectory - feel free to let me know. I'm here to assist with getting the ExecStart directive properly configured.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
install/ubuntu24/install.sh(1 hunks)install/ubuntu24/netalertx.service(1 hunks)install/ubuntu24/requirements.txt(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- install/ubuntu24/netalertx.service
- install/ubuntu24/requirements.txt
🧰 Additional context used
🪛 Shellcheck (0.11.0)
install/ubuntu24/install.sh
[warning] 126-126: Use "${var:?}" to ensure this never expands to /* .
(SC2115)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: docker_dev
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
install/ubuntu24/install.sh(1 hunks)install/ubuntu24/netalertx.service(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- install/ubuntu24/netalertx.service
🧰 Additional context used
🪛 Shellcheck (0.11.0)
install/ubuntu24/install.sh
[warning] 129-129: Use "${var:?}" to ensure this never expands to /* .
(SC2115)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: docker_dev
| #!/usr/bin/env bash | ||
|
|
||
| # 🛑 Important: This is only used for the bare-metal install 🛑 | ||
|
|
||
| echo "---------------------------------------------------------" | ||
| echo "[INSTALL] Starting NetAlertX installation for Ubuntu" | ||
| echo "---------------------------------------------------------" | ||
| echo | ||
| echo "This script will install NetAlertX on your Ubuntu system." | ||
| echo "It will clone the repository, set up necessary files, and start the application." | ||
| echo "Please ensure you have a stable internet connection." | ||
| echo "---------------------------------------------------------" | ||
|
|
||
| # DO NOT CHANGE ANYTHING BELOW THIS LINE! | ||
| INSTALL_DIR=/app | ||
| INSTALL_SYSTEM_NAME=ubuntu24 | ||
| INSTALLER_DIR=${INSTALL_DIR}/install/$INSTALL_SYSTEM_NAME | ||
| CONF_FILE=app.conf | ||
| DB_FILE=app.db | ||
| NGINX_CONF_FILE=netalertx.conf | ||
| WEB_UI_DIR=/var/www/html/netalertx | ||
| NGINX_CONFIG_FILE=/etc/nginx/conf.d/$NGINX_CONF_FILE | ||
| OUI_FILE="/usr/share/arp-scan/ieee-oui.txt" # Define the path to ieee-oui.txt and ieee-iab.txt | ||
| SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| FILEDB=${INSTALL_DIR}/db/${DB_FILE} | ||
| PHPVERSION="8.3" | ||
| VENV_DIR="/opt/netalertx-python" | ||
| # DO NOT CHANGE ANYTHING ABOVE THIS LINE! |
There was a problem hiding this comment.
Add fail-fast guards so broken installs don’t slip through
Right now the script keeps marching even if apt-get, git clone, python3 -m venv, etc. fail. That leaves a half-baked install and the systemd unit dies later with missing deps. Please switch the script into strict mode near the top and explicitly tolerate only the handful of commands you expect to fail (e.g. systemctl stop ... || true, umount ... || true).
#!/usr/bin/env bash
+set -euo pipefail🤖 Prompt for AI Agents
In install/ubuntu24/install.sh around lines 1 to 28, the installer currently
continues on errors; enable strict fail-fast behavior by turning on shell strict
mode (e.g. set -euo pipefail) near the top of the script so any unexpected
command failure causes immediate exit, and then explicitly allow known-possible
failures by appending "|| true" (or checking exit codes) only to those commands
that should be tolerated (for example systemctl stop ..., umount ..., or rm of
non-existent files); ensure critical operations (apt-get, git clone, python3 -m
venv, package installs, service starts) are left to fail the script so the
installer stops on broken installs and add minimal, specific comments by each
tolerated command explaining why it is allowed to fail.
| echo "[INSTALL] Updating the existing installation..." | ||
| cd "${INSTALL_DIR}" || { echo "[INSTALL] Failed to change directory to ${INSTALL_DIR}"; exit 1; } | ||
| # In case there were changes, stash them | ||
| git stash -q | ||
| git pull | ||
| echo "[INSTALL] If there were any local changes, they have been >>STASHED<<" | ||
| echo "[INSTALL] You can recover them with 'git stash pop' in ${INSTALL_DIR}" | ||
| echo |
There was a problem hiding this comment.
Make the git stash step robust for root installs
On real boxes we run this as root, and root usually has no git identity configured. In that case git stash -q errors out with “please tell me who you are”, the script pretends everything was stashed, and the subsequent git pull still fails because the tree is dirty. Please detect pending changes first and either perform the stash with a temporary identity or abort with a clear message when stashing isn’t possible.
- git stash -q
- git pull
- echo "[INSTALL] If there were any local changes, they have been >>STASHED<<"
+ if ! git diff --quiet; then
+ git -c user.name="NetAlertX Installer" -c user.email="installer@netalertx.local" stash push -q || {
+ echo "[INSTALL] Failed to stash local changes (configure git user.name/user.email or commit them before rerunning)."
+ exit 1
+ }
+ stashed=1
+ fi
+ git pull
+ if [ "${stashed:-0}" -eq 1 ]; then
+ echo "[INSTALL] Local changes were stashed. Recover them with 'git stash pop' in ${INSTALL_DIR}"
+ else
+ echo "[INSTALL] No local changes detected before updating."
+ fiCommittable suggestion skipped: line range outside the PR's diff.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
install/ubuntu24/netalertx.service(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: docker_dev
| WorkingDirectory=/opt/netalertx-python/bin | ||
| ExecStart=/opt/netalertx-python/bin/python3 /app/server |
There was a problem hiding this comment.
ExecStart still invokes a directory instead of the app entry point
python3 /app/server still points at the directory, so systemd will exit with “Is a directory” exactly as before. Update ExecStart to call the real script or module (python3 /app/server/<entry>.py or python3 -m netalertx) and set WorkingDirectory to the application path (e.g. /app/server) if the app relies on relative paths.
🤖 Prompt for AI Agents
In install/ubuntu24/netalertx.service around lines 7-8, ExecStart currently runs
"python3 /app/server" which is a directory and causes "Is a directory" errors;
change ExecStart to invoke the actual entry point (for example use the real
script path like /app/server/<entry>.py or run the package as a module with
"python3 -m netalertx") and set WorkingDirectory to the application path (e.g.
/app/server) if the app uses relative paths so systemd starts the correct file.
|
The plugin manager calls |
|
oh, sorry to hear that :/ - I'm not sure at all if relevant, there is a Home Assistant container which is doing some magic, but I didn't implement it myself: https://github.com/alexbelgium/hassio-addons/tree/master/netalertx - again, maybe I'm completely off topic we could also replace the calls in peoples config files if really necessary with a regex expression |
|
I managed to get it sorted. Geez, the documentation for systemd is not really great. Had to google so many sites to get answers. Not even AI was able to help. Testing ATM. Looking good. If all satisfied, I'll open a new PR. |
setup.shandstart.shcombined into a single scriptnetalertx now starts and runs via systemd unit, can be started, stopped and restarted
Amalgamated chmods
tuned chmods based on earlier feedback and discussion
Please have a look, comments welcome :-)
Summary by CodeRabbit
New Features
Chores