A Rust-based fan control daemon with REST API for dynamic configuration management.
- Automatic fan control based on temperature curves
- REST API for real-time configuration management
- Support for multiple fans with individual configurations
- Linear interpolation between temperature steps
- Graceful shutdown handling
The daemon provides a REST API on http://127.0.0.1:8080/api/v1/ with the following endpoints:
GET /api/v1/status- Get current status of all fans (temperature, power, configuration)GET /api/v1/config- Get the current configurationPUT /api/v1/config- Update the entire configuration
GET /api/v1/fans- Get all fan configurationsGET /api/v1/fans/{name}- Get configuration for a specific fanPUT /api/v1/fans/{name}- Update fan curve (steps) for a specific fanDELETE /api/v1/fans/{name}- Remove a fan from configurationPOST /api/v1/fans- Add a new fan to configuration
POST /api/v1/stop- Send stop signal to the daemonPOST /api/v1/start- Start the daemon (not implemented yet)
All API responses follow this format:
{
"success": true,
"message": "Operation completed successfully",
"data": { ... }
}curl -X PUT http://127.0.0.1:8080/api/v1/fans/fan_1 \
-H "Content-Type: application/json" \
-d '{
"steps": [
{"temp": 30, "power": 20},
{"temp": 50, "power": 50},
{"temp": 70, "power": 80},
{"temp": 85, "power": 100}
]
}'curl http://127.0.0.1:8080/api/v1/statusResponse:
{
"success": true,
"message": "Status retrieved successfully",
"data": [
{
"name": "fan_1",
"temperature": 45,
"power": 60,
"sensor_input": "/sys/class/hwmon/hwmon0/temp1_input",
"pwm_input": "/sys/class/hwmon/hwmon1/pwm1",
"steps": [
{"temp": 30, "power": 20},
{"temp": 50, "power": 50},
{"temp": 70, "power": 80},
{"temp": 85, "power": 100}
]
}
]
}The daemon reads configuration from config.json. The configuration format is JSON and can be updated via the REST API.
cargo build --releasesudo ./target/release/coold-rs daemon
# or simply (daemon is the default)
sudo ./target/release/coold-rsThe daemon will start both the fan control service and the REST API server on port 8080.
The CLI provides an easy way to interact with the daemon:
# Get current fan status
./target/release/coold-rs cli status
# List all fans
./target/release/coold-rs cli list
# Get specific fan configuration
./target/release/coold-rs cli get fan_1
# Update fan curve
./target/release/coold-rs cli update fan_1 "30:20,50:50,70:80,85:100"
# Add new fan
./target/release/coold-rs cli add \
--sensor-name "coretemp" \
--sensor-input "temp1_input" \
--pwm-name "nct6775" \
--pwm-input "pwm1" \
"30:20,50:50,70:80,85:100"
# Remove fan
./target/release/coold-rs cli remove fan_1
# Update entire configuration from file
./target/release/coold-rs cli update-config new_config.json
# Stop the daemon
./target/release/coold-rs cli stopstatus- Get current status of all fansconfig- Get current configurationupdate-config <file>- Update entire configuration from filelist- List all fansget <name>- Get specific fan configurationupdate <name> <steps>- Update fan curve (format: "temp:power,temp:power,...")add- Add new fan with required parametersremove <name>- Remove fanstop- Stop the daemonstart- Start the daemon
src/daemon.rs- Core fan control logic and configuration managementsrc/api.rs- REST API implementation using Actix-websrc/cli.rs- Command-line interface for interacting with the REST APIsrc/main.rs- Application entry point with mode selection (daemon/CLI)
The application uses a shared FanController instance that can be safely accessed from both the daemon thread and the API server, allowing for real-time configuration updates without restarting the service.
The CLI provides a user-friendly interface to the REST API, making it easy to manage fan configurations from the command line without needing to construct HTTP requests manually.