#!/usr/bin/env bash
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"

if [[ -f .env ]]; then
  set -a
  # shellcheck source=/dev/null
  source .env
  set +a
fi

VEX_NODE_SCREEN="${VEX_NODE_SCREEN:-Vexon_Node}"
VEX_WALLET_SCREEN="${VEX_WALLET_SCREEN:-Vexon_Wallet}"
VEX_STRATUM_SCREEN="${VEX_STRATUM_SCREEN:-Vexon_Stratum}"
VEX_PEER_SCREEN="${VEX_PEER_SCREEN:-Vexon_Node_Peer}"

for name in "$VEX_STRATUM_SCREEN" "$VEX_WALLET_SCREEN" "$VEX_PEER_SCREEN" "$VEX_NODE_SCREEN" vexon-pool-main vexon-pool-loop2 vexon-pool-blocks; do
  screen -S "$name" -X quit >/dev/null 2>&1 || true
done

sleep 2
screen -ls || true
