Raspberry PI Shutdown Solution
Jump to navigation
Jump to search
Shutdown on Wifi Dongle Unplug
See: http://raspberrypi.stackexchange.com/questions/4719/how-to-shut-down-rpi-when-running-headless
It uses already installed udev service to run a shell command when the a usb device unplugs.
First find the WIFI dongles vendor and model id:
sudo su
lsusb
Output:
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bus 001 Device 004: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
Note the ID of the wifi dongle. Mine was 148f:5370. Plug the numbers into the udev rule:
echo 'ACTION=="remove", ENV{ID_VENDOR_ID}=="148f", ENV{ID_MODEL_ID}=="5370", RUN+="/sbin/shutdown -h now"' >/etc/udev/rules.d/00-my_pi_shutdown.rules
udevadm control --reload-rules
That's it. Now when unplugging the wifi dongle the RPI should shutdown.