-
Notifications
You must be signed in to change notification settings - Fork 50
/
update.sh
executable file
·70 lines (56 loc) · 2.83 KB
/
update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
set -ex
: "${SATURN_NETWORK:=test}"
: "${SATURN_HOME:=$HOME}"
if pidof -o %PPID -x "update.sh" > /dev/null; then
exit
fi
compose_file=$SATURN_HOME/docker-compose.yml
env_file=$SATURN_HOME/.env
echo "$(date -u) Starting migration to docker compose setup."
echo "The auto-update script was deprecated to migrate to a docker compose setup. Updates are handled by a Watchtower container now."
echo "The run script was deprecated too. To start or stop your node use 'docker compose -f ${compose_file} up -d' or 'docker compose -f $compose_file down' respectively."
if [ -f "$compose_file" ]; then
echo "We have migrated to a docker compose setup to reduce risks caused by these update and run scripts. You can delete these scripts and use the Docker Compose workflow now."
else
wget -O "$compose_file" -T 10 -t 3 "https://raw.githubusercontent.com/filecoin-saturn/L1-node/main/docker-compose.yml"
if [[ -s "$compose_file" ]];
then
echo "Downloaded the docker compose file successfully!"
else
echo "Failed to download the docker compose file automagically. Please open a Github issue or migrate manually to the docker compose setup"
exit 1
fi
wget -O "$env_file" -T 10 -t 3 "https://raw.githubusercontent.com/filecoin-saturn/L1-node/main/.env"
if [[ -s "$env_file" ]];
then
echo "Downloaded the .env file successfully!"
else
echo "Failed to download the .env file automagically. Please open a Github issue or migrate manually to the docker compose setup"
exit 1
fi
echo "Testing compatibility with our Docker Compose workflow"
if ! sudo docker compose version;
then
echo "docker compose might not be supported by your setup, or you are still using an old docker-compose version";
exit 1
fi
echo "You have docker compose, proceeding."
printf "If any of the following steps fail, please edit the .env file to include the expected values and try running the commands:\n\t'sudo docker stop --time 900 saturn-node && sudo docker compose -f %s up -d'." "$compose_file"
random_sleep="$(( RANDOM % 2000 ))"
echo "Waiting for $random_sleep seconds to avoid stopping all nodes in the network at once..."
sleep "$random_sleep"
echo "Pulling Saturn $SATURN_NETWORK network L1 node updates."
sudo -E docker compose -f "$compose_file" pull
echo "Draining $SATURN_NETWORK network L1 node... "
sudo docker stop --time 900 saturn-node || true
echo "Restarting with docker compose now..."
sudo docker rm -f saturn-node || true
sudo -E docker compose -f "$compose_file" pull
if ! sudo -E docker compose -f "$compose_file" up -d;
then
echo "Error while launching the docker compose setup. Please try running 'docker compose up -d' yourself or open an issue on Github."
exit 1
fi
echo "Updated to the latest version successfully! You can now delete the run.sh and update.sh scripts."
fi