Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@ingoratsdorf
Copy link
Contributor

@ingoratsdorf ingoratsdorf commented Oct 11, 2025

  • 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.
  • Updates to exec bits to files, fixed the pre-start script to use bash for env import and security check.
  • Using bash for source command and automatically getting environment variables.
  • Deleted api and log creation from install script. This is now part of the pre-start script

Summary by CodeRabbit

  • Refactor

    • Moved log and API tmpfs setup from installer to a service pre-start step so mounts are prepared at service startup.
  • Chores

    • Added a pre-start routine to clean previous mounts, create required directories/files, mount tmpfs for logs and API, and enforce secure ownership/permissions.
    • Updated the service to run the pre-start routine before launching.
    • Removed redundant log/API setup from the installer.

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
Updates fo file executable bits and using bash for source command and automatically getting environment variables
This is now part of the pre-start script
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 11, 2025

Walkthrough

Tmpfs creation and initialization for log and api were removed from install.sh and moved into a new pre-start.sh. The systemd unit now runs this pre-start script via ExecStartPre to prepare directories, mounts, permissions, and required files before service start.

Changes

Cohort / File(s) Summary
Ubuntu24 installer script
install/ubuntu24/install.sh
Removed inline tmpfs creation/mount and log/api initialization; added note that those steps are handled by pre-start.sh.
Pre-start initialization
install/ubuntu24/pre-start.sh
New script: sources /etc/default/netalertx, validates INSTALL_DIR, unmounts previous mounts, creates directories/files, mounts tmpfs for log and api, sets ownership (www-data) and permissions.
Systemd unit
install/ubuntu24/netalertx.service
Added ExecStartPre=/usr/bin/bash ${INSTALLER_DIR}/pre-start.sh to run pre-start initialization before the main ExecStart.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor systemd
  participant unit as netalertx.service
  participant pre as pre-start.sh
  participant fs as Filesystem
  participant app as NetAlertX

  systemd->>unit: Start unit
  Note over unit: ExecStartPre (new) runs before ExecStart
  unit->>pre: /usr/bin/bash ${INSTALLER_DIR}/pre-start.sh
  pre->>fs: Unmount previous mounts (if any)
  pre->>fs: Create dirs/files (INSTALL_DIR/log, INSTALL_DIR/api, logs, plugins, user_notifications.json)
  pre->>fs: Mount tmpfs for log and api
  pre->>fs: chown/chmod (www-data, perms)
  pre-->>unit: exit 0
  unit->>app: ExecStart (unchanged) -> run server
  app-->>unit: Running
  unit-->>systemd: Active
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Ubuntu 24 Installer rewrite #1201 — Touches Ubuntu24 installer/service flow and tmpfs handling; directly overlaps service/unit changes.
  • Installer rework #1174 — Refactors log/api mount and initialization logic similar to this PR’s relocation to a pre-start script.
  • Ubuntu installer #1166 — Adjusts installer/startup tmpfs management for log/api; conceptually linked to moving mounts into ExecStartPre.

Poem

I thump my paws: pre-start trims the heap,
Mounts neat clouds where logs and APIs sleep.
Directories ready, permissions in line,
I twitch my nose — the service will shine.
Hoppity-hop, clean start every time. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly indicates updates to the Ubuntu24 installer service, reflecting the changes to service configuration and installer scripts without extraneous detail and making clear the context of the modifications.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
install/ubuntu24/pre-start.sh (1)

5-10: Consider adding error handling for the source command.

If /etc/default/netalertx doesn't exist or fails to source, the script continues and only fails later when checking INSTALL_DIR. Adding explicit error handling would provide clearer diagnostics.

Apply this diff to improve error handling:

-source /etc/default/netalertx
+source /etc/default/netalertx || {
+  echo "[NetAlertX Pre-Start] Failed to source /etc/default/netalertx"
+  exit 1
+}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8b62de and eb170a0.

