-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestart.sh
137 lines (115 loc) · 3.77 KB
/
restart.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
export FULA_CONTRACT_API_HOST="https://contract-api.functionyard.fula.network"
export FULA_SUGARFUNGE_API_HOST="http://127.0.0.1:4000"
# Variables from the original script
USER="ubuntu" # Adjust as necessary
# Define the directories and services from the original script
DATA_DIR="/home/$USER/.sugarfunge-node/data"
SERVICES=("sugarfunge-node01.service" "sugarfunge-node02.service" "sugarfunge-node03.service" "sugarfunge-api03.service") # Add other related services if necessary
SEED_MASTER=$1
SEED_NODE=$2
# Function to stop services in reverse order
stop_services() {
echo "Stopping services in reverse order..."
for (( idx=${#SERVICES[@]}-1 ; idx>=0 ; idx-- )); do
service=${SERVICES[idx]}
sudo systemctl stop "$service"
echo "Stopped $service."
done
}
# Function to clear data directories
clear_data_folders() {
echo "Clearing data folders..."
if [ -d "$DATA_DIR" ]; then
sudo rm -rf "$DATA_DIR"/*
echo "Cleared data in $DATA_DIR."
else
echo "Data directory $DATA_DIR does not exist."
fi
}
# Function to start services
start_services() {
echo "Starting services..."
for service in "${SERVICES[@]}"; do
sudo systemctl start "$service"
echo "Started $service."
sleep 10
done
}
# Function to fund an account
fund_account() {
echo "Funding account..."
curl -X POST -H "Content-Type: application/json" \
--data "{
\"seed\": \"$1\",
\"amount\": 1000000000000000000,
\"to\": \"5Dc6dTQo6ZhDsHVFTDYwYz2oWDQ88kuEWrg39XWzrFagPdjS\"
}" http://127.0.0.1:4000/account/fund
}
# Function to create a pool
create_pool() {
echo "Creating pool..."
curl -X POST -H "Content-Type: application/json" \
--data "{
\"seed\": \"$1\",
\"pool_name\":\"Canada Central\",
\"peer_id\": \"12D3KooWRTzN7HfmjoUBHokyRZuKdyohVVSGqKBMF24ZC3tGK78Q\",
\"region\": \"CanadaCentral\"
}" http://127.0.0.1:4000/fula/pool/create
}
# Function to upload a manifest
upload_manifest() {
echo "Uploading manifest..."
curl -X POST -H "Content-Type: application/json" \
--data "{
\"seed\": \"$1\",
\"replication_factor\": 1,
\"pool_id\": 1,
\"cid\": \"QmcwQBzZcFVa7gyEQazd9WryzXKVMK2TvwBweruBZhy3pf\",
\"manifest_metadata\": {
\"job\": {
\"work\": \"Storage\",
\"engine\": \"IPFS\",
\"uri\": \"QmcwQBzZcFVa7gyEQazd9WryzXKVMK2TvwBweruBZhy3pf\"
}
}
}" $FULA_SUGARFUNGE_API_HOST/fula/manifest/upload
}
# Function to store a manifest
store_manifest() {
echo "Storing manifest..."
curl -X POST -H "Content-Type: application/json" \
--data "{
\"seed\": \"$1\",
\"uploader\": \"5CcHZucP2u1FXQW9wuyC11vAVxB3c48pUhc5cc9b3oxbKPL2\",
\"cid\": \"QmcwQBzZcFVa7gyEQazd9WryzXKVMK2TvwBweruBZhy3pf\",
\"pool_id\": 1
}" $FULA_SUGARFUNGE_API_HOST/fula/manifest/storage
}
# Main function to orchestrate stopping, clearing, and restarting
main() {
# Stop all the services
stop_services
echo "All services stopped"
# Clear only the data folders
clear_data_folders
echo "Chain data cleared"
# Restart the stopped services
start_services
echo "All services started"
# Wait a little for services to be fully up
sleep 5
# Fund account
fund_account "$SEED_MASTER"
echo "Account $SEED_NODE funded from $SEED_MASTER"
# Create pool
create_pool "$SEED_NODE"
echo "Pool created by $SEED_NODE"
upload_manifest "$SEED_MASTER"
echo "Manifest uploaded by $SEED_MASTER"
store_manifest "$SEED_NODE"
echo "Manifest stored by $SEED_NODE"
echo "All services have been restarted and data folders cleared."
}
# Run the main function
main "$@"