Skip to content

Commit

Permalink
Add script for migrating from local host D13 + allow name and guid ov…
Browse files Browse the repository at this point in the history
…errides for set-telemetry-name (#27)
  • Loading branch information
hsoerensen committed Feb 3, 2024
1 parent f872439 commit c0fc3a5
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 8 deletions.
41 changes: 41 additions & 0 deletions bin/migrate-from-d13-setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
is_root=0

execute_sudo() {
if [[ ${is_root} -eq 1 ]]; then
bash -c "$1"
else
sudo bash -c "$1"
fi
}

container_id=$(docker ps -q -f name=voinetwork_algod)
if [ -z "${container_id}" ]; then
echo "AVM container is not running. Please start it first."
exit 1
fi

if [[ $(id -u) -eq 0 ]]; then
is_root=1
fi

echo "This script will assist migrating your node from D13 based setups to Voi Swarm, if your node is already running D13 based setup."
echo "If you are running a D13 based setup on another service follow guidance in the documentation to migrate to Voi Swarm: https://voinetwork.github.io/voi-swarm/"
echo ""
if [[ -f /var/lib/algorand/logging.config ]]; then
echo "Migrating telemetry configuration"
execute_sudo "cp /var/lib/algorand/logging.config /var/lib/voi/algod/data/logging.config"
if [[ ${is_root} -eq 0 ]]; then
execute_sudo "chgrp docker /var/lib/voi/algod/data/logging.config"
fi
fi

echo "Stopping Voi.service if available"
execute_sudo "systemctl stop voi"
execute_sudo "systemctl disable voi"
echo "If you want to revert to D13 based setup on this host, you can start the service again by running 'systemctl start voi && systemctl enable voi'"

echo "Start Voi Swarm"
bash -c "env VOINETWORK_TELEMETRY_NAME=$VOINETWORK_TELEMETRY_NAME docker stack deploy -c ${HOME}/voi/docker/compose.yml voinetwork"

echo "Changes has been applied to the network. Please wait a minute for the changes to take effect."
67 changes: 59 additions & 8 deletions bin/set-telemetry-name
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash
is_root=0

container_id=$(docker ps -q -f name=voinetwork_algod)
if [ -z "${container_id}" ]; then
echo "AVM container is not running. Please start it first."
exit 1
fi
execute_sudo() {
if [[ ${is_root} -eq 1 ]]; then
bash -c "$1"
else
sudo bash -c "$1"
fi
}

set_telemetry_name() {
if [[ -z ${VOINETWORK_TELEMETRY_NAME} ]]; then
Expand All @@ -27,8 +30,56 @@ set_telemetry_name() {
fi
}

set_telemetry_name
get_logging_config() {
execute_sudo "cat /var/lib/voi/algod/data/logging.config"
}

write_logging_config() {
local config_content="$1"
local temp_file
temp_file=$(mktemp)

echo "${config_content}" > "$temp_file"
execute_sudo "mv $temp_file /var/lib/voi/algod/data/logging.config"

if [[ ${is_root} -eq 0 ]]; then
execute_sudo "chgrp docker /var/lib/voi/algod/data/logging.config"
fi
}

update_guid_in_config() {
local guid="$1"
local logging_config
logging_config=$(get_logging_config)

echo "${logging_config}" | jq --arg guid "${guid}" '.GUID = $guid'
}

container_id=$(docker ps -q -f name=voinetwork_algod)
if [ -z "${container_id}" ]; then
echo "AVM container is not running. Please start it first."
exit 1
fi

if [[ $(id -u) -eq 0 ]]; then
is_root=1
fi

if [[ $1 && $2 ]]; then
telemetry_name="${1//\"}"
guid="${2//\"}"

new_config=$(update_guid_in_config "${guid}")
write_logging_config "${new_config}"

VOINETWORK_TELEMETRY_NAME="${telemetry_name}"

echo "Telemetry name set to: $telemetry_name, GUID set to: $guid"
else
set_telemetry_name
fi

bash -c "env VOINETWORK_TELEMETRY_NAME=$VOINETWORK_TELEMETRY_NAME docker stack deploy -c ${HOME}/voi/docker/compose.yml voinetwork"
echo "${VOINETWORK_TELEMETRY_NAME}"
bash -c "env VOINETWORK_TELEMETRY_NAME=\"${VOINETWORK_TELEMETRY_NAME}\" docker stack deploy -c ${HOME}/voi/docker/compose.yml voinetwork"

echo "Changes has been applied to the network. Please wait a minute for the changes to take effect."
echo "Changes has been applied to the network. Please wait a minute for the changes to take effect. Confirm changes by running 'bin/get-telemetry-status' after a minute."
33 changes: 33 additions & 0 deletions docs/migrating.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Migrating to Voi Swarm

## From D13 based setups

=== "Installing on same server"

To help migrate from D13 based setups, there's a migration command available. This command will

1. Duplicate telemetry settings, including existing telemetry name and GUID, without affecting rewards.
2. Stop the host-based Voi service
3. Restart Voi Swarm

To run this command, you must install Voi Swarm first. Then run the following command:

```bash
~/voi/bin/migrate-from-d13-setup
```

=== "Installing on a new server"

To migrate to a new server, you must first install Voi Swarm on the new server.

1. Run the following command on the old server to get the telemetry name and GUID:

```bash
sudo ALGORAND_DATA=/var/lib/algorand diagcfg telemetry status
```
2. Copy the telemetry name and GUID to the new server.
3. Run the following command on the new server to set the telemetry name and GUID:

```bash
~/voi/bin/set-telemetry-name <telemetry-name> <telemetry-guid>
```
7 changes: 7 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ theme:
- navigation.instant.progress
- content.action.edit
- content.code.copy
- content.tabs.link
- search.suggest
- search.highlight

Expand Down Expand Up @@ -69,6 +70,11 @@ markdown_extensions:
- pymdownx.details
- pymdownx.superfences
- footnotes
- pymdownx.tabbed:
alternate_style: true
slugify: !!python/object/apply:pymdownx.slugs.slugify
kwds:
case: lower

plugins:
- search
Expand Down Expand Up @@ -100,5 +106,6 @@ nav:
- Notification Guides:
- Pushbullet: notification-guides/pushbullet.md
- Provider Guidance: provider-guidance.md
- Migrating: migrating.md
- CLI Tools: cli-tools.md
- Troubleshooting: troubleshooting.md

0 comments on commit c0fc3a5

Please sign in to comment.