Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)**
Expand All @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions fanctl.service
Original file line number Diff line number Diff line change
@@ -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
13 changes: 7 additions & 6 deletions fanctl.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ""
Expand All @@ -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
}

Expand Down