Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postinstall.sh should detect chrooted environments to prevent dpkg failures #767

Open
bowling233 opened this issue Dec 10, 2024 · 0 comments
Labels
artifact:deb Issues related to DEB packages bug Something isn't working

Comments

@bowling233
Copy link

Description

When installing otelcol in chrooted environments (e.g., chroot or systemd-nspawn), the installation fails because the postinstall.sh script attempts to run systemctl commands to start and enable systemd services.

In these environments, systemd is not running as PID 1, which causes the script to fail. As a result:

  • dpkg enters a broken state.
  • Any subsequent package installations or updates fail because dpkg keeps retrying the failing postinstall script.

This is extremely critical for automated workflows.

Error Output

Below is the error message observed during installation:

Setting up otelcol-contrib (0.115.1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/otelcol-contrib.service → /lib/systemd/system/otelcol-contrib.service.
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
dpkg: error processing package otelcol-contrib (--install):
 installed otelcol-contrib package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 otelcol-contrib

Steps to Reproduce

  1. Enter a chroot or systemd-nspawn environment.
  2. Install otelcol using dpkg (e.g., dpkg -i otelcol-contrib.deb).
  3. Observe that the installation fails with the above error message due to systemctl commands in postinstall.sh.

Expected Behavior

The script should check whether systemd is running before executing systemctl commands. If systemd is not active, the script should safely skip service-related operations.

Proposed Solution

Modify postinstall.sh to verify if systemd is running as PID 1 before calling systemctl. For example:

if ps --no-headers -o comm 1 | grep -q 'systemd'; then
    # Safe to run systemctl commands
    systemctl start otelcol-contrib
fi

This ensures that the systemctl commands only run in appropriate environments, avoiding failures in chrooted setups.

@dosubot dosubot bot added artifact:deb Issues related to DEB packages bug Something isn't working labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
artifact:deb Issues related to DEB packages bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant