<commit_before>#!/bin/bash -

# Check Memory as well here, if memory is low don't write ...
#
# this should deal with /dev/watchdog

mem=0

swapmem=$(free -m | awk '/Swap:/{print $4}')
realmem=$(free -m | awk '/Mem:/{print $7}')
totalmem=$(( swapmem + realmem ))

if [[ -n "$swapmem" && $swapmem -gt 0 ]]; then
  mem=$totalmem
  (( mem <= 35 )) && echo fireapi swap $mem >> /home/pi/.forever/top_before_reboot.log
else
  mem=$realmem
  (( mem <= 35 )) && echo fireapi real mem $mem >> /home/pi/.forever/top_before_reboot.log
fi

(( mem <= 0 )) && mem=$(free -m | awk '/Mem:/{print $7}')
(( mem <= 35 )) && /home/pi/firewalla/scripts/firelog -t local -m "REBOOT: Memory less than 35 $mem"
(( mem <= 35 )) && /home/pi/firewalla/scripts/free-memory-lastresort 

#DEFAULT_ROUTE=$(ip route show default | awk '/default/ {print $3}')
DEFAULT_ROUTE=$(ip r |grep eth0 | grep default | cut -d ' ' -f 3 | sed -n '1p')

touch /tmp/watchdog 

for i in `seq 1 10`; do
    if ping -w 1 -c 1 $DEFAULT_ROUTE &> /dev/null
    then
#      /home/pi/firewalla/scripts/firelog -t debug -m"FIREWALLA PING WRITE"
       exit 0
    else
      echo "Ping Failed"
      /home/pi/firewalla/scripts/firelog -t debug -m "FIREWALLA PING NO Local Network $DEFAULT_ROUTE"
      sleep 1
      touch /tmp/watchdog 
    fi
done

# if there is api process running, we have likely lost connection ...
# reboot ...

api_process_cnt=`sudo systemctl status fireapi |grep 'active (running)' | wc -l`
if [[ $api_process_cnt > 0 ]]; then
   /home/pi/firewalla/scripts/firelog -t cloud -m "REBOOT: FIREWALLA PING NO Local Network REBOOT "
   /home/pi/firewalla/scripts/fire-rebootf 
   exit 0
fi

FOUND=`grep "eth0:" /proc/net/dev`
if [ -n "$FOUND" ] ; then
   echo found
else
   /home/pi/firewalla/scripts/firelog -t cloud -m "REBOOT: FIREWALLA PING MISSING ETH0 Local Network REBOOT "
   /home/pi/firewalla/scripts/fire-rebootf 
   exit 0
fi

/home/pi/firewalla/scripts/firelog -t debug -m "FIREWALLA PING WRITE2"
<commit_msg>add config file for no_network_reboot and no_eth0_reboot<commit_after>#!/bin/bash -

# Check Memory as well here, if memory is low don't write ...
#
# this should deal with /dev/watchdog

mem=0

swapmem=$(free -m | awk '/Swap:/{print $4}')
realmem=$(free -m | awk '/Mem:/{print $7}')
totalmem=$(( swapmem + realmem ))

if [[ -n "$swapmem" && $swapmem -gt 0 ]]; then
  mem=$totalmem
  (( mem <= 35 )) && echo fireapi swap $mem >> /home/pi/.forever/top_before_reboot.log
else
  mem=$realmem
  (( mem <= 35 )) && echo fireapi real mem $mem >> /home/pi/.forever/top_before_reboot.log
fi

(( mem <= 0 )) && mem=$(free -m | awk '/Mem:/{print $7}')
(( mem <= 35 )) && /home/pi/firewalla/scripts/firelog -t local -m "REBOOT: Memory less than 35 $mem"
(( mem <= 35 )) && /home/pi/firewalla/scripts/free-memory-lastresort 

#DEFAULT_ROUTE=$(ip route show default | awk '/default/ {print $3}')
DEFAULT_ROUTE=$(ip r |grep eth0 | grep default | cut -d ' ' -f 3 | sed -n '1p')

touch /tmp/watchdog 

for i in `seq 1 10`; do
    if ping -w 1 -c 1 $DEFAULT_ROUTE &> /dev/null
    then
#      /home/pi/firewalla/scripts/firelog -t debug -m"FIREWALLA PING WRITE"
       exit 0
    else
      echo "Ping Failed"
      /home/pi/firewalla/scripts/firelog -t debug -m "FIREWALLA PING NO Local Network $DEFAULT_ROUTE"
      sleep 1
      touch /tmp/watchdog 
    fi
done

# if there is api process running, we have likely lost connection ...
# reboot ...

api_process_cnt=`sudo systemctl status fireapi |grep 'active (running)' | wc -l`
if [[ $api_process_cnt > 0 && ! -e /home/pi/.firewalla/config/disable_no_network_reboot ]]; then
   /home/pi/firewalla/scripts/firelog -t cloud -m "REBOOT: FIREWALLA PING NO Local Network REBOOT "
   /home/pi/firewalla/scripts/fire-rebootf 
   exit 0
fi

FOUND=`grep "eth0:" /proc/net/dev`
if [ -n "$FOUND" ] ; then
   echo found
else
  if [[ ! -e /home/pi/.firewalla/config/disable_no_eth0_reboot ]]; then
    /home/pi/firewalla/scripts/firelog -t cloud -m "REBOOT: FIREWALLA PING MISSING ETH0 Local Network REBOOT "
    /home/pi/firewalla/scripts/fire-rebootf 
  fi
  exit 0
fi

/home/pi/firewalla/scripts/firelog -t debug -m "FIREWALLA PING WRITE2"

{'fraction_non_alphanumeric': 0.15397590361445784, 'fraction_numerical': 0.0163855421686747, 'mean_word_length': 3.0856299212598426, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1737276', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1571, 'n_words': 451}