diff --git a/README.MD b/README.MD index 14c3718..2317222 100644 --- a/README.MD +++ b/README.MD @@ -46,7 +46,7 @@ cd fanctl 2. Make the script executable: ```bash -chmod +x fan_control.sh +chmod +x fanctl.sh ``` 3. Configure iDRAC settings: @@ -58,6 +58,7 @@ chmod +x fan_control.sh - Click Apply 4. Adjust script variables: + Open the script in a text editor and modify the following variables as needed: - `IPMI_HOST`: Your iDRAC IP address or FQDN **(Required)** - `IPMI_USER`: iDRAC username **(Required)** @@ -67,16 +68,50 @@ chmod +x fan_control.sh - `LOG_FILE`: Path to the log file **(Optional)** - `TEMP_MAX`: Maximum safe temperature threshold **(Optional)** + +5. For your **Credentials** use a secret file: + +The secret file: +- create a idrac file in /root/.connexions/idrac +- fill it with three lines : ip, login an password. +- protect-it + +```bash +touch /root/.connexions/idrac +sudo chmod 600 /root/.connexions/idrac +``` + ## Usage Run the script with: ```bash -./fan_control.sh +./fanctl.sh ``` For long-term use, consider setting up the script as a systemd service or running it in a screen/tmux session. +### Installation with systemd + +1. Copy script in /usr/sbin + +```bash +sudo cp fanctl.sh /usr/sbin/ +``` + +2. Copy .service file in /etc/systemd/system + +```bash +sudo cp fanctl.service /etc/systemd/system +``` + +3. Activate and start the service + +```bash +sudo systemctl enable fanctl +sudo systemctl start fanctl +``` + ## Important Notes - This script takes control of your server's fans. Use at your own risk and monitor temperatures closely when first implementing. diff --git a/fanctl.service b/fanctl.service new file mode 100644 index 0000000..8d1a3a2 --- /dev/null +++ b/fanctl.service @@ -0,0 +1,15 @@ +[Unit] +Description=fanctl : idrac fan control service +Requires=network.target +After=systemd-user-sessions.service + +[Service] +Type=simple +ExecStart=/usr/sbin/fanctl.sh +ExecStop=/bin/bash -c 'kill -9 $(ps aux | grep fanctl.sh | grep -v grep | awk '{print $2}')' +User=root +#ExecStartPre=/bin/sleep 30 +Requires=NetworkManager.service + +[Install] +WantedBy=multi-user.target diff --git a/fanctl.sh b/fanctl.sh old mode 100644 new mode 100755 index bc127eb..e540cb6 --- a/fanctl.sh +++ b/fanctl.sh @@ -1,9 +1,10 @@ #!/bin/bash # IPMI iDrac Settings -IPMI_HOST="idrac.lab.local" # Your iDrac IP Address or FQDN -IPMI_USER="root" # iDrac Username -IPMI_PASS="calvin" # iDrac Password +IPMI_SECRET_FILE=~/.connexions/idrac # 3 lines, IP\nlogin\npassword +IPMI_HOST=$(sed -n '1p' $IPMI_SECRET_FILE) # Your iDrac IP Address or FQDN (first line) +IPMI_USER=$(sed -n '2p' $IPMI_SECRET_FILE) # iDrac Username (second line) +IPMI_PASS=$(sed -n '3p' $IPMI_SECRET_FILE) # iDrac Password (third line) # Fan Speed Thresholds TEMP_THRESHOLD_1=50 @@ -19,7 +20,7 @@ TEMP_THRESHOLD_8=90 CHECK_INTERVAL=60 # Log Path -LOG_FILE="/var/log/fanctrl.log" +LOG_FILE="/var/log/fanctl.log" # Danger Zone Temperature Threshold (in Celsius) TEMP_MAX=90 @@ -50,7 +51,7 @@ check_dependencies() { # Get CPU Temps and Parse Out Inlet & Exhaust get_cpu_temperatures() { - temps=$(ipmitool -I lanplus -H $IPMI_HOST -U $IPMI_USER -P $IPMI_PASS sdr type temperature | grep -E '^\s*Temp\s+\|' | awk -F'|' '{print $5}' | awk '{print $1}') + temps=$(ipmitool -I lanplus -H $IPMI_HOST -U $IPMI_USER -P $IPMI_PASS sdr type temperature | grep -E '^\s*Temp\s+\|' | awk -F'|' '{print $5}' | grep -v Disabled | awk '{print $1}') if [ $? -ne 0 ]; then log "ERROR" "Failed to retrieve temperatures from IPMI. Error: $temps" echo "" @@ -65,7 +66,7 @@ get_avg_cpu_temperature() { if [ -z "$temps" ]; then echo "" else - echo "$temps" | awk '{sum+=$1} END {if (NR>0) print sum/NR; else print ""}' | awk '{printf "%.1f", $0}' + echo "$temps" | awk '{sum+=$1} END {if (NR>0) print sum/NR; else print ""}' | LC_ALL=C awk '{printf "%.1f", $0}' fi }