Skip to content

Conversation

@DocMAX
Copy link

@DocMAX DocMAX commented Aug 14, 2025

Here's a summary of the changes made to hd-idle:

Added creation of /var/run/hd-idle directory at startup
Added writing "0" to /var/run/hd-idle/sdX.status when a disk spins down
Added writing "1" to /var/run/hd-idle/sdX.status when a disk spins up
Error handling for file operations (only logged in debug mode)
The changes maintain all existing functionality while adding the requested status file feature. The status files will be created with:

Content "1" when the disk spins up
Content "0" when the disk spins down
File permissions 0644 (readable by all users)
The implementation is robust and handles cases where:

The directory doesn't exist (it will be created)
File writes fail (errors are logged in debug mode)
Multiple disks are being monitored (each gets its own status file)

@adelolmo
Copy link
Owner

Hi @DocMAX
Thank you for the PR.
I'll like to test it during the next days before merging it.
In the meantime, would you mind to update the documentation with the new feature?

@DocMAX
Copy link
Author

DocMAX commented Aug 15, 2025

I allready wrote in the PR what this change does.
Also updated it now to just create a empty file sdX.idle if a drive is down. I find it more appealing.

@adelolmo
Copy link
Owner

I allready wrote in the PR what this change does. Also updated it now to just create a empty file sdX.idle if a drive is down. I find it more appealing.

Updating the documentation is a way to enable other users to understand how to use the new feature.
If you describe the new functionality in the README.md, I'll update the rest of the places later 👍
Thank you !

DocMAX added 4 commits August 31, 2025 07:56
Introduces a new configuration option, `SkipIfMounted`, to prevent hard drives from spinning down if they are currently mounted. This feature can be enabled globally or per-device.

- Add `SkipIfMounted` boolean to `DefaultConf` and `DeviceConf`.
- Implement `isDeviceMounted` function using `findmnt` to check mount status.
- Modify `updateState` to check `SkipIfMounted` before initiating spindown.
- Add `-M` command-line flag to enable this behavior.
- Update usage instructions to reflect the new option.

This prevents potential data corruption or issues that could arise from spinning down an actively used, mounted drive.
Introduce a `--dry-run` CLI flag to simulate disk spindown operations without executing actual commands, allowing for safe testing of configurations.

Improve the `isDeviceMounted` function to reliably detect mounted devices, including Btrfs and ZFS filesystems, and to check for mounted partitions. This makes the `skip-if-mounted` feature more accurate and robust.
Add a new `verbose` flag (`-v`, `--verbose`) to provide more user-facing informational output. This flag is distinct from the `debug` flag, which is intended for more internal debugging details.

Update various print statements to be conditional on `verbose` (or `debug` or `logFile` presence) for events like disk spindown/spinup, and reasons for skipping spindown (e.g., device mounted). Enhance messages for Btrfs and ZFS devices when spindown is skipped due to being mounted.

Remove the `LastSpunDownAt` field from the detailed disk state debug output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants