Add HA watchdog
This commit is contained in:
@@ -14,6 +14,7 @@ LINE_DOCKER=5
|
||||
LINE_ZSH=6
|
||||
LINE_TAILSCALE=7
|
||||
LINE_WIFITUI=8
|
||||
LINE_HA_WATCHDOG=9
|
||||
|
||||
teardown_ui() {
|
||||
local ROWS
|
||||
@@ -32,7 +33,7 @@ setup_ui() {
|
||||
LOG_END=$ROWS
|
||||
LOG_START=$(( LOG_END - MAX_LOG_LINES + 1 ))
|
||||
|
||||
local MIN_LOG_START=$(( LINE_WIFITUI + 4 ))
|
||||
local MIN_LOG_START=$(( LINE_HA_WATCHDOG + 4 ))
|
||||
if [ "$LOG_START" -le "$(( MIN_LOG_START - 1 ))" ]; then
|
||||
LOG_START=$MIN_LOG_START
|
||||
fi
|
||||
@@ -49,6 +50,7 @@ setup_ui() {
|
||||
printf "\033[${LINE_ZSH};1H [ ] ZSH\n"
|
||||
printf "\033[${LINE_TAILSCALE};1H [ ] Tailscale\n"
|
||||
printf "\033[${LINE_WIFITUI};1H [ ] Wifitui\n"
|
||||
printf "\033[${LINE_HA_WATCHDOG};1H [ ] HA Watchdog\n"
|
||||
|
||||
printf "\033[${SEP_LINE};1H${YELLOW}--- Verbose Logs ------------------------${NC}\n"
|
||||
|
||||
@@ -57,6 +59,7 @@ setup_ui() {
|
||||
update_status "$LINE_ZSH" "Pending"
|
||||
update_status "$LINE_TAILSCALE" "Pending"
|
||||
update_status "$LINE_WIFITUI" "Pending"
|
||||
update_status "$LINE_HA_WATCHDOG" "Pending"
|
||||
|
||||
printf "\033[${LOG_START};${LOG_END}r"
|
||||
printf "\033[${LOG_END};1H"
|
||||
@@ -70,7 +73,7 @@ update_status() {
|
||||
Pending) color="${NC}" ;;
|
||||
Running) color="${BLUE}" ;;
|
||||
Installed) color="${GREEN}" ;;
|
||||
Skipped) color="${YELLOW}" ;;
|
||||
Skipped|Removed) color="${YELLOW}" ;;
|
||||
esac
|
||||
printf "\0337\033[%d;4H${color}%-10s${NC}\0338" "$line" "$status"
|
||||
}
|
||||
@@ -80,7 +83,7 @@ print_step() {
|
||||
}
|
||||
|
||||
print_info() {
|
||||
local IL=${INFO_LINE:-$(( LINE_WIFITUI + 2 ))}
|
||||
local IL=${INFO_LINE:-$(( LINE_HA_WATCHDOG + 2 ))}
|
||||
printf "\0337\033[${IL};1H\033[K${CYAN} ➜ %s${NC}\0338" "$1"
|
||||
printf "${CYAN}➜ %s${NC}\n" "$1"
|
||||
}
|
||||
@@ -109,8 +112,10 @@ setup_server() {
|
||||
print_step "Setting up Server"
|
||||
print_info "Updating packages and configuring firewall..."
|
||||
sudo apt-get update
|
||||
sudo ufw allow 22/tcp
|
||||
sudo ufw allow 443/tcp
|
||||
sudo ufw allow 22/tcp #ssh
|
||||
sudo ufw allow 80/tcp #nginx
|
||||
sudo ufw allow 81/tcp #nginx
|
||||
sudo ufw allow 443/tcp #nginx
|
||||
sudo ufw allow 8123/tcp #homeassistant
|
||||
sudo ufw allow 8123/udp #homeassistant
|
||||
sudo ufw allow 3000/tcp #nextcloud
|
||||
@@ -195,6 +200,27 @@ setup_wifitui() {
|
||||
update_status "$line" "Installed"
|
||||
}
|
||||
|
||||
setup_ha_watchdog() {
|
||||
local line="$1"
|
||||
local watchdog_path="$(cd "$(dirname "$0")" && pwd)/ha_watchdog.sh"
|
||||
|
||||
print_step "Setting up HA Watchdog"
|
||||
if [ -f "/etc/cron.d/ha_watchdog" ]; then
|
||||
print_info "Uninstalling HA Watchdog..."
|
||||
sudo rm -f "/etc/cron.d/ha_watchdog"
|
||||
sudo rm -f "/usr/local/bin/ha_watchdog.sh" 2>/dev/null || true
|
||||
update_status "$line" "Removed"
|
||||
else
|
||||
print_info "Configuring HA Watchdog script permissions..."
|
||||
chmod +x "$watchdog_path"
|
||||
|
||||
print_info "Creating cron job (every 5 minutes)..."
|
||||
echo "*/5 * * * * root $watchdog_path" | sudo tee /etc/cron.d/ha_watchdog > /dev/null
|
||||
|
||||
update_status "$line" "Installed"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
clear
|
||||
printf "\n${BLUE}=========================================${NC}\n"
|
||||
@@ -231,10 +257,12 @@ main() {
|
||||
setup_zsh
|
||||
ask_optional_step "$LINE_TAILSCALE" "Tailscale" setup_tailscale
|
||||
ask_optional_step "$LINE_WIFITUI" "Wifitui" setup_wifitui
|
||||
ask_optional_step "$LINE_HA_WATCHDOG" "HA Watchdog" setup_ha_watchdog
|
||||
;;
|
||||
2)
|
||||
update_status "$LINE_TAILSCALE" "Skipped"
|
||||
update_status "$LINE_WIFITUI" "Skipped"
|
||||
update_status "$LINE_HA_WATCHDOG" "Skipped"
|
||||
setup_server
|
||||
setup_docker
|
||||
setup_zsh
|
||||
@@ -245,6 +273,7 @@ main() {
|
||||
update_status "$LINE_ZSH" "Skipped"
|
||||
ask_optional_step "$LINE_TAILSCALE" "Tailscale" setup_tailscale
|
||||
ask_optional_step "$LINE_WIFITUI" "Wifitui" setup_wifitui
|
||||
ask_optional_step "$LINE_HA_WATCHDOG" "HA Watchdog" setup_ha_watchdog
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user