You should choose an external hard drive that will spin down automatically after idle(no I/O activity) for some time. And in order to let it idle, you need to dismount the drive; that leads to the use of autofs.
Add this to /etc/auto.master:
# dismount after no file access for 120 seconds: /mnt /etc/auto.mnt --timeout=120
Create file etc/auto.mnt with this:
usbhd -fstype=ext3,rw :/dev/disk/by-label/USB40G
Add thsi line to /etc/nsswitch.conf:
automount: files
Restart autofs to take effect.
After that, whenever you access /mnt/usbhd, the partition labeled USB40G will be auto mounted.
First, don't use autofs for the drive.
tune2fs -L "USB1TB" /dev/sda1
/dev/disk/by-label/USB1TB /mnt/usbhd ext3 defaults,noauto,relatime,data=ordered 0 0
Add these line to /etc/udev/rules.d/mount-usb.rules:
ENV{ID_FS_LABEL}=="USB1TB", ACTION=="add", RUN+="/usr/local/bin/usbhd_added.sh"
ENV{ID_FS_LABEL}=="USB1TB", ACTION=="remove", RUN+="/bin/umount /mnt/usbhd", RUN+="/bin/touch /var/tmp/usbhd_removed"
Create file /usr/local/bin/usbhd_added.sh:
cat > /usr/local/bin/usbhd_added.sh <<EOT
#!/bin/sh
/bin/mount /mnt/usbhd
# restart services that broke after usbhd removed and inserted again
if [ -f /var/tmp/usbhd_removed ] ; then
/bin/rm -f /var/tmp/usbhd_removed
/usr/sbin/service minidlna restart
# more services here
fi
EOT
chmod 755 /usr/local/bin/usbhd_added.sh
So, whenever the drive is plugged, it is mounted automatically, and dependent services are restarted as needed.