-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from vahid-dan/main
Bug fixes, improvements and new modules and features
- Loading branch information
Showing
9 changed files
with
252 additions
and
19 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/bin/bash | ||
|
||
# Network Interface Monitor Module | ||
# Executd from the Gateways | ||
# Monitors network activity on specific interface(s) | ||
# Usage: Run when needed | ||
|
||
########## HEADER ########## | ||
|
||
module_name=general # status_update is a part of general | ||
|
||
# Load utility functions and configurations for gateways | ||
source /home/ubuntu/miscellaneous/gateways/base/utils.sh | ||
|
||
# Redirect all output of this module to log_to_file function | ||
exec > >(while IFS= read -r line; do log_to_file "$module_name" "$line"; echo "$line"; done) 2>&1 | ||
|
||
echo "########## START ##########" | ||
|
||
########## BODY ########## | ||
|
||
# Function to display modules and their status | ||
display_modules_status() { | ||
echo "Modules and their current status:" | ||
modules=($(yq eval 'keys | .[]' $config_file)) | ||
for idx in "${!modules[@]}"; do | ||
if [ "${modules[$idx]}" == "general" ]; then | ||
status=$(yq e ".general.gateway_maintenance_mode" $config_file) | ||
echo "$((idx+1)). ${modules[$idx]} (maintenance_mode): $status" | ||
else | ||
status=$(yq e ".${modules[$idx]}.enabled" $config_file) | ||
echo "$((idx+1)). ${modules[$idx]}: $status" | ||
fi | ||
done | ||
} | ||
|
||
# Function to toggle the status of a module | ||
toggle_module_status() { | ||
local opt="$1" | ||
local current_status | ||
|
||
if [ "$opt" == "general" ]; then | ||
current_status=$(get_config_value "general" "gateway_maintenance_mode") | ||
if [ "$current_status" == "true" ]; then | ||
yq eval ".${opt}.gateway_maintenance_mode = false" -i $config_file | ||
echo "Set ${opt}'s gateway_maintenance_mode to false." | ||
else | ||
yq eval ".${opt}.gateway_maintenance_mode = true" -i $config_file | ||
echo "Set ${opt}'s gateway_maintenance_mode to true." | ||
fi | ||
else | ||
current_status=$(get_config_value "$opt" "enabled") | ||
if [ "$current_status" == "true" ]; then | ||
yq eval ".${opt}.enabled = false" -i $config_file | ||
echo "Set ${opt} to false." | ||
else | ||
yq eval ".${opt}.enabled = true" -i $config_file | ||
echo "Set ${opt} to true." | ||
fi | ||
fi | ||
} | ||
|
||
# Display modules and their status | ||
display_modules_status | ||
|
||
# Get user selection | ||
echo "Select modules to toggle its status (e.g., 1 3 6) or enter 'q' to exit without changes:" | ||
read -a selections | ||
|
||
for selected in "${selections[@]}"; do | ||
# Exit if user chooses the exit option | ||
if [ "$selected" == "q" ]; then | ||
echo "Exiting without changes." | ||
|
||
# Validate user input | ||
elif [ "$selected" -lt 1 ] || [ "$selected" -gt "${#modules[@]}" ]; then | ||
echo "Invalid selection: $selected. Exiting without changes." | ||
|
||
else | ||
idx=$((selected-1)) | ||
toggle_module_status "${modules[$idx]}" | ||
fi | ||
done | ||
|
||
# After toggling the status, display and log the final status | ||
echo "Final Status:" | ||
display_modules_status 2>&1 | tee $general_data_dir/$general_git_logs_branch/$general_module_toggler_log_file | ||
|
||
########## FOOTER ########## | ||
|
||
echo "########## END ##########" | ||
|
||
# Close stdout and stderr | ||
exec >&- 2>&- | ||
# Wait for all background processes to complete | ||
wait |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/bin/bash | ||
|
||
# LoRa Module | ||
# This module sets up and configures the LoRa interface, applies traffic control, configures IP layer as NAT in "noevio" mode, and configures IP layer to route through the gateway it connects to in "pendant" mode. | ||
|
||
# mode: evio (if the fitlet2 serves as an EdgeVPN (evio) switch) | ||
# When fitlet2 gateway is connected to a LoRa radio but not a cell link (e.g. at the FCR Weir) | ||
# It configures the LoRa tnc0 interface, applies traffic control, and configures IP layer to route through the gateway it connects to | ||
# this assumes the evio docker container is already running | ||
# docker run -d -v /home/$USER/.evio/config.json:/etc/opt/evio/config.json -v /var/log/evio/:/var/log/evio/ --restart always --privileged --name evio-node --network host edgevpnio/evio-node:latest | ||
|
||
# mode: noevio (if the fitlet2 is not running as an EdgeVPN (evio) switch to the other node) | ||
# When fitlet2 gateway is connected to a LoRa radio and a cell link (e.g. at the FCR Catwalk) | ||
|
||
# mode: pendant | ||
# When fitlet2 gateway is connected to a LoRa radio but not a cell link (e.g. at the FCR Weir) | ||
|
||
# Usage: Run after reboot and periodically, every hour, for instance. | ||
|
||
########## HEADER ########## | ||
|
||
module_name=lora | ||
|
||
# Load utility functions and configurations for gateways | ||
source /home/ubuntu/miscellaneous/gateways/base/utils.sh | ||
|
||
# Check if the module is enabled | ||
check_if_enabled "$module_name" | ||
|
||
# Redirect all output of this module to log_to_file function | ||
exec > >(while IFS= read -r line; do log_to_file "$module_name" "$line"; echo "$line"; done) 2>&1 | ||
|
||
echo "########## START ##########" | ||
|
||
########## BODY ########## | ||
|
||
# Bring lora interface down and up | ||
/usr/bin/killall tncattach || true | ||
|
||
sleep 5 | ||
|
||
case $lora_mode in | ||
"pendant") | ||
/usr/local/bin/tncattach /dev/$lora_serial_interface $lora_baud_rate -d -e -n -m $lora_mtu -i $lora_node_ip | ||
/usr/sbin/tc qdisc add dev $lora_lora_interface root tbf rate "$lora_rate"kbit burst "$lora_burst"kbit latency "$lora_latency"ms | ||
/usr/sbin/ip route delete default | ||
/usr/sbin/ip route add default via $lora_switch_ip | ||
;; | ||
|
||
"noevio") | ||
/usr/local/bin/tncattach /dev/$lora_serial_interface $lora_baud_rate -d -e -n -m $lora_mtu -i $lora_node_ip | ||
/usr/sbin/tc qdisc add dev $lora_lora_interface root tbf rate "$lora_rate"kbit burst "$lora_burst"kbit latency "$lora_latency"ms | ||
echo 1 > /proc/sys/net/ipv4/ip_forward | ||
/sbin/iptables -t nat -A POSTROUTING -o $lora_switch_interface -j MASQUERADE | ||
/sbin/iptables -A FORWARD -i $lora_switch_interface -o $lora_lora_interface -m state --state RELATED,ESTABLISHED -j ACCEPT | ||
/sbin/iptables -A FORWARD -i $lora_lora_interface -o $lora_switch_interface -j ACCEPT | ||
;; | ||
|
||
"evio") | ||
/usr/local/bin/tncattach /dev/$lora_serial_interface $lora_baud_rate -d -e -n -m $lora_mtu | ||
/usr/bin/docker exec -it evio-node ovs-vsctl add-port $lora_evio_interface $lora_lora_interface | ||
/usr/bin/docker exec -it evio-node ovs-vsctl set interface $lora_lora_interface ingress_policing_rate=$lora_ingress_policing_rate | ||
/usr/bin/docker exec -it evio-node ovs-vsctl set interface $lora_lora_interface ingress_policing_burst=$lora_ingress_policing_burst | ||
/usr/sbin/tc qdisc add dev $lora_lora_interface root tbf rate "$lora_rate"kbit burst "$lora_burst"kbit latency "$lora_latency"ms | ||
/usr/sbin/sysctl -w net.ipv4.ip_forward=1 | ||
/usr/sbin/iptables -t nat -A POSTROUTING -s $lora_node_ip -j MASQUERADE | ||
;; | ||
|
||
*) | ||
echo "Invalid mode: $lora_mode. Exiting." | ||
exit 1 | ||
;; | ||
esac | ||
|
||
########## FOOTER ########## | ||
|
||
echo "########## END ##########" | ||
|
||
# Close stdout and stderr | ||
exec >&- 2>&- | ||
# Wait for all background processes to complete | ||
wait |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
# Nebula Module | ||
# This module manages the Nebula service by ensuring the service is restarted and logs are captured. | ||
# Usage: Run after reboot and periodically, every hour, for instance. | ||
|
||
########## HEADER ########## | ||
|
||
module_name=nebula | ||
|
||
# Load utility functions and configurations for gateways | ||
source /home/ubuntu/miscellaneous/gateways/base/utils.sh | ||
|
||
# Check if the module is enabled | ||
check_if_enabled "$module_name" | ||
|
||
# Redirect all output of this module to log_to_file function | ||
exec > >(while IFS= read -r line; do log_to_file "$module_name" "$line"; echo "$line"; done) 2>&1 | ||
|
||
echo "########## START ##########" | ||
|
||
########## BODY ########## | ||
|
||
# Killing any running instance of nebula | ||
/usr/bin/killall nebula || true | ||
|
||
# Start nebula with configuration | ||
nohup /etc/nebula/nebula -config /etc/nebula/config.yaml & | ||
|
||
########## FOOTER ########## | ||
|
||
echo "########## END ##########" | ||
|
||
# Close stdout and stderr | ||
exec >&- 2>&- | ||
# Wait for all background processes to complete | ||
wait | ||
cront |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters