Git Product home page Git Product logo

autofs-standby's Introduction

autofs-standby

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.

Installation

Prerequisites

  1. Download and install https://github.com/mvp/uhubctl (make sure you can turn the correct USB hub on and off)
  2. Install autofs: sudo apt install autofs

Configure AutoFS

  1. Create the directory where the share is mounted: sudo mkdir /autofs
  2. Adjust the uuid of the drive to ./auto.vault.sh (can be checked with sudo lsblk -f)
  3. Copy the files ./auto.vault and ./auto.vault.sh to /etc and chown them to root
  4. 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)
  5. Restart autofs: sudo service autofs restart

Create a Standby Watchdog Service

  1. Copy standby_watchdog.service to /etc/systemd/system/: sudo cp standby_watchdog.service /etc/systemd/system/
  2. Start the service: sudo systemctl start standby_watchdog
  3. Start the service on boot: sudo systemctl enable standby_watchdog
  4. Register a service to run standby_watchdog.py in the background

Testing / Troubleshooting

  1. Check if USB can be powered on and off using uhubctl:
    1. power on: sudo uhubctl -l 1-1 -a on
    2. power off: sudo uhubctl -l 1-1 -a off
  2. Access the share: ls -la /autofs/vault
  3. Monitor standby_watchdog.service to see if the mounted share is detected.
  4. Wait the timeout specified in auto.vault.sh and try to access the share again.
  5. Wait the timeout specified in standby_watchdog.py (SLEEP_DURATION * STANDBY_COUNT seconds) to check if USB is automatically powered off.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.