@@ -79,12 +79,70 @@ ${RUN_AS_LOGIN_USER} "ln -sf '${USER_WORKBENCH_CONFIG_DIR}' '${USER_WORKBENCH_LE
7979exec > >( tee -a " ${POST_STARTUP_OUTPUT_FILE} " ) # Append output to the file and print to terminal
8080exec 2> >( tee -a " ${POST_STARTUP_OUTPUT_FILE} " >&2 ) # Append errors to the file and print to terminal
8181
82+ # Memory diagnostics before package installation
83+ echo " === Memory diagnostics before apt-get update ==="
84+ echo " --- System memory overview (NOTE: this shows HOST memory, not container limits) ---"
85+ free -h
86+ echo " "
87+ echo " --- Detailed memory info ---"
88+ grep -E " MemTotal|MemFree|MemAvailable|Buffers|Cached|SwapTotal|SwapFree" /proc/meminfo
89+ echo " "
90+ echo " --- Cgroup memory limits (actual container limits) ---"
91+ echo " Cgroup v2 memory.max:"
92+ cat /sys/fs/cgroup/memory.max 2> /dev/null || echo " not available"
93+ echo " Cgroup v2 memory.current:"
94+ cat /sys/fs/cgroup/memory.current 2> /dev/null || echo " not available"
95+ echo " Cgroup v2 memory.swap.max:"
96+ cat /sys/fs/cgroup/memory.swap.max 2> /dev/null || echo " not available"
97+ echo " Cgroup v1 memory.limit_in_bytes:"
98+ cat /sys/fs/cgroup/memory/memory.limit_in_bytes 2> /dev/null || echo " not available"
99+ echo " Cgroup v1 memory.usage_in_bytes:"
100+ cat /sys/fs/cgroup/memory/memory.usage_in_bytes 2> /dev/null || echo " not available"
101+ echo " "
102+ echo " --- Top 20 processes by memory (RSS) ---"
103+ ps aux --sort=-%mem | head -21
104+ echo " "
105+ echo " --- Process tree with memory ---"
106+ ps axo pid,ppid,comm,%mem,rss --sort=-%mem | head -30
107+ echo " === End memory diagnostics ==="
108+
109+ # Check disk space before package installation
110+ echo " === Disk space before apt-get ==="
111+ df -h /var /tmp / 2> /dev/null || df -h
112+ echo " "
113+
82114# The apt package index may not be clean when we run; resynchronize
83115if type apk > /dev/null 2>&1 ; then
84116 apk update
85117 apk add --no-cache jq curl fuse tar wget
86118elif type apt-get > /dev/null 2>&1 ; then
87- apt-get update
119+ # Start background memory monitor
120+ echo " === Starting memory monitor (logging every second) ==="
121+ (
122+ while true ; do
123+ echo " [$( date ' +%H:%M:%S' ) ] cgroup_mem=$( cat /sys/fs/cgroup/memory.current 2> /dev/null || echo N/A) free_mem=$( grep MemAvailable /proc/meminfo | awk ' {print $2}' ) kB"
124+ sleep 1
125+ done
126+ ) &
127+ MONITOR_PID=$!
128+
129+ # Run apt-get update with error handling
130+ echo " === Running apt-get update ==="
131+ if ! apt-get update; then
132+ APT_EXIT=$?
133+ echo " === apt-get update failed with exit code $APT_EXIT ==="
134+ echo " === Checking dmesg for OOM messages ==="
135+ dmesg | tail -50 || echo " dmesg not available"
136+ echo " === Memory state after failure ==="
137+ free -h
138+ cat /sys/fs/cgroup/memory.current 2> /dev/null || echo " cgroup memory not available"
139+ kill $MONITOR_PID 2> /dev/null || true
140+ exit $APT_EXIT
141+ fi
142+
143+ kill $MONITOR_PID 2> /dev/null || true
144+ echo " === apt-get update completed successfully ==="
145+
88146 apt install -y jq curl fuse tar wget
89147else
90148 >&2 echo " ERROR: Unable to find a supported package manager"
0 commit comments