93 lines
2.8 KiB
Bash
93 lines
2.8 KiB
Bash
#!/bin/bash
|
|
#vars
|
|
NF="\e[0m"
|
|
FB="\e[1m"
|
|
CG="\e[38;5;40m"
|
|
CR="\e[38;5;9m"
|
|
CY="\033[38;5;226m"
|
|
HOST=$(hostnamectl --static)
|
|
PUSHOVERAPI="https://api.pushover.net"
|
|
|
|
#functions
|
|
guardband() {
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${CR}Health check - ${FB}FAIL${NF} ${CR}- Services start aborted.${NF}"
|
|
PushoverReturnBootError
|
|
exit 0
|
|
else
|
|
echo -e "${CG}Health check - ${FB}PASS${NF}"
|
|
fi
|
|
}
|
|
|
|
verifyZFS() {
|
|
echo -e "${CY}Verify ZFS...${NF}"
|
|
systemctl is-active zfs-mount
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${CR}${FB}ZFS FAILED${NF}"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
PushoverReturnBootOK() {
|
|
if ! wget --spider "$PUSHOVERAPI" 2>/dev/null; then
|
|
echo -e "${CR}Pushover API unreachable - Message will retry.${NF}"
|
|
sleep 600
|
|
TITLE="$HOST Boot health check PASS"
|
|
APP_TOKEN="apipushoverapptoken"
|
|
USER_TOKEN="apipushoverusertoken"
|
|
MESSAGE="$HOST has successfully passed all healthchecks after bootup."
|
|
curl -s -F "token=$APP_TOKEN" -F "user=$USER_TOKEN" -F "title=$TITLE" -F "message=$MESSAGE" https://api.pushover.net/1/messages.json
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${CR}Pushover API still unreachable - Message not sent.${NF}"
|
|
fi
|
|
else
|
|
TITLE="$HOST Boot health check PASS"
|
|
APP_TOKEN="apipushoverapptoken"
|
|
USER_TOKEN="apipushoverusertoken"
|
|
MESSAGE="$HOST has successfully passed all healthchecks after bootup."
|
|
curl -s -F "token=$APP_TOKEN" -F "user=$USER_TOKEN" -F "title=$TITLE" -F "message=$MESSAGE" https://api.pushover.net/1/messages.json
|
|
fi
|
|
}
|
|
|
|
PushoverReturnBootError() {
|
|
if ! wget --spider "$PUSHOVERAPI" 2>/dev/null; then
|
|
echo -e "${CR}Pushover API unreachable - Message will retry.${NF}"
|
|
systemctl stop syncthing@root
|
|
systemctl stop cronicle
|
|
systemctl stop docker.socket
|
|
systemctl stop ampinstmgr
|
|
if [ "$HOST" = "Delta" ]
|
|
then
|
|
systemctl stop jellyfin #delta only
|
|
fi
|
|
systemctl stop rsyncd
|
|
sleep 600
|
|
TITLE="$HOST Boot health check FAIL"
|
|
APP_TOKEN="apipushoverapptoken"
|
|
USER_TOKEN="apipushoverusertoken"
|
|
MESSAGE="$HOST has failed a healthcheck after bootup - Services will not be initiated. Manual Intervention Required."
|
|
curl -s -F "token=$APP_TOKEN" -F "user=$USER_TOKEN" -F "title=$TITLE" -F "message=$MESSAGE" https://api.pushover.net/1/messages.json
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${CR}Pushover API still unreachable - Message not sent.${NF}"
|
|
fi
|
|
else
|
|
TITLE="$HOST Boot health check FAIL"
|
|
APP_TOKEN="apipushoverapptoken"
|
|
USER_TOKEN="apipushoverusertoken"
|
|
MESSAGE="$HOST has failed a healthcheck after bootup - Services will not be initiated. Manual Intervention Required."
|
|
curl -s -F "token=$APP_TOKEN" -F "user=$USER_TOKEN" -F "title=$TITLE" -F "message=$MESSAGE" https://api.pushover.net/1/messages.json
|
|
systemctl stop syncthing@root
|
|
systemctl stop cronicle
|
|
systemctl stop docker.socket
|
|
systemctl stop ampinstmgr
|
|
if [ "$HOST" = "Delta" ]
|
|
then
|
|
systemctl stop jellyfin #delta only
|
|
fi
|
|
systemctl stop rsyncd
|
|
fi
|
|
}
|
|
sleep 60
|
|
verifyZFS
|
|
guardband
|
|
PushoverReturnBootOK |