# apt-ostree Container Installation Fix ## Problem Solved The `apt-ostree` package was failing to install in container environments due to systemd service configuration attempts that require a running systemd instance. ## Root Cause The original `check_systemd()` function only checked if the `systemctl` command existed, but didn't verify: 1. If systemd was actually running as PID 1 2. If the system was in a container environment 3. If the systemd D-Bus interface was available ## Solution Implemented Updated the `check_systemd()` function in `debian/apt-ostree.postinst` to: 1. **Check for systemctl command availability** 2. **Detect container environments** using multiple indicators: - `/.dockerenv` file (Docker) - `container` environment variable (Podman, Docker, etc.) - `/run/.containerenv` file (Podman) - Docker in `/proc/1/cgroup` (additional Docker detection) 3. **Verify systemd is running as PID 1** using `ps -p 1 -o comm=` 4. **Check systemd D-Bus availability** using `systemctl is-system-running` ## Key Changes ### Before (Original Code) ```bash check_systemd() { if ! command -v systemctl >/dev/null 2>&1; then log "Warning: systemd not available, skipping service setup" return 1 fi return 0 } ``` ### After (Fixed Code) ```bash check_systemd() { # Check if systemctl command exists if ! command -v systemctl >/dev/null 2>&1; then log "Warning: systemd not available, skipping service setup" return 1 fi # Check if we're in a container environment if [ -f /.dockerenv ] || [ -n "${container:-}" ] || [ -f /run/.containerenv ] || \ ([ -f /proc/1/cgroup ] && grep -q docker /proc/1/cgroup 2>/dev/null); then log "Warning: Running in container environment, skipping systemd service setup" return 1 fi # Check if systemd is actually running as PID 1 if ! ps -p 1 -o comm= | grep -q systemd; then log "Warning: systemd not running as PID 1, skipping service setup" return 1 fi # Check if systemd D-Bus is available if ! systemctl is-system-running >/dev/null 2>&1; then log "Warning: systemd not running, skipping service setup" return 1 fi return 0 } ``` ## Additional Improvements - Enhanced `setup_service()` function to provide helpful manual configuration instructions when skipping systemd setup - Added proper parentheses to fix logical operator precedence in container detection ## Testing Results ✅ **Container Environment**: Package installs successfully, skips systemd configuration gracefully ✅ **Real System**: Package installs and configures systemd services normally ✅ **Podman Container**: Verified working with actual Podman container build ## Files Modified - `debian/apt-ostree.postinst` - Updated `check_systemd()` and `setup_service()` functions ## Impact - **Fixes**: Container builds and CI/CD pipelines that install apt-ostree - **Maintains**: Full functionality on real systems with systemd - **Improves**: User experience with clear error messages and manual configuration instructions ## Verification Commands ```bash # Test in container (should skip systemd) docker run --rm -it debian:unstable bash -c "apt update && apt install -y apt-ostree" # Test on real system (should configure systemd) apt install -y apt-ostree && systemctl status apt-ostreed ``` ## Status ✅ **COMPLETED** - Fix implemented and tested successfully