Skip to content

[orbit/packaging] delay restart for in-band pkg upgrade on Linux - #31286

Merged
getvictor merged 1 commit into
fleetdm:mainfrom
fuhry:delay-restart-on-inband-upgrade
Jul 28, 2025
Merged

[orbit/packaging] delay restart for in-band pkg upgrade on Linux#31286
getvictor merged 1 commit into
fleetdm:mainfrom
fuhry:delay-restart-on-inband-upgrade

Conversation

@fuhry

@fuhry fuhry commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

Admins should be upgrading orbit/osqueryd/fleet-desktop using TUF, but there's no official path for pushing updates to the orbit environment file (/etc/default/orbit).

Knowing that this file is installed by fleet-osquery, I naively pushed a new fleet-osquery package to a user's machine, thinking that would be fine installing over the existing package. Instead it actually broke orbit entirely on the host, rendering it unreachable until the user manually reinstalled the package. This is because the pre-removal script unconditionally stops orbit even if it's being upgraded, and when orbit is stopped it terminates any processes underneath it, including the ongoing package installation.

To workaround this, we replace the simple
systemctl restart orbit.service with a check for the INSTALLER_PATH environment variable that orbit sets during software installations. If the variable is present, systemd-run is used to schedule the service restart 60 seconds in the future, which is assumed to be more than enough time for the package manager to finish and exit. Unfortunately, this bugfix cannot be made retroactive, because the broken version of the prerm script is called before the new package starts to be unpacked/installed.

Although there are other ways of doing anything an administrator might be trying to accomplish by pushing a new fleet-osquery package, bricking an endpoint simply by pushing this package through the Software page seems like a pretty massive footgun that is easy to protect against.

Summary by CodeRabbit

  • New Features

    • Added support for safe in-band upgrades of DEB and RPM packages generated by the fleetctl package command via the Software page, after an initial manual update.
  • Documentation

    • Added a note clarifying the new upgrade process and the need for a one-time manual update before using in-band upgrades.
  • Bug Fixes

    • Improved upgrade scripts to prevent the Orbit service from stopping unexpectedly during package upgrades, ensuring smoother and safer updates.

@fuhry
fuhry requested a review from a team as a code owner July 25, 2025 18:50
@coderabbitai

coderabbitai Bot commented Jul 25, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This update changes how the DEB and RPM packages for Orbit handle upgrades. It adds logic to safely restart the Orbit service during in-band upgrades and improves the uninstall scripts to avoid stopping the service unnecessarily during upgrades. Documentation is updated to explain the new upgrade process.

Changes

Cohort / File(s) Change Summary
Packaging scripts logic
orbit/pkg/packaging/linux_shared.go
Introduces a reusable shell script (postInstallSafeRestart) for safer service restarts during upgrades. Updates post-install and pre-remove scripts to prevent stopping Orbit during upgrades, using environment checks and argument parsing to distinguish between uninstall and upgrade. Adds a constant for the new script snippet.
Documentation and notes
orbit/changes/31286-package-upgrade-fix
Adds a note explaining the new upgrade process: packages are now safe to upgrade in-band after an initial out-of-band update, due to changes in how the pre-removal script handles service stopping and restarting.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 809c493 and 935afc7.

📒 Files selected for processing (2)
  • orbit/changes/31286-package-upgrade-fix (1 hunks)
  • orbit/pkg/packaging/linux_shared.go (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
orbit/changes/31286-package-upgrade-fix (1)

Learnt from: getvictor
PR: #30589
File: server/fleet/datastore.go:13-14
Timestamp: 2025-07-08T16:12:48.182Z
Learning: The Fleet team is not currently testing or enforcing OSS build compatibility, so imports of enterprise-only packages (like ee/server/service/hostidentity/types) into OSS code are acceptable for now.

orbit/pkg/packaging/linux_shared.go (2)

Learnt from: sgress454
PR: #30882
File: orbit/pkg/user/user_linux.go:81-85
Timestamp: 2025-07-15T18:49:38.237Z
Learning: In orbit/pkg/user/user_linux.go, when finding systemd processes for SELinux context retrieval, there should typically only be one active systemd process per user under normal conditions. Multiple systemd processes may exist temporarily during crashes or reboots, but in those cases the newest one (obtained with pgrep -nx systemd) is the correct choice.

Learnt from: sgress454
PR: #30882
File: orbit/pkg/user/user_linux.go:75-100
Timestamp: 2025-07-15T18:52:39.239Z
Learning: In orbit/pkg/user/user_linux.go, for the GetUserContext function, the user considers PID validation unnecessary when using pgrep -nx systemd because pgrep with these flags should only return valid numeric PIDs, making additional validation overkill.

🔇 Additional comments (6)
orbit/pkg/packaging/linux_shared.go (5)

22-39: Well-designed solution for in-band upgrade safety.

This constant provides a thoughtful approach to preventing orbit from terminating itself during package upgrades. The logic correctly checks for the INSTALLER_PATH environment variable to detect in-band upgrades and uses systemd-run with a 60-second delay to allow the package installation to complete.

The fallback handling when systemd-run is unavailable is appropriate - it's better to skip the restart than risk breaking the installation.


389-389: Safe restart integration looks good.

The integration of postInstallSafeRestart into the post-install template replaces the direct systemctl restart call, which addresses the core issue described in the PR objectives.


413-429: Excellent documentation of package manager differences.

This comment block clearly explains the different behaviors between Debian and RPM package managers during upgrades. The references to official documentation are helpful for future maintainers.


435-442: Smart conditional logic for upgrade vs. uninstall scenarios.

The case statement correctly handles the different argument patterns between Debian and RPM systems:

  • Debian: "upgrade" vs "remove"/"deconfigure"
  • RPM: "1" (upgrade) vs "0" (uninstall)

This prevents the service from being stopped during upgrades while still allowing proper cleanup during actual uninstalls.


483-483: Consistent safe restart usage in RPM post-transaction script.

The RPM post-transaction script also uses the postInstallSafeRestart snippet, ensuring consistent behavior across both DEB and RPM package formats.

orbit/changes/31286-package-upgrade-fix (1)

1-3: Clear and helpful documentation for users.

This documentation does a nice job explaining both the improvement and the important caveat about needing an initial out-of-band update. The explanation of why this one-time update is necessary (due to the old pre-removal script behavior) helps users understand the reasoning behind the requirement.

This aligns well with the implementation changes in linux_shared.go where the pre-removal scripts were updated to handle upgrades properly.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@fuhry
fuhry force-pushed the delay-restart-on-inband-upgrade branch from 6726ab6 to 8ac2fbb Compare July 25, 2025 18:51
@codecov

codecov Bot commented Jul 25, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.04%. Comparing base (809c493) to head (935afc7).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #31286      +/-   ##
==========================================
- Coverage   62.04%   62.04%   -0.01%     
==========================================
  Files        1912     1912              
  Lines      188280   188303      +23     
  Branches     5548     5548              
==========================================
+ Hits       116827   116840      +13     
- Misses      62117    62125       +8     
- Partials     9336     9338       +2     
Flag Coverage Δ
backend 62.71% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Admins _should_ be upgrading orbit/osqueryd/fleet-desktop using TUF, but
there's no official path for pushing updates to the orbit environment file
(`/etc/default/orbit`).

Knowing that this file is installed by fleet-osquery, I naively pushed a
new fleet-osquery package to a user's machine, thinking that would be
fine installing over the existing package. Instead it actually broke
orbit entirely on the host, rendering it unreachable until the user
manually reinstalled the package. This is because the pre-removal script
unconditionally stops orbit even if it's being upgraded, and when orbit
is stopped it terminates any processes underneath it, including the
ongoing package installation.

To workaround this, we replace the simple
`systemctl restart orbit.service` with a check for the `INSTALLER_PATH`
environment variable that orbit sets during software installations. If
the variable is present, `systemd-run` is used to schedule the service
restart 60 seconds in the future, which is assumed to be more than
enough time for the package manager to finish and exit. Unfortunately,
this bugfix cannot be made retroactive, because the broken version of
the prerm script is called before the new package starts to be
unpacked/installed.

Although there are other ways of doing anything an administrator might
be trying to accomplish by pushing a new fleet-osquery package,
bricking an endpoint simply by pushing this package through the Software
page seems like a pretty massive footgun that is easy to protect
against.

Signed-Off-By: Dan Fuhry <dan@fuhry.com>
@fuhry
fuhry force-pushed the delay-restart-on-inband-upgrade branch from 8ac2fbb to 935afc7 Compare July 25, 2025 19:40
@jahzielv

Copy link
Copy Markdown
Contributor

Thanks for the contribution @fuhry !

Assigning to @sharon-fdm as the g-orchestration EM.

@getvictor

Copy link
Copy Markdown
Member

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 28, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@getvictor getvictor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the contribution, @fuhry

Could we run into the same issues on Windows and/or macOS?

@getvictor
getvictor merged commit 6e227b6 into fleetdm:main Jul 28, 2025
44 of 53 checks passed
@getvictor

Copy link
Copy Markdown
Member

Also, since this is a fleetctl change, it would go out in the next 4.73.0 release (in ~4 weeks).

@getvictor getvictor linked an issue Jul 28, 2025 that may be closed by this pull request
getvictor added a commit that referenced this pull request Jul 30, 2025
Moved #31286 changes since this is a packaging change (part of
fleet/fleetctl release) and not part of orbit release.
getvictor added a commit that referenced this pull request Sep 10, 2025
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.

Updating orbit from Software page breaks orbit on Linux

3 participants