1
0
mirror of https://github.com/algora-io/tv.git synced 2024-11-16 00:58:59 +02:00

add observer script

This commit is contained in:
zafer 2024-06-24 21:30:11 +03:00
parent f98bf3302d
commit 8bd6156df8

59
observer Executable file
View File

@ -0,0 +1,59 @@
#!/bin/bash
# After opening a Wireguard connection to your Fly network, run this script to
# open a BEAM Observer from your local machine to the remote server. This creates
# a local node that is clustered to a machine running on Fly.
# In order for it to work:
# - Your wireguard connection must be up.
# - The RELEASE_COOKIE value must be the same as the cookie value used for your project.
# - Observer needs to be working in your local environment. That requires WxWidget support in your Erlang install.
# When done, close Observer. It leaves you with an open IEx shell that is connected to the remote server. You can safely CTRL+C, CTRL+C to exit it.
set -e
if [ -z "$RELEASE_COOKIE" ]; then
echo "Set the RELEASE_COOKIE your project uses in the RELEASE_COOKIE ENV value before running this script."
exit 1
fi
if ! command -v jq &> /dev/null; then
echo "jq is not installed. Please install it before running this script. It is a command-line JSON processor."
exit 1
fi
# Get the data we need in JSON format
json_data=$(fly status --json)
# Extract app name
app_name=$(echo "$json_data" | jq -r '.Name')
# Extract private_ip for the first started machine
private_ip=$(echo "$json_data" | jq -r '.Machines[] | select(.state == "started") | .private_ip' | head -n 1)
if [ -z "$private_ip" ]; then
echo "No instances appear to be running at this time."
exit 1
fi
# Assemble the full node name
FULL_NODE_NAME="${app_name}@${private_ip}"
echo Attempting to connect to $FULL_NODE_NAME
# IMPORTANT:
# ==========
# Fly.io uses an IPv6 network internally for private IPs. The BEAM needs IPv6
# support to be enabled explicitly.
#
# The issue is, if it's enabled globally like in a `.bashrc` file, then setting
# it here essentially flips it OFF. If not set globally, then it should be set
# here. Choose the version that fits your situation.
#
# It's the `--erl "-proto_dist inet6_tcp"` portion.
# Toggles on IPv6 support for the local node being started.
iex --erl "-proto_dist inet6_tcp" --sname my_remote --cookie ${RELEASE_COOKIE} -e "IO.inspect(Node.connect(:'${FULL_NODE_NAME}'), label: \"Node Connected?\"); IO.inspect(Node.list(), label: \"Connected Nodes\"); :observer.start"
# Does NOT toggle on IPv6 support, assuming it is enabled some other way.
# iex --sname my_remote --cookie ${RELEASE_COOKIE} -e "IO.inspect(Node.connect(:'${FULL_NODE_NAME}'), label: \"Node Connected?\"); IO.inspect(Node.list(), label: \"Connected Nodes\"); :observer.start"