Nvidia driver reload

I keep hitting an issue where nvidia’s drivers get messed up on Linux and it causes my plex media server to crash on startup, requiring me to restart. nvidia-smi would return this error: Failed to initialize NVML: Driver/library version mismatch.

I finally found some time to investigate and came up with a script to cleanly unload/reload nvidia drivers and allow plex to start up without a restart of my machine. Script below:

#!/usr/bin/env bash

# Ensure the script is executed with root privileges
if [ "$EUID" -ne 0 ]; then
  echo "Error: This script must be run as root. Please run with sudo." >&2
  exit 1
fi

echo "===================================================="
echo "Starting Live NVIDIA Driver Version Mismatch Fix"
echo "===================================================="

# 1. Detect and stop the active display manager
DM=""
if systemctl is-active --quiet gdm3; then
  DM="gdm3"
elif systemctl is-active --quiet gdm; then
  DM="gdm"
elif systemctl is-active --quiet sddm; then
  DM="sddm"
elif systemctl is-active --quiet lightdm; then
  DM="lightdm"
fi

if [ -n "$DM" ]; then
  echo "[+] Detected active display manager: $DM"
  echo "[+] Stopping $DM to free up GPU handles..."
  systemctl stop "$DM"
  # Provide a short pause for the system to settle the graphical stack
  sleep 2
else
  echo "[!] No standard active display manager detected (headless server mode). Proceeding..."
fi

# 2. Force-terminate lingering processes accessing NVIDIA devices
echo "[+] Checking for lingering processes accessing NVIDIA device files..."
if lsof /dev/nvidia* >/dev/null 2>&1; then
  echo "[!] Found processes clinging to the GPU. Forcing termination via fuser..."
  fuser -k -9 /dev/nvidia* 2>/dev/null
  sleep 2
else
  echo "[+] No user-space processes currently locking the GPU."
fi

# 3. Unload existing kernel modules sequentially from most to least dependent
echo "[+] Unloading active NVIDIA kernel modules..."
modules=("nvidia_drm" "nvidia_modeset" "nvidia_uvm" "nvidia")

for mod in "${modules[@]}"; do
  if lsmod | grep -q "^${mod}"; then
    echo "  -> Removing module: $mod"
    if ! rmmod "$mod"; then
      echo "  [!] Error: Failed to remove $mod. Checking for persistent locks..." >&2
      lsof /dev/nvidia* 2>/dev/null
      echo "  [!] Please manually stop any background tasks listed above and rerun this script." >&2
      exit 1
    fi
  else
    echo "  -> Module $mod is not currently loaded or already removed."
  fi
done

# 4. Reload updated kernel modules sequentially from least to most dependent
echo "[+] Reloading updated NVIDIA kernel modules..."
reload_modules=("nvidia" "nvidia_uvm" "nvidia_modeset" "nvidia_drm")

for mod in "${reload_modules[@]}"; do
  echo "  -> Loading module: $mod"
  if ! modprobe "$mod"; then
    echo "  [!] Critical Error: Failed to load module $mod." >&2
    exit 1
  fi
done

# 5. Restart the display manager if one was originally running
if [ -n "$DM" ]; then
  echo "[+] Restarting display manager: $DM..."
  systemctl start "$DM"
fi

# 6. Verify NVML initialization status
echo "===================================================="
echo "Verification Check"
echo "===================================================="
if command -v nvidia-smi &> /dev/null; then
  echo "[+] Running nvidia-smi to confirm fix..."
  nvidia-smi
else
  echo "[+] Modules reloaded successfully, but nvidia-smi utility is not in the system PATH."
fi

Fixing upload limit w/HTTPS-Portal and WordPress docker images

I was trying to upload this photo of my dog to test out some things and hit an issue with https-portal and the wordpress docker images. I thought I’d share my fixes since it wouldn’t let me upload anything over 1MB.

The https-portal has a limit of 1M, so you need to add the CLIENT_MAX_BODY_SIZE environment variable to whatever size you want, I went with 500M so I added that to my docker-compose file.

The wordpress container has a php.ini limit of about 2M as well, so you need to modify the uploads.ini file to be:

file_uploads = On
memory_limit = 500M
upload_max_filesize = 500M
post_max_size = 500M
max_execution_time = 600

That should do it. Finally to tie it all together if you’re using docker-compose you’ll need to add a volume section to copy that file into docker:

volumes:
 - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

Hope this helps someone!

Fridge and Freezer Temperature Monitoring

A couple of weeks ago I had the unfortunate problem of my freezer’s auto-defrost not kicking on an the coils freezing completely. This led to my fridge not cooling down past 60. I had to take apart my freezer for the first time to de-ice the coils to get it working again. Then I got the bright idea of using some of the spare temperature probes I have and a spare Pi to monitor temperature. So I wired up a Pi and created a dashboard for monitoring temperatures in Grafana out of a postgres database.

Wiring was really simple, I just followed this guide to wire multiple probes up: https://www.hackster.io/vinayyn/multiple-ds18b20-temp-sensors-interfacing-with-raspberry-pi-d8a6b0

Code looks like this: https://gitlab.com/-/snippets/2491465

A couple of minutes in grafana and I get some cool graphs like this:

Continue reading “Fridge and Freezer Temperature Monitoring”

Gitlab Pages + Namecheap

I came across a small issue when trying to use some namecheap domains with Gitlab pages, namely two stupid joke pages: burgerlover.us and fsdbutton.xyz. I couldn’t get the verification to happen after adding the TXT entries. One simple support issue led me to find the reason, which is namecheap appends the domain automatically to the field.

So instead of entering _gitlab-pages-verification-code.www.burgerlover.us like gitlab suggests for the host, just enter _gitlab-pages-verification-code.www for example, which will fill in the rest. That did the trick.

Hope it helps some other folks.

Ubiquiti UniFi Ap-AC Lite Troubleshooting after firmware fix

I recently did two things. 1) Upgrade the firmware on my Ubiquiti Access Point and 2) Replaced my router with PFSense running on an old Xeon-based machine I had. This led to a big problem when trying to get my access point to work, it just wouldn’t connect to the controller. It failed to be adopted by the controller so it couldn’t get its configuration. TLDR: The solution was to remove the device when it was turned off, turn it back on and then adopt the access point from the controller interface

I might have a bit of a unique setup. I only have the Access point and use a Linux server to run the software that manages it instead of the hardware they sell. So that might have caused problems. Overall I’ve been incredibly happy with the alien space-ship looking access point. I’ve never had to reboot it to get it to work and it gets pretty good coverage for being under my couch. Plus I dig the PoE single cable connection for when I eventually get into the attic to mount it to my ceiling. So if you’re looking for something good and relatively cheap, I do recommend it. Its about $80 on Amazon: Click here.

The Aliens have landed. Amazon.com link.

Troubleshooting steps:

  1. Unplug and plug back in… No dice.
  2. Hold reset button with paper-clip for 30 seconds… No dice.
  3. SSH to the device to set-inform-url… No dice.
    This one was interesting though. You can run: ssh ubnt@<ip of device> with the password ubnt to get to a busybox shell. From there you can run: set-inform http://ip-of-controller:8080/inform and see if it connects.

At this point I considered reflashing the firmware, but didn’t want to go through all the steps of setting up a tftp server, etc. to boot the image correctly. As a last-ditch effort I just unplugged the access-point, logged into the web console and deleted/forgot device, and plugged it back in. And sure enough it worked. So instead of trying even step 3 above, it makes sense just to forget the device and set it up after step 2 above.