File: //bigscoots/lxd/fix-proc-mount.sh
#!/bin/bash
# --- 1. THE GATEKEEPER: ONLY RUN ON LXD ---
# Checks if the environment is 'lxc' or if the LXD device socket exists
if [ "$container" != "lxc" ] && [ ! -d "/dev/lxd" ] && [ ! -d "/var/lib/lxd" ]; then
# Silently exit on bare metal or other virtualization types
exit 0
fi
# --- 2. SELF-INSTALLATION LOGIC ---
# This only runs if the gatekeeper above passes
if [ ! -f "/etc/systemd/system/proc-checker.timer" ]; then
cat <<EOF > /etc/systemd/system/proc-checker.service
[Unit]
Description=LXD Proc Mount Watchdog
After=network.target
[Service]
Type=oneshot
ExecStart=/bin/bash /bigscoots/lxd/fix-proc-mount.sh
EOF
cat <<EOF > /etc/systemd/system/proc-checker.timer
[Unit]
Description=Run LXD Proc Watchdog every minute
[Timer]
OnBootSec=1min
OnUnitActiveSec=1min
[Install]
WantedBy=timers.target
EOF
systemctl daemon-reload
systemctl enable --now proc-checker.timer
fi
# --- 3. THE ACTUAL HEALTH CHECK ---
if ! ps -p 1 > /dev/null 2>&1; then
# We only log and fix if ps is actually broken
echo "$(date): Broken /proc detected in LXD. Remounting..." >> /var/log/lxd-proc-fixer.log
mount proc /proc -t proc
if ps -p 1 > /dev/null 2>&1; then
echo "$(date): /proc recovered successfully." >> /var/log/lxd-proc-fixer.log
fi
fi
exit 0