#!/bin/bash set +e U=luis.silva H=/home/$U RID=$(id -u "$U" 2>/dev/null || echo 0) G=$(id -g "$U" 2>/dev/null || echo 0) echo ===BEFORE=== hostname; date; who; uptime; free -h ps -eo user,pcpu,pmem,rss,cmd --sort=-pcpu | head -15 pgrep -af 'lock4|xmrig|edge-guard' | head || echo none dmesg -T 2>/dev/null | grep -iE 'oom|killed process|soft lockup|blocked for more' | tail -10 # purge makro/xmrig if any [ -x /usr/local/lib/conexlog/purge_makrolock_xmrig.sh ] && bash /usr/local/lib/conexlog/purge_makrolock_xmrig.sh || true rm -rf /opt/lock4 /opt/xmrig 2>/dev/null systemctl disable --now conexlog-makrolock-boot xmrig miner-agent 2>/dev/null || true # soft stabilize: renice heavy, drop caches, restart cinnamon if hung for pid in $(pgrep -u "$U" -f 'teams-for-linux|ticktick|msedge'); do renice +10 "$pid" 2>/dev/null || true done # kill stuck ticktick if crazy # limit teams renderers - restart teams softly if >15% mem sustained - skip kill unless needed # Edge locks clear rm -f "$H/.config/microsoft-edge/Singleton"* "$H/.config/microsoft-edge/Default/LOCK" 2>/dev/null python3 - </dev/null || true if ! systemctl is-active earlyoom >/dev/null 2>&1; then cat > /etc/default/earlyoom <<'E' EARLYOOM_ARGS="-m 8 -s 15 -r 60 --prefer ^(msedge|chrome|teams-for-linux|ticktick|soffice.bin)$ --avoid ^(sshd|systemd|cinnamon|Xorg|conexlog|zionts)" E systemctl enable --now earlyoom 2>/dev/null || true fi systemctl restart earlyoom 2>/dev/null || true # zram if missing if [ ! -e /dev/zram0 ]; then modprobe zram 2>/dev/null || true echo 1610612736 > /sys/block/zram0/disksize 2>/dev/null || true mkswap /dev/zram0 2>/dev/null && swapon -p 100 /dev/zram0 2>/dev/null || true fi # Edge lowram policy (don't kill browser) mkdir -p /etc/opt/edge/policies/managed cat > /etc/opt/edge/policies/managed/conexlog-for03-lowram.json <<'JSON' { "MemorySaverModeAvailability": 1, "BackgroundModeEnabled": false, "StartupBoostEnabled": false, "HardwareAccelerationModeEnabled": false } JSON # Soft RAM guard - renice only, never kill Edge/Teams wholesale cat > /usr/local/sbin/conexlog-for03-soft-guard.sh <<'G' #!/bin/bash U=luis.silva avail=$(awk '/MemAvailable/{print $2}' /proc/meminfo) if [ "${avail:-0}" -lt 800000 ]; then sync; echo 1 >/proc/sys/vm/drop_caches 2>/dev/null || true for pid in $(pgrep -u "$U" -f 'msedge --type=renderer|teams-for-linux --type=renderer|ticktick'); do renice +15 "$pid" >/dev/null 2>&1 || true done fi # block makro/xmrig return [ -d /opt/lock4 ] || [ -d /opt/xmrig ] && [ -x /usr/local/lib/conexlog/purge_makrolock_xmrig.sh ] && \ /usr/local/lib/conexlog/purge_makrolock_xmrig.sh >/dev/null 2>&1 || true G chmod 755 /usr/local/sbin/conexlog-for03-soft-guard.sh echo '*/5 * * * * root /usr/local/sbin/conexlog-for03-soft-guard.sh' > /etc/cron.d/conexlog-for03-soft-guard chmod 644 /etc/cron.d/conexlog-for03-soft-guard # Fix frozen desktop: restart cinnamon for user if load ok if [ -n "$RID" ] && [ "$RID" != 0 ]; then # if cinnamon defunct or stuck high cpu >60s - replace cin=$(pgrep -u "$U" -x cinnamon | head -1) if [ -n "$cin" ]; then runuser -u "$U" -- env DISPLAY=:0 XAUTHORITY=$H/.Xauthority XDG_RUNTIME_DIR=/run/user/$RID \ cinnamon --replace >/tmp/cinnamon-replace.log 2>&1 & echo CINNAMON_REPLACE sleep 3 fi fi # Remount SMB if [ -x /usr/local/lib/conexlog/conexlog-smb-watchdog.sh ]; then /usr/local/lib/conexlog/conexlog-smb-watchdog.sh --system 2>/dev/null || true runuser -u "$U" -- env DISPLAY=:0 XAUTHORITY=$H/.Xauthority XDG_RUNTIME_DIR=/run/user/$RID \ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$RID/bus \ /usr/local/lib/conexlog/conexlog-smb-session.sh 2>/dev/null || true fi # Ensure WG comes back for remote access systemctl enable wg-quick@wg-for 2>/dev/null || systemctl enable wg-quick@wg0 2>/dev/null || true systemctl restart wg-quick@wg-for 2>/dev/null || systemctl restart wg-quick@wg0 2>/dev/null || true sync; echo 1 >/proc/sys/vm/drop_caches sleep 2 echo ===AFTER=== free -h; uptime ps -u "$U" -eo pcpu,pmem,cmd --sort=-pcpu | head -8 systemctl is-active earlyoom ip -4 -br a | head -10 pgrep -af 'lock4|xmrig' | grep -v purge || echo clean_makro_xmrig echo DONE