Fix apt-ostree container installation failure
Some checks failed
Comprehensive CI/CD Pipeline / Build and Test (push) Successful in 16m28s
Comprehensive CI/CD Pipeline / Security Audit (push) Failing after 7s
Comprehensive CI/CD Pipeline / Package Validation (push) Successful in 52s
Comprehensive CI/CD Pipeline / Status Report (push) Has been skipped

- Enhanced check_systemd() function to properly detect container environments
- Added detection for Docker, Podman, and other container runtimes
- Verify systemd is running as PID 1 before attempting service operations
- Check systemd D-Bus availability before service configuration
- Gracefully skip systemd setup in containers with helpful messages
- Provide manual configuration instructions for real systems

Fixes container builds and CI/CD pipelines that install apt-ostree
while maintaining full functionality on real systems with systemd.
This commit is contained in:
robojerk 2025-09-08 10:41:11 -07:00
parent 6a6f511a51
commit 2306ee2a72
2 changed files with 122 additions and 1 deletions

View file

@ -28,18 +28,43 @@ setup_completions() {
fi
}
# Function to check if systemd is available
# Function to check if systemd is available and running
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
}
# Function to enable and start the service
setup_service() {
if ! check_systemd; then
log "Skipping systemd service configuration"
log "To configure services manually on a real system, run:"
log " systemctl enable apt-ostreed.service"
log " systemctl start apt-ostreed.service"
return 0
fi