📒 Files selected for processing (3)
  • install/ubuntu24/install.sh (1 hunks)
  • install/ubuntu24/netalertx.service (1 hunks)
  • install/ubuntu24/pre-start.sh (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
🔇 Additional comments (1)
install/ubuntu24/netalertx.service (1)

7-7: INSTALLER_DIR is correctly exported
install/ubuntu24/install.sh creates /etc/default/netalertx and writes INSTALLER_DIR (alongside the other env vars) before enabling and starting the service.

install/ubuntu24/install.sh Outdated Show resolved Hide resolved
install/ubuntu24/netalertx.service Outdated Show resolved Hide resolved
install/ubuntu24/pre-start.sh Outdated Show resolved Hide resolved
install/ubuntu24/pre-start.sh Outdated Show resolved Hide resolved
ingoratsdorf and others added 4 commits October 11, 2025 22:32
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
install/ubuntu24/install.sh (1)

279-285: Guard api/log ownership and perms to avoid noisy errors pre–pre-start.

If pre-start hasn’t run yet, ${INSTALL_DIR}/api/user_notifications.json and ${INSTALL_DIR}/log may not exist. Guard existence or silence benign failures.

Apply:

-if [ -f "$FILEDB" ]; then
-    chown -R www-data:www-data "$FILEDB"
-fi
-chown root:www-data "${INSTALL_DIR}"/api/user_notifications.json
+if [ -f "$FILEDB" ]; then
+  chown -R www-data:www-data "$FILEDB"
+fi
+if [ -f "${INSTALL_DIR}/api/user_notifications.json" ]; then
+  chown root:www-data "${INSTALL_DIR}/api/user_notifications.json"
+fi
 chgrp -R www-data "${INSTALL_DIR}"
 chmod -R u+rwx,g+rwx,o=rx "$WEB_UI_DIR"
 chmod -R u+rwx,g+rwx,o=rx "${INSTALL_DIR}"
-chmod -R u+rwX,g+rwX,o=rX "${INSTALL_DIR}/log"
+if [ -d "${INSTALL_DIR}/log" ]; then
+  chmod -R u+rwX,g+rwX,o=rX "${INSTALL_DIR}/log"
+fi
 chmod -R u+rwX,g+rwX,o=rX "${INSTALL_DIR}/config"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb170a0 and 7e3381b.

📒 Files selected for processing (3)
  • install/ubuntu24/install.sh (1 hunks)
  • install/ubuntu24/netalertx.service (1 hunks)
  • install/ubuntu24/pre-start.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • install/ubuntu24/pre-start.sh
  • install/ubuntu24/netalertx.service
⏰ 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

Comment on lines +253 to +255
# 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
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).

@adamoutler
Copy link
Contributor

Hello @ingoratsdorf . I've noticed lot of commits from you on the hardware installers. I'm watching and worried because I'm in the middle of a month's long revamp of the main docker container, docker compose, and devcontainer, working toward a new and more secure, reliable, unified user/developer experience.

I'd like it if you could please try to focus on making this a single script which deploys everything required with a single copy-paste operation. The hardware installers are not officially supported due to lack of ability to cleanly uninstall/reinstall on a hardware installation. They will be moving into docs only soon. Combining the installer into a document will make your work live longer eg cat << EOF > file.txt .

Currently the hardware installers all download the code directly from the github repository making them entirely separate from the code, and not actually needing to be located within the code. Because they aren't actually part of the repo, they can't be tested with the repo. The upcoming changes will likely break a lot of things and I'd like you to be prepared for these changes.

@JVKeller
Copy link
Contributor

JVKeller commented Nov 6, 2025

@ingoratsdorf I think we should combine the best of both scripts and just have one, non docker, installer.

The one I did for proxmox will work on ubuntu as well, but I do have to address an issue with the tmps file mount strategy.
Since it's a temp filesystem, it's not there if the server reboots so the service fails to restart. 🤦‍♂️🤷‍♀️

I haven't had the chance to mess with that, I need to finish a server upgrade so I can use this with multiple VLAN's.

@ingoratsdorf
Copy link
Contributor Author

@JVKeller yes, I noticed that, after restart of the server / container, the tmpfs is gone.
Hence I updated the systemd unit to create those on start. That was part of this PR.

The bare metal installer have to change significantly now that we have a production file system.
I just glanced over the dockerfile but did not have an in-depth look.
It is so haevily geared towards docker now that it seems very complicated to mimic what the dockerfile does and keep up with changes tro it - and the security and hardening aspects.

I think I'll drop work on the bare metal installer and use an Alpine docker LXC again ;-)

@adamoutler
Copy link
Contributor

The proxmox should really be called debian 13 not proxmox. It's designed to support Debian 13. A proper proxmox script would setup an environment within proxmox and then install.

@JVKeller
Copy link
Contributor

After you're done with the code base overhaul, we'll revisit this and maybe make it a full fledged Proxmox installer and add it to the proxmox helper scripts repo.

I never even fully got NetAlertx working for my network. It wasn't picking up devices on other VLAN's, and adding additional eth devices wasn't working for me either so I have to look at my network config but haven't had the time.

@adamoutler
Copy link
Contributor

Layer 2 scanners don't cross network boundaries. You'll need to use one of the higher layer scanners.

@jokob-sk
Copy link
Owner

jokob-sk commented Dec 9, 2025

If someone can have a look that would be great - we are not planning to touch the file structure for a while. One proxmox related issue reported here as well #1336

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.