On 30.04.2014 13:02, Lennart Poettering wrote: > On Wed, 30.04.14 01:02, Marcin Kocur (marcin2...@gmail.com) wrote: > >> Hello all, >> >> I wrote a service /etc/systemd/system/disable-2nd-hdd.service. I >> have 2 HDD's where one of them doesn't need to work all the time. So >> I thought it'd be cool to shut it down after 30 minutes of >> inactivity (the disc isn't mounted when system starts): >> /usr/bin/hdparm -S 241 /dev/sdb >> >> Then I wrote a service: >> >> [Unit] >> Description=Disable sdb >> Requires=local-fs.target >> After=local-fs.target > > These two lines are implied and hence can be removed. > >> >> [Service] >> Type=oneshot >> ExecStart=/usr/bin/hdparm -S 241 /dev/sdb >> >> [Install] >> WantedBy=multi-user.target >> >> Which seems to work: >> >> [root@linux mk]# systemctl status disable-2nd-hdd.service >> ● disable-2nd-hdd.service - Disable sdb >> Loaded: loaded (/etc/systemd/system/disable-2nd-hdd.service; enabled) >> Active: inactive (dead) since pon 2014-04-28 10:00:53 CEST; 21min ago >> Main PID: 248 (code=exited, status=0/SUCCESS) >> >> kwi 28 10:00:53 linux hdparm[248]: /dev/sdb: >> kwi 28 10:00:53 linux hdparm[248]: setting standby to 241 (30 minutes) >> >> But it doesn't work, like it had never happened, the disc is not spun down. >> >> When I change the command to /usr/bin/hdparm -y /dev/sdb (spin down >> disc immediately), the disc is spun down while booting but is starts >> again right away. >> >> When I manually start this service after system has already booted, >> it works as expected. > > Note that devices are probed asynchronously, and a device not needed at > boot is not waited for. THis means that your service might run before > the harddisk showed up in the kernel, or possibly that your hdparm > command is invoked before the initializating/probing/identifying of the > hdd or its filesystems is compelted, thus possibly negating the effect > of your command. > > YOu probably want to invoke your commandn with RUN from a udev rule so > that it is run when the hw is found. > > Lennart >
e.g. /etc/udev/rules.d/99-diskungfu.rules ACTION=="add", SUBSYSTEM=="block", DRIVERS=="ahci", RUN+="/usr/bin/diskungfu" disk spindown - sdparm https://lists.fedoraproject.org/pipermail/users/2013-April/434786.html systemd/cron functionality https://wiki.archlinux.org/index.php/Systemd/cron_functionality poma _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel