Skip to content

Commit

Permalink
fix env access
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-shashank committed Jun 6, 2024
1 parent e3df4ea commit 01dff19
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
8 changes: 1 addition & 7 deletions ansible/archival-snapshots/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
cmd: "unzip -o {{ zip_file_name }}"
chdir: "{{ remote_resources_path }}"

- name: Check if Forest is running
ansible.builtin.shell:
cmd: "ps aux | grep forest | grep -v grep"
register: forest_running
ignore_errors: true

- name: Download Forest release package
ansible.builtin.get_url:
url: "{{ forest_release_url }}"
Expand All @@ -65,7 +59,7 @@

- name: Execute the init.sh script
ansible.builtin.shell:
cmd: "nohup ./init.sh > init.log &"
cmd: "sh init.sh"
chdir: "{{ remote_resources_path }}"
environment:
ARCHIVAL_SLACK_TOKEN: "{{ lookup('env', 'ARCHIVAL_SLACK_TOKEN') }}"
Expand Down
6 changes: 3 additions & 3 deletions ansible/archival-snapshots/resources/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ FOREST_NODE_PID=$!
sleep 30
echo "Forest process started with PID: $FOREST_NODE_PID"

ADMIN_TOKEN=$(cat admin_token)
export FULLNODE_API_INFO="$ADMIN_TOKEN:/ip4/127.0.0.1/tcp/3456/http"
echo "USING TOKEN: $FULLNODE_API_INFO"
# Set required env variables
sh set_env.sh

echo "Waiting for forest to sync to latest network head"
$FOREST_CLI sync wait
Expand All @@ -49,6 +48,7 @@ LATEST_EPOCH=$($FOREST_CLI sync status | grep "Height:" | awk '{print $2}')
echo "Latest Height: $LATEST_EPOCH"

while ((LATEST_EPOCH - CURRENT_EPOCH > 30000)); do
echo "USING TOKEN: $FULLNODE_API_INFO"
NEW_EPOCH=$((CURRENT_EPOCH + 30000))
echo "Next Height: $NEW_EPOCH"

Expand Down
21 changes: 21 additions & 0 deletions ansible/archival-snapshots/resources/set_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Read the ADMIN_TOKEN from the file
ADMIN_TOKEN=$(cat admin_token)

# Check if the environment variable is set
if [ -z "$FULLNODE_API_INFO" ]; then
echo "FULLNODE_API_INFO is not set. Setting it now."
export FULLNODE_API_INFO="$ADMIN_TOKEN:/ip4/127.0.0.1/tcp/3456/http"
else
echo "FULLNODE_API_INFO is already set to: $FULLNODE_API_INFO"
fi

# Save the environment variable to a file
echo "export FULLNODE_API_INFO=\"$FULLNODE_API_INFO\"" > forest-archival.env

# Source the file to load the environment variable
. forest-archival.env

# Use the environment variable
echo "Using FULLNODE_API_INFO: $FULLNODE_API_INFO"

0 comments on commit 01dff19

Please sign in to comment.