|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 3 | +# To use staker scripts |
| 4 | +# shellcheck disable=SC1091 |
| 5 | +. /etc/profile |
| 6 | + |
| 7 | +SUPPORTED_NETWORKS="gnosis" |
| 8 | + |
| 9 | +# Set environment variables before running the health checks. |
| 10 | +echo "[INFO | keyper] Setting environment variables for beacon API and execution API..." |
| 11 | +export SHUTTER_BEACONAPIURL=$(get_beacon_api_url_from_global_env "$NETWORK" "$SUPPORTED_NETWORKS") |
| 12 | +export SHUTTER_GNOSIS_NODE_CONTRACTSURL=http://execution.gnosis.dncore.dappnode:8545 |
| 13 | + |
3 | 14 | perform_chain_healthcheck() { |
4 | | - echo "[INFO | keyper] Waiting for chain to be healthy..." |
| 15 | + echo "[INFO | keyper] Starting health check for chain, beacon API, and execution API..." |
5 | 16 |
|
6 | 17 | while true; do |
7 | | - # Perform the health check |
8 | | - if curl -sf http://localhost:26657/status >/dev/null; then |
9 | | - echo "[INFO | keyper] Service is healthy. Exiting health check loop." |
10 | | - break # Exit the loop if the service is healthy |
| 18 | + echo "[INFO | keyper] Checking chain health at: http://localhost:26657/status" |
| 19 | + if ! curl -sf http://localhost:26657/status >/dev/null; then |
| 20 | + echo "[WARN | keyper] Chain service is not healthy yet. Retrying in 30 seconds..." |
| 21 | + sleep 30 |
| 22 | + continue |
| 23 | + else |
| 24 | + echo "[INFO | keyper] Chain service is healthy." |
| 25 | + fi |
| 26 | + |
| 27 | + # Check the syncing status using JSON-RPC |
| 28 | + echo "[INFO | keyper] Checking execution API syncing status at: $SHUTTER_GNOSIS_NODE_CONTRACTSURL/eth/v1/node/syncing" |
| 29 | + sync_status=$(curl -s -X POST "$SHUTTER_GNOSIS_NODE_CONTRACTSURL" \ |
| 30 | + -H "Content-Type: application/json" \ |
| 31 | + -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' | jq -r '.result') |
| 32 | + |
| 33 | + if [ "$sync_status" != "false" ]; then |
| 34 | + echo "[WARN | keyper] Execution API is syncing. Sync status: $sync_status. Retrying in 30 seconds..." |
| 35 | + sleep 30 |
| 36 | + continue |
| 37 | + else |
| 38 | + echo "[INFO | keyper] Execution API is not syncing." |
| 39 | + fi |
| 40 | + |
| 41 | + # Check the syncing status using JSON-RPC |
| 42 | + echo "[INFO | keyper] Checking execution API syncing status at: $SHUTTER_GNOSIS_NODE_CONTRACTSURL/eth/v1/node/syncing" |
| 43 | + |
| 44 | + # Perform the request and capture the response |
| 45 | + response=$(curl -s -w "%{http_code}" -o /tmp/sync_response.json -X POST "$SHUTTER_GNOSIS_NODE_CONTRACTSURL" \ |
| 46 | + -H "Content-Type: application/json" \ |
| 47 | + -d '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}') |
| 48 | + |
| 49 | + # Extract HTTP status code and response body |
| 50 | + http_code="${response: -3}" |
| 51 | + response_body=$(cat /tmp/sync_response.json) |
| 52 | + |
| 53 | + # Check if the response body is empty or the HTTP status code is not 200 |
| 54 | + if [ -z "$response_body" ] || [ "$http_code" -ne 200 ]; then |
| 55 | + echo "[ERROR | keyper] No response or error from execution API. Not healthy" |
| 56 | + sleep 30 |
| 57 | + continue |
| 58 | + fi |
| 59 | + |
| 60 | + # Parse the JSON response to check the syncing status |
| 61 | + syncing_status=$(echo "$response_body" | jq -r '.result.is_syncing') |
| 62 | + |
| 63 | + # If syncing is true or an error occurs, treat it as not synced |
| 64 | + if [ "$syncing_status" = "true" ]; then |
| 65 | + echo "[WARN | keyper] Execution API is syncing. Sync status: $syncing_status. Retrying in 30 seconds..." |
| 66 | + sleep 30 |
| 67 | + continue |
11 | 68 | else |
12 | | - echo "[INFO | keyper] Service is not healthy yet. Retrying in 30 seconds..." |
| 69 | + echo "[INFO | keyper] Execution API is healthy." |
13 | 70 | fi |
14 | 71 |
|
15 | | - # Wait for the next interval (30 seconds) |
16 | | - sleep 30 |
| 72 | + # If we reach this point, all checks have passed. |
| 73 | + echo "[INFO | keyper] All services are healthy. Exiting health check loop." |
| 74 | + break |
17 | 75 | done |
18 | 76 | } |
19 | 77 |
|
20 | 78 | run_keyper() { |
| 79 | + echo "[INFO | keyper] Starting gnosiskeyper..." |
| 80 | + echo "[DEBUG | keyper] Command: $SHUTTER_BIN gnosiskeyper --config \"$KEYPER_CONFIG_FILE\"" |
21 | 81 | $SHUTTER_BIN gnosiskeyper --config "$KEYPER_CONFIG_FILE" |
22 | 82 | } |
23 | 83 |
|
| 84 | +# Run health checks first |
24 | 85 | perform_chain_healthcheck |
25 | 86 |
|
| 87 | +# If everything is healthy, run keyper |
26 | 88 | run_keyper |
0 commit comments