Monday, March 08, 2021

Creating ipip tunnels in RedHat 8 that is compatible with LVS/TUN.

Every few seasons I built a virtual LVS (Linux Virtual Server) mock up just to keep in shape.  LVS-TUN (lvs/tunnel mode) ipip configuration for RH8 had me stumped for a while.  

There was a change from RH7 to RH8 in that network scripts are being deprecated.  So, /etc/sysconfig/ network scripts behave just a bit different.  For one thing I could not build a reliable ipip tunnel interface in RH8 even after installing and using traditional RH-style network scripts.  

After a lot of difficult tests I am posting the solution for keeping up an ipip tunnel interface for RH8.  Here it is:

# In this example 192.168.131.239 is the RIP (Real Server IP) IP address, 
# 192.168.131.235 is the VIP address.
nmcli con add type ip-tunnel ip-tunnel.mode ipip con-name tun0
          ifname tun0 remote 0.0.0.0 local 192.168.131.239
nmcli con mod tun0 ipv4.addresses 192.168.131.235
nmcli con mod tun0 ipv4.method manual
nmcli con up tun0

The key thing to remember is that the remote ip should be 0.0.0.0.    In RH7 you could use an ipip for LVS-TUN without specifying remote and local IP's.  

If this helps somebody out there with a similar problem, please let me know by replying to this blog.



Wednesday, February 17, 2021

Raspberry pi simple fan control script

Here is a simple fan control script that I made to turn on and off a raspberry pi fan.  It turns on a fan when the temp reaches a threshold (in this case, 60 degrees).  

#!/bin/bash
#
# Wed Feb 17 19:14:54 EST 2021 JondZ very simple fan controller
GPIO_PIN=4
GPIO_NAME=gpio${GPIO_PIN}
GPIO_PATH=/sys/class/gpio/$GPIO_NAME/value
TEMP_THRESHOLD=60000
TEMP_SOURCE_FILE=/sys/class/thermal/thermal_zone0/temp
# 600: 10 minutes
# 900: 15 minutes
# 1800: 30 minutes
SLEEP_TIME=600
SLEEP_POLL=10
function get_temp {
         if [[ -e $TEMP_SOURCE_FILE ]] ; then
            cat $TEMP_SOURCE_FILE
         fi
         }
function init_ports {
         if [[ ! -e /sys/class/gpio/$GPIO_NAME ]]; then
            echo $GPIO_PIN > /sys/class/gpio/export && \
            sleep 5 && \
            echo out > /sys/class/gpio/$GPIO_NAME/direction
         fi
         }
init_ports
function turn_on_fan {
         temp=$(get_temp)
         if [[ -e $GPIO_PATH ]]; then
            echo "$(date) fan on ($temp)"
            v=$(< $GPIO_PATH )
            if [[ $v == 0 ]]; then
               echo 1 > $GPIO_PATH
            fi
         fi
         }
function turn_off_fan {
         temp=$(get_temp)
         if [[ -e $GPIO_PATH ]]; then
            v=$(< $GPIO_PATH )
            if [[ $v == 1 ]]; then
               echo "$(date) fan off ($temp)"
               echo 0 > $GPIO_PATH
            fi
         fi
         }
while :
   do
   CT=$(get_temp)
   if [[ $TEMP_THRESHOLD -lt $CT ]]; then
      turn_on_fan
      sleep $SLEEP_TIME
   else
      turn_off_fan
   fi
   sleep $SLEEP_POLL
   done
 

Here is the systemd script:

[Unit]
Description=Simple Fan Controller
DefaultDependencies=no
After=sysinit.target

[Service]
Type=simple
ExecStart=/root/scriptsd/system-fan-control.sh

[Install]
WantedBy=graphical.target multi-user.target

As far as I can see it is working fine.

Here is a picture of the circuit that i soldered.  I copied the circuit from some other site on the web.   This comprises of a resistor, a transistor, and a diode.


Here is what the fan circuit looks like on my setup.  The case is already crowded with an OLED display and an RTC clock:



There may be minor bugs.  I was tired from soldering so I only did the coding in a few minutes' rush so comments are welcome...

EP 20210217


Creating ipip tunnels in RedHat 8 that is compatible with LVS/TUN. Every few seasons I built a virtual LVS (Linux Virtual Server) mock up ju...