From 6731fe48b834a29c681c8e056189d97b6c01f746 Mon Sep 17 00:00:00 2001 From: tigerblue77 <37409593+tigerblue77@users.noreply.github.com> Date: Mon, 11 Apr 2022 20:38:11 +0200 Subject: [PATCH] Beautify code and log messages --- Dockerfile | 17 +++++++++-------- README.md | 38 ++++++++++++++++++++++++++++++++------ check-temp.sh | 29 ----------------------------- check_temp.sh | 34 ++++++++++++++++++++++++++++++++++ crontab | 2 +- startup.sh | 12 ++++++------ 6 files changed, 82 insertions(+), 50 deletions(-) delete mode 100755 check-temp.sh create mode 100755 check_temp.sh diff --git a/Dockerfile b/Dockerfile index a0dd958..0287caf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,26 +4,27 @@ RUN apt-get update RUN apt-get install ipmitool cron -y -COPY crontab /etc/cron.d/fan-control +COPY crontab /etc/cron.d/dell_idrac_fan_control -RUN chmod 0777 /etc/cron.d/fan-control +RUN chmod 0777 /etc/cron.d/dell_idrac_fan_control RUN touch /var/log/cron.log -ADD check-temp.sh /opt/check-temp.sh +ADD check_temp.sh /opt/check_temp.sh ADD startup.sh /startup.sh -RUN chmod 0777 /opt/check-temp.sh +RUN chmod 0777 /opt/check_temp.sh RUN chmod 0777 /startup.sh -RUN /usr/bin/crontab /etc/cron.d/fan-control +RUN /usr/bin/crontab /etc/cron.d/dell_idrac_fan_control -# you should override these when running. See README.md +# you should override these default values when running. See README.md #ENV IDRAC_HOST 192.168.1.100 ENV IDRAC_HOST local #ENV IDRAC_USER root -#ENV IDRAC_PW calvin +#ENV IDRAC_PASSWORD calvin ENV FAN_SPEED 5 -CMD /startup.sh && cron && tail -f /var/log/cron.log + +CMD /startup.sh && /opt/check_temp.sh && cron && tail -f /var/log/cron.log diff --git a/README.md b/README.md index c915a32..6e75f44 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,34 @@ # IDRAC Fan Controller Docker Image -To use, +- `IDRAC_HOST` parameter can be set to "local" or to your distant iDRAC's IP address. Default value is "local". +- `IDRAC_USERNAME` parameter is only necessary if you're adressing a distant iDRAC. Default value is "root". +- `IDRAC_PASSWORD` parameter is only necessary if you're adressing a distant iDRAC. Default value is "calvin". +- `FAN_SPEED` parameter can be set as a decimal or hexadecimal value (0x00 to 0x64). Default value is 5 (%). -`docker run -e IDRAC_HOST= -e IDRAC_USER= -e IDRAC_PW= -e FAN_SPEED= alombardo4/idrac-fan-control:latest` +To use: -`FAN_SPEED` can be set as a decimal or hexadecimal value (0x00 to 0x64). Default value is 5 (%). +1. with local iDRAC: + +```bash +docker run -d \ + --name Dell_iDRAC_fan_controller \ + --restart unless-stopped \ + -e FAN_SPEED= \ + alombardo4/idrac-fan-control:latest +``` + +2. with LAN iDRAC: + +```bash +docker run -d \ + --name Dell_iDRAC_fan_controller \ + --restart unless-stopped \ + -e IDRAC_HOST= \ + -e IDRAC_USERNAME= \ + -e IDRAC_PASSWORD= \ + -e FAN_SPEED= \ + alombardo4/idrac-fan-control:latest +``` `docker-compose.yml` examples: @@ -16,6 +40,7 @@ version: '3' services: Dell_iDRAC_fan_controller: image: alombardo4/idrac-fan-control + container_name: Dell_iDRAC_fan_controller restart: unless-stopped environment: - IDRAC_HOST=local # can be omitted as it is the default value @@ -32,10 +57,11 @@ version: '3' services: Dell_iDRAC_fan_controller: image: alombardo4/idrac-fan-control + container_name: Dell_iDRAC_fan_controller restart: unless-stopped environment: - - IDRAC_HOST=192.168.1.100 # override to the IP of your IDRAC - - IDRAC_USER=root # set to your IPMI username - - IDRAC_PW=calvin # set to your IPMI password + - IDRAC_HOST=192.168.1.100 # override to the IP address of your IDRAC + - IDRAC_USERNAME=root # set to your IPMI username + - IDRAC_PASSWORD=calvin # set to your IPMI password - FAN_SPEED=0x05 # set to the decimal or hexadecimal value you want to set the fans to (from 0 to 100%) ``` diff --git a/check-temp.sh b/check-temp.sh deleted file mode 100755 index f32d4bf..0000000 --- a/check-temp.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -IPMIHOST=`cat /host.txt` -IPMIUSER=`cat /user.txt` -IPMIPW=`cat /pw.txt` -DECIMAL_FAN_SPEED=`cat /decimal_fan_speed.txt` -HEXADECIMAL_FAN_SPEED=`cat /hexadecimal_fan_speed.txt` - -MAXTEMP=32 - -if [[ $IPMIHOST == "local" ]] -then - LOGIN_STRING='open' -else - LOGIN_STRING="lanplus -H $IPMIHOST -U $IPMIUSER -P $IPMIPW" -fi - -TEMP=$(ipmitool -I $LOGIN_STRING sdr type temperature |grep Inlet |grep degrees |grep -Po '\d{2}' | tail -1) - -echo "Current Temp is $TEMP C" -if [ $TEMP -gt $MAXTEMP ]; -then - echo "Temp is too high. Activating dynamic fan control" - ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x01 -else - echo "Temp is OK. Using manual fan control" - ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x00 - ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x02 0xff $HEXADECIMAL_FAN_SPEED -fi diff --git a/check_temp.sh b/check_temp.sh new file mode 100755 index 0000000..23c2c9e --- /dev/null +++ b/check_temp.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +IPMI_HOST=`cat /idrac_host.txt` +IPMI_USERNAME=`cat /idrac_username.txt` +IPMI_PASSWORD=`cat /idrac_password.txt` +DECIMAL_FAN_SPEED=`cat /decimal_fan_speed.txt` +HEXADECIMAL_FAN_SPEED=`cat /hexadecimal_fan_speed.txt` + +MAX_INLET_TEMPERATURE=32 + +if [[ $IPMI_HOST == "local" ]] +then + LOGIN_STRING='open' +else + LOGIN_STRING="lanplus -H $IPMI_HOST -U $IPMI_USERNAME -P $IPMI_PASSWORD" +fi + +INLET_TEMPERATURE=$(ipmitool -I $LOGIN_STRING sdr type temperature |grep Inlet |grep degrees |grep -Po '\d{2}' | tail -1) + +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' # No Color + +echo "------------------------------------" +echo "Current inlet temperature is $INLET_TEMPERATURE °C." +if [ $INLET_TEMPERATURE -gt $MAX_INLET_TEMPERATURE ] +then + printf "Inlet temperature is ${RED}too high${NC}. Activating default dynamic fan control." + ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x01 +else + printf "Inlet temperature is ${GREEN}OK${NC}. Using manual fan control with ${DECIMAL_FAN_SPEED}%% fan speed." + ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x01 0x00 + ipmitool -I $LOGIN_STRING raw 0x30 0x30 0x02 0xff $HEXADECIMAL_FAN_SPEED +fi diff --git a/crontab b/crontab index f1e3416..331bd43 100644 --- a/crontab +++ b/crontab @@ -1 +1 @@ -* * * * * /bin/bash -c "/opt/check-temp.sh &> /var/log/cron.log" +* * * * * /bin/bash -c "/opt/check_temp.sh &> /var/log/cron.log" diff --git a/startup.sh b/startup.sh index 91aebaf..72317df 100644 --- a/startup.sh +++ b/startup.sh @@ -1,8 +1,8 @@ #!/bin/bash -echo $IDRAC_HOST >> /host.txt -echo $IDRAC_USER >> /user.txt -echo $IDRAC_PW >> /pw.txt +echo $IDRAC_HOST >> /idrac_host.txt +echo $IDRAC_USERNAME >> /idrac_username.txt +echo $IDRAC_PASSWORD >> /idrac_password.txt if [[ $FAN_SPEED == 0x* ]] then @@ -16,10 +16,10 @@ fi echo $DECIMAL_FAN_SPEED >> /decimal_fan_speed.txt echo $HEXADECIMAL_FAN_SPEED >> /hexadecimal_fan_speed.txt -echo "Host: `cat /host.txt`" +echo "Idrac/IPMI host: `cat /idrac_host.txt`" if [[ $IDRAC_HOST != "local" ]] then - echo "User: `cat /user.txt`" - echo "PW: `cat /pw.txt`" + echo "Idrac/IPMI user: `cat /idrac_username.txt`" + echo "Idrac/IPMI password: `cat /idrac_password.txt`" fi echo "Fan speed objective: `cat /decimal_fan_speed.txt`%"