• 11 Posts
  • 239 Comments
Joined 2 years ago
cake
Cake day: July 5th, 2023

help-circle

  • 0 4   *   *   *    /usr/sbin/reboot
    

    Adjust interval as needed.

    Or if you want something a bit faster and less disruptive:

    #!/bin/sh
    
    NAME="$0"
    
    logger_cmd () {
      echo $@
      logger -p daemon.info -t "$NAME[$$]" $@
    }
    
    if ! which ncat 1>/dev/null
    then
      logger_cmd "ncat not found, installing..."
      opkg update && opkg install ncat
    fi
    
    chk_conn () {
      echo "Checking connectivity to $@"
      if ncat --send-only --recv-only -w 334ms $@ 2>/dev/null; then
        return 0
      fi
    
      logger_cmd "Cannot reach $@"
      return 1
    }
    
    restart_network_iface() {
        # TODO: Don't restart every minute
    
        COOLDOWN_LOCK=/tmp/internet-connectivity-watchcat.tmp
        COOLDOWN_SECONDS=300
    
        cooldown_time_end=$(cat $COOLDOWN_LOCK || echo 0)
    
        time_now="$(cat /proc/uptime)"
        time_now="${time_now%%.*}"
    
        cooldown_time_left=$((cooldown_time_end - time_now))
    
        if [ "$cooldown_time_left" -lt "1" ]
        then
            logger_cmd "Restarting network interface: \"$1\"."
            ifdown "$1"
            ifup "$1"
    
            cooldown_time_end=$((time_now + COOLDOWN_SECONDS))
            echo $cooldown_time_end > $COOLDOWN_LOCK
        else
            logger_cmd "Skipping interface \"$1\" restart due to cooldown. Cooldown left: $cooldown_time_left seconds"
        fi
    }
    
    
    logger_cmd "Checking internet connectivity..."
    
    if   chk_conn google.com 443 \
      || chk_conn amazon.com 443 \
      || chk_conn facebook.com 443 \
      || chk_conn cloudflare.com 443 \
      || chk_conn telekom.de 443
    then
      logger_cmd "Connected to internet."
    else
      logger_cmd  "Not connected to internet."
      restart_network_iface "$1"
    fi
    

    In restart_network_iface use /usr/sbin/reboot instead of interface up/down and run the script every few minutes via cron or systemd timer. This was written for OpenWrt so if you use that you can use it as-is. For other systems you’d also have to adjust the logger_cmd.

    You can place that on another machine and send a signal to a smart plug instead if you’re worried of a locked up / frozen router. That said if your router freezes like that, you should probably change it and you should be able to run this script on it.

















  • State planning and funding those plans. Taiwan, S. Korea and China (among others) have all planned their chip manufacturing capabilities and appropriately funded their development. Instead of relying on markets and firms to decide to do it, their governments decided that chips are strategically important input to their (and others’) economies and directed funding and labor to create those production capacities - education, machines, factories, etc. Critically we also used to do this in Europe and North America but we decided we’ll let the market make those decisions based on profit alone since the 80s. Turns out that the market had somewhat different ideas for making profit. Which is unsurprising since chip design and manufacturing is inherently long-term affair while threre’s plenty of profit to be made in short term lower risk bets. We still have an edge on the design side but I think it’s a matter of time till planners overtake us on that front too. You see what’s happening with Intel, laying highly skilled people off, investment banker directors considering selling their factories to TSMC, and the America First government proposing a foreign takeover instead of directing public capital and setting long term goals.