adelolmo / hd-idle

Hard Disk Idle Spin-Down Utility
GNU General Public License v3.0
587 stars 32 forks source link

Hook-function to be called after spinning down #110

Closed squonk11 closed 10 months ago

squonk11 commented 11 months ago

I would like to propose an additional feature: Implementation of a hook-function (e.g. call of external shell script, if present) after the disks successfully spun down. With this functionality I could be able switch off the HD-Bay which (in my case) makes a terrible noise from the fans and still has a power consumption of 10W even if the disks are spun down. But there also needs to be a hook-function for spinning up the disks when accessing them again - is this also handled by hd-idle or is this an OS-function?

adelolmo commented 11 months ago

This is a topic that already came up in the past: https://github.com/adelolmo/hd-idle/issues/49

On 7 December 2023 18:28:51 CET, Lothar @.***> wrote:

I would like to propose an additional feature: Implementation of a hook-function (e.g. call of external shell script, if present) after the disks successfully spun down. With this functionality I could be able switch off the HD-Bay which (in my case) makes a terrible noise from the fans and still has a power consumption of 10W even if the disks are spun down. But there also needs to be a hook-function for spinning up the disks when accessing them again - is this also handled by hd-idle or is this an OS-function?

-- Reply to this email directly or view it on GitHub: https://github.com/adelolmo/hd-idle/issues/110 You are receiving this because you are subscribed to this thread.

Message ID: @.***>

squonk11 commented 10 months ago

I solved my requirement by using std on-board tools: cron and autofs. For those who are interested in the solution: I am using a shell-script via a cron-job which checks the result of hdparm in order to power-off the drive bay like so:

#!/usr/bin/env bash
if [[ -n $( /usr/sbin/hdparm -C /dev/disk/by-uuid/05628b67-de44-44f1-a3fe-2cd4e0cbaf26 2>&1 | grep "standby" ) ]]; then
  if [[ -n $( /usr/sbin/hdparm -C /dev/disk/by-uuid/40322f73-89ce-423d-a29d-14157a412007 2>&1 | grep "standby" ) ]]; then
    /usr/bin/curl "http://192.168.1.76/relay/0?turn=off"
    echo -e "\nHDs switched off at: $( date )"
  fi
fi

For powering the drives up again I used autofs by setting up an auto.nas file:

#!/bin/bash
if [[ -n $( /usr/bin/curl -s http://192.168.1.76/relay/0 | grep '"ison":false' ) ]]; then
   /usr/bin/curl "http://192.168.1.76/relay/0?turn=on" > /dev/null 2>&1
   /usr/bin/sleep 20 > /dev/null 2>&1
fi
case $1 in
        nas1) echo "-fstype=ext4,rw :/dev/disk/by-uuid/05628b67-de44-44f1-a3fe-2cd4e0cbaf26"
              ;;
        nas2) echo "-fstype=ext4,rw :/dev/disk/by-uuid/40322f73-89ce-423d-a29d-14157a412007"
              ;;
esac

Of course I am using hd-idle also in order to put the drives in standby after 20 minutes of non-usage. For switching the power on and off I am using a Shelly Plug S.

Maybe this info might help someone.