ajout script ipmihddtemp

This commit is contained in:
nyanloutre 2021-10-19 14:27:42 +02:00
parent 458b6a72cd
commit 1383d2574d
3 changed files with 78 additions and 1 deletions

View File

@ -16,6 +16,22 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-nyanloutre-pysmart": {
"locked": {
"lastModified": 1634643555,
"narHash": "sha256-Fu0JVScZt0fUqfeo2tsTUcoehtpalBU7+15pxy1Ld+Y=",
"owner": "nyanloutre",
"repo": "nixpkgs",
"rev": "256d8d34f05c8badeaf3ecb615d3af08a4b492d6",
"type": "github"
},
"original": {
"owner": "nyanloutre",
"ref": "pysmart-init",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-unstable": { "nixpkgs-unstable": {
"locked": { "locked": {
"lastModified": 1634436779, "lastModified": 1634436779,
@ -50,6 +66,7 @@
"root": { "root": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nixpkgs-nyanloutre-pysmart": "nixpkgs-nyanloutre-pysmart",
"nixpkgs-unstable": "nixpkgs-unstable", "nixpkgs-unstable": "nixpkgs-unstable",
"simple-nixos-mailserver": "simple-nixos-mailserver" "simple-nixos-mailserver": "simple-nixos-mailserver"
} }

View File

@ -2,10 +2,11 @@
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-21.05"; nixpkgs.url = "github:nixos/nixpkgs/nixos-21.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs-nyanloutre-pysmart.url = "github:nyanloutre/nixpkgs/pysmart-init";
simple-nixos-mailserver.url = "gitlab:simple-nixos-mailserver/nixos-mailserver/nixos-21.05"; simple-nixos-mailserver.url = "gitlab:simple-nixos-mailserver/nixos-mailserver/nixos-21.05";
}; };
outputs = { self, nixpkgs, nixpkgs-unstable, simple-nixos-mailserver }: { outputs = { self, nixpkgs, nixpkgs-unstable, simple-nixos-mailserver, nixpkgs-nyanloutre-pysmart }: {
nixosConfigurations.loutreos = nixpkgs.lib.nixosSystem { nixosConfigurations.loutreos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux"; system = "x86_64-linux";
modules = [ modules = [
@ -18,6 +19,23 @@
"${nixpkgs-unstable}/nixos/modules/services/audio/navidrome.nix" "${nixpkgs-unstable}/nixos/modules/services/audio/navidrome.nix"
simple-nixos-mailserver.nixosModule simple-nixos-mailserver.nixosModule
./systems/LoutreOS/configuration.nix ./systems/LoutreOS/configuration.nix
({ pkgs, ... }: {
systemd.services.ipmihddtemp = {
description = "IPMI HDD temp fan control";
wantedBy = ["multi-user.target"];
path = with pkgs;[ ipmitool smartmontools ];
serviceConfig = {
ExecStart = with nixpkgs-nyanloutre-pysmart.legacyPackages.x86_64-linux;
let env = python3Packages.python.buildEnv.override {
extraLibs = with python3Packages;[ pysmart ];
ignoreCollisions = true;
};
in "${pkgs.writeShellScriptBin "run.sh" ''
${env}/bin/python ${pkgs.writeScript "ipmihddtemp.py" "${builtins.readFile ./ipmihddtemp.py}"}
''}/bin/run.sh";
};
};
})
]; ];
}; };

42
ipmihddtemp.py Normal file
View File

@ -0,0 +1,42 @@
import math
import subprocess
import time
from pySMART import DeviceList
MIN_FAN_SPEED = 30
MAX_FAN_SPEED = 100
MIN_HDD_TEMP = 30
MAX_HDD_TEMP = 50
devlist = DeviceList()
# Put fans in full speed mode
subprocess.run(["ipmitool", "raw", "0x30", "0x45", "0x01", "0x01"])
while True:
for device in devlist:
device.update()
# Linear fan speed between MIN_FAN_SPEED and MAX_FAN_SPEED
fan_speed = max(
min(
math.ceil(
MIN_FAN_SPEED
+ (
(MAX_FAN_SPEED - MIN_FAN_SPEED)
* (
(max([x.temperature for x in devlist]) - MIN_HDD_TEMP)
/ (MAX_HDD_TEMP - MIN_HDD_TEMP)
)
)
),
MAX_FAN_SPEED,
),
MIN_FAN_SPEED,
)
subprocess.run(["ipmitool", "raw", "0x30", "0x70", "0x66", "0x01", "0x00", hex(fan_speed)])
time.sleep(10)