Skip to content

Commit

Permalink
refactor: 💡 move the user request to clear logs earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
heldrida committed Oct 18, 2023
1 parent 2cd70e3 commit e870263
Showing 1 changed file with 65 additions and 68 deletions.
133 changes: 65 additions & 68 deletions scripts/healthcheck
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ warningCount=0

echo

while read -rp "🤖 This process might require to clear the logs and restart the service. Is it ok to clear the logs and restart the service? (yes/no) " answer; do
if [[ "$answer" == [nN] || "$answer" == [nN][oO] ]]; then
echo "👹 Oops! The healthcheck verification was exited."

exit 1
elif [[ "$answer" == [yY] || "$answer" == [yY][eE][sS] ]]; then
break;
fi

printf "💩 Uh-oh! We expect a yes or no answer. Try again...\n"
done

echo

if [[ ! -d "$basePath/fleek-network/$defaultName" ]]; then
echo "⚠️ WARNING: The Fleek Network Lightning CLI source code wasn't found in $basePath/fleek-network/$defaultName. If you have installed the service with the username $(whoami) and haven't customised the path, the source code is not in the expected location"

Expand Down Expand Up @@ -123,77 +137,60 @@ warningCount=0
fi

if [[ -f "$defaultLightningSystemdServicePath" ]]; then
while read -rp "🤖 This process requires to clear the logs and restart the service. Should it clear the logs and restart the service? (yes/no) " answer; do
if [[ "$answer" == [nN] || "$answer" == [nN][oO] ]]; then
echo "👹 Oops! The healthcheck verification was exited."

exit 1
elif [[ "$answer" == [yY] || "$answer" == [yY][eE][sS] ]]; then
sudo rm "$defaultLightningOutputLogAbsPath"
sudo rm "$defaultLightningDiagnosticLogAbsPath"

if [[ -f "$defaultLightningSystemdServicePathForDocker" ]]; then
sudo systemctl restart "$defaultLightningSystemdServiceNameForDocker"
else
sudo systemctl restart "$defaultName"
fi

serverOutputWaitAttempts=0
while [[ -f "$defaultLightningOutputLogAbsPath" && ! -s "$defaultLightningOutputLogAbsPath" ]]; do
echo "🤖 Please wait for the service output logs..."
sleep 5

if [[ "$serverOutputWaitAttempts" -gt 10 ]]; then
break
fi

((serverOutputWaitAttempts++))
done

if tail -n 500 "$defaultLightningOutputLogAbsPath" | grep -iq "Node is not staked"; then
echo "⚠️ WARNING: The node is not staked. Have you read the instructions to get onboarded? Find it here https://docs.fleek.network/docs/node/testnet-onboarding"
echo

((warningCount++))
((healthIssueCount++))

break;
fi

if tail -n 500 "$defaultLightningOutputLogAbsPath" | grep -iq "Please update your node"; then
echo "⚠️ WARNING: Binary process version mismatch, you have to update your node. A quick reference is available in https://docs.fleek.network/references/Lightning%20CLI/update-cli-from-source-code/"
echo

((warningCount++))
((healthIssueCount++))

break;
fi

if tail -n 500 "$defaultLightningDiagnosticLogAbsPath" | grep -iq "Node secret key does not exist"; then
echo "⚠️ WARNING: The Node Key wasn't found, this might be due to missing keystore or user delegation permissions (sudo). A quick reference to help troubleshoout is available in https://docs.fleek.network/references/Lightning%20CLI/keys-not-found/"
echo

((warningCount++))
((healthIssueCount++))

break;
fi

if ! curl -s -w "\p" localhost:4230/health | grep -iq 'OK'; then
echo "⚠️ WARNING: Failed to get a response from localhost:4230/health. The node is not running, if you are participating in testnet, then read the instructions in https://docs.fleek.network/docs/node/testnet-onboarding, to run successfully!"

((warningCount++))
((healthIssueCount++))
else
echo "✅ The localhost:4230/health is okay"

break;
fi
sudo rm "$defaultLightningOutputLogAbsPath"
sudo rm "$defaultLightningDiagnosticLogAbsPath"

if [[ -f "$defaultLightningSystemdServicePathForDocker" ]]; then
sudo systemctl restart "$defaultLightningSystemdServiceNameForDocker"
else
sudo systemctl restart "$defaultName"
fi

serverOutputWaitAttempts=0
while [[ -f "$defaultLightningOutputLogAbsPath" && ! -s "$defaultLightningOutputLogAbsPath" ]]; do
sleep 1

if [[ "$serverOutputWaitAttempts" -gt 10 ]]; then
echo "⚠️ WARNING: The Node failed to provide log information, the script will not be able to analyze the log for you. If you'd like to learn how to analyze the logs manually check https://docs.fleek.network/docs/node/analyzing-logs"

break
fi

printf "💩 Uh-oh! We expect a yes or no answer. Try again...\n"
((serverOutputWaitAttempts++))
done

if tail -n 500 "$defaultLightningOutputLogAbsPath" | grep -iq "Node is not staked"; then
echo "⚠️ WARNING: The node is not staked. Have you read the instructions to get onboarded? Find it here https://docs.fleek.network/docs/node/testnet-onboarding"
echo

((warningCount++))
((healthIssueCount++))
fi

if tail -n 500 "$defaultLightningOutputLogAbsPath" | grep -iq "Please update your node"; then
echo "⚠️ WARNING: Binary process version mismatch, you have to update your node. A quick reference is available in https://docs.fleek.network/references/Lightning%20CLI/update-cli-from-source-code/"
echo

((warningCount++))
((healthIssueCount++))
fi

if tail -n 500 "$defaultLightningDiagnosticLogAbsPath" | grep -iq "Node secret key does not exist"; then
echo "⚠️ WARNING: The Node Key wasn't found, this might be due to missing keystore or user delegation permissions (sudo). A quick reference to help troubleshoout is available in https://docs.fleek.network/references/Lightning%20CLI/keys-not-found/"
echo

((warningCount++))
((healthIssueCount++))
fi

if ! curl -s -w "\p" localhost:4230/health | grep -iq 'OK'; then
echo "⚠️ WARNING: Failed to get a response from localhost:4230/health. The node is not running, if you are participating in testnet, then read the instructions in https://docs.fleek.network/docs/node/testnet-onboarding, to run successfully!"

((warningCount++))
((healthIssueCount++))
else
echo "✅ The localhost:4230/health is okay"
fi
fi

echo
Expand Down

0 comments on commit e870263

Please sign in to comment.