Skip to content

fix(linux-scripts): fix linux scripts when systemd is degraded + imp… (#5871)#200

Merged
MarineLeM merged 4 commits into
mainfrom
issue/5871
Jul 2, 2026
Merged

fix(linux-scripts): fix linux scripts when systemd is degraded + imp… (#5871)#200
MarineLeM merged 4 commits into
mainfrom
issue/5871

Conversation

@MarineLeM

@MarineLeM MarineLeM commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Problem Information :

systemctl is-system-running returns a non-zero exit code for any state other than running (e.g. degraded → exit code 1). Combined with set -e, this causes the script to exit immediately, even though degraded is an acceptable state.
Moreover, the script exits silently without any details about what failed

Proposed changes

  • Capture the systemd state without triggering set -e:
    systemd_status=$(systemctl is-system-running 2>/dev/null || true)
    Then explicitly handle each state — accepting running and degraded, otherwise stopping the script with a clear error message.
  • Improve error handling by introducing two helpers:
    - run() — wraps any command and calls die on failure
    - die() — logs the exact command that failed and exits

Testing Instructions

  1. Use linux machine where systemd is degraded
    • to check systemd status : systemctl is-system-running
  2. install openaev agent
  3. the installation should work

Related issues

@github-actions

Copy link
Copy Markdown

Thank you for your contribution. This PR is but one step away from being ready for merging: all commits must be PGP-signed. To get started, please see https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

@github-actions github-actions Bot added the filigran team Item from the Filigran team. label Jun 26, 2026
@Filigran-Automation Filigran-Automation changed the title fix(linux-scripts) : fix linux scripts when systemd is degraded + imp… fix(linux-scripts): fix linux scripts when systemd is degraded + imp… (#5871) Jun 26, 2026
@Filigran-Automation

Copy link
Copy Markdown
Contributor

🤖 [AI-generated]

Hey @MarineLeM! 👋 Thanks a lot for opening PR #200 — really appreciate the fix for the degraded-systemd installation path! 🙏

I just had a quick look and I think the description could be enhanced a little to help reviewers get through it faster. I haven't changed anything in your description — just a gentle suggestion:

Area What could help Suggestion
### Proposed changes The two bullets are currently empty, so reviewers can't see what changed or why A couple of lines on what was adjusted across the 6 installer/upgrade scripts (e.g. how degraded systemd is detected/handled) and why it fixes the failing install

Nice touch already having concrete Testing Instructions and the linked issue (#5871) — that really helps! 🙌

💡 If helpful, the contribution conventions / PR template walk through what to include.

No rush at all — thanks again for contributing to OpenAEV! 🚀

@MarineLeM MarineLeM self-assigned this Jun 26, 2026
@MarineLeM MarineLeM marked this pull request as ready for review June 26, 2026 12:16
Copilot AI review requested due to automatic review settings June 26, 2026 12:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Linux installer/upgrade shell scripts to tolerate systemctl is-system-running returning a non-zero exit code for acceptable states (notably degraded) and to improve failure diagnostics by introducing small log/die/run helpers.

Changes:

  • Capture systemd status without tripping set -e and treat running + degraded as acceptable states.
  • Introduce log(), die(), and run() helpers to standardize error handling and messages.
  • Improve install-time filesystem checks and replace silent exits with explicit error messages.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
installer/linux/agent-upgrade.sh Adds log/die/run and systemd-state handling; refactors upgrade + reinstall flow.
installer/linux/agent-upgrade-session-user.sh Same systemd-state handling + helper functions for session-user upgrade path.
installer/linux/agent-upgrade-service-user.sh Same systemd-state handling + helper functions for service-user upgrade path.
installer/linux/agent-installer.sh Same systemd-state handling + helper functions; improves install directory checks and service setup flow.
installer/linux/agent-installer-session-user.sh Same systemd-state handling + helper functions for session-user installer path.
installer/linux/agent-installer-service-user.sh Same systemd-state handling + helper functions for service-user installer path and argument validation errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread installer/linux/agent-upgrade.sh Outdated
rm -f ${uninstall_dir}/openbas-agent
systemctl disable ${uninstall_service} --now
) || (echo "Error while uninstalling OpenBAS Agent" >&2 && exit 1)
run curl -sSfLG ${base_url}/api/tenants/${tenant_id}/agent/installer/openaev/${os}/service/${OPENAEV_TOKEN} --data-urlencode "installationDir=${openaev_dir}" --data-urlencode "serviceName=${openaev_service}" | sh
log "01. Installing OpenAEV Agent..."
openaev_session=$(printf %s "${session_name}" | sed 's/openbas/openaev/g')
curl -sSfLG ${base_url}/api/tenants/${tenant_id}/agent/installer/openaev/${os}/session-user/${OPENAEV_TOKEN} --data-urlencode "installationDir=${openaev_dir}" --data-urlencode "serviceName=${openaev_session}" | sh
run curl -sSfLG ${base_url}/api/tenants/${tenant_id}/agent/installer/openaev/${os}/session-user/${OPENAEV_TOKEN} --data-urlencode "installationDir=${openaev_dir}" --data-urlencode "serviceName=${openaev_session}" | sh
Comment thread installer/linux/agent-upgrade.sh Outdated
Comment thread installer/linux/agent-installer.sh Outdated
Comment thread installer/linux/agent-installer-service-user.sh Outdated
MarineLeM and others added 2 commits July 1, 2026 10:56
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@EvaE-Filigran

EvaE-Filigran commented Jul 1, 2026

Copy link
Copy Markdown

🧪 Test Matrix — Agent Install / Update / Execution (In Progress)

Legend

  • Degraded: systemctl is-system-runningdegraded (at least one systemd unit in failed state)
  • No degraded: systemctl is-system-runningrunning

🏗️ ARM64 (aarch64)

Install

  • service — running
  • service — degraded
  • session-user — running
  • session-user — degraded
  • service-user — running
  • service-user — degraded

Update

  • service — running
  • service — degraded
  • session-user — running
  • session-user — degraded
  • service-user — running
  • service-user — degraded

Execution

  • service — running
  • service — degraded
  • session-user — running
  • session-user — degraded
  • service-user — running
  • service-user — degraded

🏗️ x86_64 (amd64) FAILED❌

Install

  • service — running
  • service — degraded
  • session-user — running
  • session-user — degraded
  • service-user — running
  • service-user — degraded

Update

  • service — running
  • service — degraded
  • session-user — running
  • session-user — degraded
  • service-user — running
  • service-user — degraded

Execution

  • service — running
  • service — degraded
  • session-user — running
  • session-user — degraded
  • service-user — running
  • service-user — degraded

✅ Acceptance Criteria

  • All installs create the systemd unit correctly
  • Agent registers in OpenAEV UI after install
  • Update preserves existing configuration
  • Execution completes and reports status back to platform
  • No crash or hang in degraded mode
  • No regression between arm64 and x86_64

📋 Environment Details

ARM64 x86_64
VM Tool Multipass UTM (emulated)
OS Ubuntu 22.04 Ubuntu 22.04
Arch check uname -maarch64 uname -mx86_64

🔧 How to simulate degraded mode

# Force systemd into "degraded" state
sudo bash -c 'cat > /etc/systemd/system/fake-degraded.service <<EOF
[Unit]
Description=Fake service to simulate degraded state
[Service]
Type=oneshot
ExecStart=/bin/false
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF'
sudo systemctl daemon-reload
sudo systemctl start fake-degraded.service
systemctl is-system-running  # → degraded

@EvaE-Filigran

Copy link
Copy Markdown

PR Test Results — Linux Agent Install Fix

Environment: Tested on both x86 and arm64 Linux VMs.

Observations

  1. Bug reproduction: Successfully reproduced the original bug on both x86 and arm64 architectures.

  2. arm64 — ✅ Pass:

    • Tested the new install and update scripts on an arm64 instance.
    • Works correctly in both degraded and non-degraded states.
  3. x86 — ⚠️ Partial fix:

    • The original install error is no longer displayed (initial bug is resolved for this issue).
    • However, after installation, the service immediately enters a failed state:
      openaev-agent.service  loaded failed failed  OpenAEV Agent
      
    • This appears to be a separate bug in the x86 executable itself.
    • As a result, the agent is currently not usable on Linux x86 architectures.

Conclusion

The PR successfully fixes the original install script issue on both architectures. However, a separate, pre-existing bug in the x86 agent binary prevents the service from running on x86 — this should be tracked in a dedicated issue.

@EvaE-Filigran EvaE-Filigran self-requested a review July 2, 2026 12:32
@MarineLeM MarineLeM merged commit 8e97512 into main Jul 2, 2026
22 checks passed
@MarineLeM MarineLeM deleted the issue/5871 branch July 2, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

filigran team Item from the Filigran team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Linux agent deployment fails with curl | sh command

4 participants