-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of script and service unit
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#! /bin/bash -eu | ||
|
||
# set rotational disks to spin down after a timeout | ||
|
||
DISK_NAME=${1:?disk name required} | ||
|
||
# default delay: 10 mins | ||
DELAY=${2:-120} | ||
|
||
function resolve_disk { | ||
for devpath in "$1" "disk/by-id/$1" "disk/by-path/$1"; do | ||
if [ -b "/dev/$devpath" ]; then | ||
abspath=$(readlink -f "/dev/$devpath") | ||
echo ${abspath#/dev/} | ||
return | ||
fi | ||
done | ||
echo "No disk named '$1' found" >/dev/stderr | ||
return 1 | ||
} | ||
|
||
DISK=$(resolve_disk "$DISK_NAME") | ||
|
||
if [ $(cat /sys/block/$DISK/queue/rotational) == 0 ]; then | ||
echo "Not a rotating disk: $DISK" >/dev/stderr | ||
exit 1 | ||
fi | ||
|
||
hdparm -S $DELAY /dev/$DISK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=Spindown timeout for rotating disk %i | ||
After=suspend.target hibernate.target | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
ExecStart=/usr/sbin/hd-standby %i | ||
ExecStop=/usr/sbin/hd-standby %i 0 | ||
|
||
[Install] | ||
WantedBy=basic.target suspend.target hibernate.target | ||
|