|
| 1 | +#! /bin/bash |
| 2 | +# Copyright © 2025-2026 Apple Inc. and the container project authors. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# Monitor system startup for debugging CI delays |
| 17 | +# This script runs in the background and captures: |
| 18 | +# 1. Extended attributes on binaries (quarantine checks) |
| 19 | +# 2. launchd service state |
| 20 | +# 3. Process table every second |
| 21 | + |
| 22 | +LOG_FILE="${1:-/tmp/startup-monitor.log}" |
| 23 | +DURATION="${2:-30}" |
| 24 | + |
| 25 | +# Ensure the log directory exists |
| 26 | +LOG_DIR=$(dirname "$LOG_FILE") |
| 27 | +mkdir -p "$LOG_DIR" |
| 28 | + |
| 29 | +# Redirect all output to log file |
| 30 | +exec > "$LOG_FILE" 2>&1 |
| 31 | + |
| 32 | +echo "=== Startup Monitor Started at $(date -u +"%Y-%m-%dT%H:%M:%SZ") ===" |
| 33 | +echo |
| 34 | + |
| 35 | +# Check for quarantine attributes on binaries |
| 36 | +echo "=== Extended Attributes on Binaries ===" |
| 37 | +for binary in bin/container-apiserver \ |
| 38 | + libexec/container/plugins/container-network-vmnet/bin/container-network-vmnet \ |
| 39 | + libexec/container/plugins/container-runtime-linux/bin/container-runtime-linux \ |
| 40 | + libexec/container/plugins/container-core-images/bin/container-core-images; do |
| 41 | + if [ -f "$binary" ]; then |
| 42 | + echo "--- $binary ---" |
| 43 | + xattr -l "$binary" 2>&1 || echo "No extended attributes or error reading xattr" |
| 44 | + fi |
| 45 | +done |
| 46 | +echo |
| 47 | + |
| 48 | +# Monitor loop |
| 49 | +echo "=== Process and Service Monitoring (every 1 second for ${DURATION}s) ===" |
| 50 | +for i in $(seq 1 $DURATION); do |
| 51 | + echo "--- Snapshot $i at $(date -u +"%Y-%m-%dT%H:%M:%SZ") ---" |
| 52 | + |
| 53 | + # Capture container-related processes |
| 54 | + echo "Container processes:" |
| 55 | + ps -ef | grep -E 'container-apiserver|container-network-vmnet|container-runtime|launchd' | grep -v grep || echo "No container processes found" |
| 56 | + |
| 57 | + # Check launchd service state for network plugin |
| 58 | + echo |
| 59 | + echo "Launchd service state:" |
| 60 | + DOMAIN=$(launchctl managername 2>/dev/null | tr '[:upper:]' '[:lower:]' | sed 's/aqua/gui/' | sed "s/background/user/" | sed "s/system/system/" ) |
| 61 | + if [ "$DOMAIN" = "gui" ] || [ "$DOMAIN" = "user" ]; then |
| 62 | + DOMAIN="${DOMAIN}/$(id -u)" |
| 63 | + fi |
| 64 | + |
| 65 | + # Try to print state for default network service |
| 66 | + launchctl print "${DOMAIN}/com.apple.container.network.container-network-vmnet.default" 2>&1 || echo "Service not registered yet" |
| 67 | + |
| 68 | + echo |
| 69 | + echo "---" |
| 70 | + echo |
| 71 | + |
| 72 | + sleep 1 |
| 73 | +done |
| 74 | + |
| 75 | +echo "=== Startup Monitor Ended at $(date -u +"%Y-%m-%dT%H:%M:%SZ") ===" |
0 commit comments