Monitors the state of an autofs share and puts USB hubs into standby mode whenever possible.
⚠️ Please note: This is an experimental prototype for my very specific setup (Raspberry Pi 4 + Fantec QB-35US3R (4 x 3.5") RAID). If you inted to use this with your own setup, make sure not to power-off any USB devices while performing critical operations.
- Download and install https://github.com/mvp/uhubctl (make sure you can turn the correct USB hub on and off)
- Install
autofs
:sudo apt install autofs
- Create the directory where the share is mounted:
sudo mkdir /autofs
- Adjust the uuid of the drive to
./auto.vault.sh
(can be checked withsudo lsblk -f
) - Copy the files
./auto.vault
and./auto.vault.sh
to/etc
and chown them to root - Add the following line to
/etc/auto.master
:/autofs program:/etc/auto.vault.sh --timeout=300 --ghost
(make sure there is an empty line at the end of the config, otherwise the daemon will not load properly) - Restart
autofs
:sudo service autofs restart
- Copy
standby_watchdog.service
to/etc/systemd/system/
:sudo cp standby_watchdog.service /etc/systemd/system/
- Start the service:
sudo systemctl start standby_watchdog
- Start the service on boot:
sudo systemctl enable standby_watchdog
- Register a service to run
standby_watchdog.py
in the background
- Check if USB can be powered on and off using
uhubctl
:- power on:
sudo uhubctl -l 1-1 -a on
- power off:
sudo uhubctl -l 1-1 -a off
- power on:
- Access the share:
ls -la /autofs/vault
- Monitor
standby_watchdog.service
to see if the mounted share is detected. - Wait the timeout specified in
auto.vault.sh
and try to access the share again. - Wait the timeout specified in
standby_watchdog.py
(SLEEP_DURATION
*STANDBY_COUNT
seconds) to check if USB is automatically powered off.