33set -e
44
55# Variables
6- export MASTER_SEED=" "
76USER=" ubuntu"
87PASSWORD_FILE=" /home/$USER /password.txt"
98SECRET_DIR=" /home/$USER /.secrets"
@@ -235,25 +234,29 @@ EOF
235234
236235# Function to set up and start go-fula service
237236setup_gofula_service () {
238- gofula_service_file_path=" /etc/systemd/system/go-fula.service"
239- echo " setup go-fula service at $gofula_service_file_path "
240- # Check if the file exists and then remove it
241- if [ -f " $gofula_service_file_path " ]; then
242- sudo systemctl stop go-fula.service
243- sudo systemctl disable go-fula.service
244- sudo rm " $gofula_service_file_path "
245- sudo systemctl daemon-reload
246- echo " Removed $gofula_service_file_path ."
247- else
248- echo " $gofula_service_file_path does not exist."
249- fi
237+ gofula_service_file_path=" /etc/systemd/system/go-fula.service"
238+ echo " Setting up go-fula service at $gofula_service_file_path "
239+
240+ # Check if the file exists and then remove it
241+ if [ -f " $gofula_service_file_path " ]; then
242+ sudo systemctl stop go-fula.service
243+ sudo systemctl disable go-fula.service
244+ sudo rm " $gofula_service_file_path "
245+ sudo systemctl daemon-reload
246+ echo " Removed $gofula_service_file_path ."
247+ else
248+ echo " $gofula_service_file_path does not exist."
249+ fi
250+
251+ # Create the service file using the provided path
250252 sudo bash -c " cat > '$gofula_service_file_path '" << EOF
251253[Unit]
252254Description=Go Fula Service
253255After=network.target
254256
255257[Service]
256258Type=simple
259+ Environment=HOME=/home/$USER
257260ExecStart=/home/$USER /go-fula/go-fula --config /home/$USER /.fula/config.yaml
258261Restart=always
259262RestartSec=10s
@@ -264,11 +267,14 @@ StartLimitBurst=4
264267WantedBy=multi-user.target
265268EOF
266269
270+ # Reload systemd and enable the service
267271 sudo systemctl daemon-reload
268272 sudo systemctl enable go-fula.service
269273 sudo systemctl start go-fula.service
274+ echo " Go-fula service has been set up and started."
270275}
271276
277+
272278# Function to fund an account
273279fund_account () {
274280 echo " Checking account balance before funding..."
@@ -315,16 +321,23 @@ create_pool() {
315321 seed=$( cat " $SECRET_DIR /secret_seed.txt" )
316322 node_peerid=$( cat " $SECRET_DIR /node_peerid.txt" )
317323
318- # Create the pool
319- create_response=$( curl -s -X POST https://api.node3.functionyard.fula.network/fula/pool/create \
324+ # Capture the HTTP status code while creating the pool
325+ create_response=$( curl -s -o response.json -w " %{http_code} " - X POST https://api.node3.functionyard.fula.network/fula/pool/create \
320326 -H " Content-Type: application/json" \
321327 -d " {\" seed\" : \" $seed \" , \" pool_name\" : \" $pool_name \" , \" peer_id\" : \" $node_peerid \" , \" region\" : \" $region \" }" )
322-
323- pool_id=$( echo $create_response | jq ' .pool_id' )
324- echo " Created Pool ID: $pool_id "
325-
326- # Update the Fula config file with the pool ID
327- setup_fula_config " $pool_id "
328+
329+ # Extract the pool_id from the response
330+ pool_id=$( cat response.json | jq ' .pool_id' )
331+ rm response.json # Clean up the temporary file
332+
333+ # Check if the pool was created successfully (HTTP status 200) and pool_id is not null
334+ if [[ $create_response == 200 ]] && [[ $pool_id != null ]]; then
335+ echo " Created Pool ID: $pool_id "
336+ # Update the Fula config file with the pool ID
337+ setup_fula_config " $pool_id "
338+ else
339+ echo " Failed to create the pool for region $region . HTTP Status: $create_response , Pool ID: $pool_id "
340+ fi
328341 fi
329342}
330343
@@ -384,7 +397,7 @@ verify_pool_creation() {
384397
385398 # Check if the specified region exists in the list of pools
386399 if echo " $pools_response " | jq --arg region " $region " ' .pools[] | select(.region == $region)' | grep -q ' pool_id' ; then
387- echo " Verification successful: Pool for region $region exists."
400+ echo " OK Verification successful: Pool for region $region exists."
388401 else
389402 echo " ERROR: Verification failed: No pool found for region $region ."
390403 fi
@@ -413,7 +426,7 @@ check_services_status() {
413426 if [ " $all_services_running " = false ]; then
414427 echo " ERROR: One or more services are not running. Please check the logs for more details."
415428 else
416- echo " All services are running as expected."
429+ echo " OK All services are running as expected."
417430 fi
418431}
419432
@@ -437,12 +450,14 @@ main() {
437450 export DEBIAN_FRONTEND=noninteractive
438451
439452 # Check if a region is provided
440- if [ $# -lt 1 ]; then
441- echo " Please provide a region as an argument ."
453+ if [ $# -lt 2 ]; then
454+ echo " Please provide 1:MASTER seed and 2: region as arguments ."
442455 exit 1
443456 fi
457+
458+ export MASTER_SEED=$1
444459
445- region=$1
460+ region=$2
446461 pool_name=$( echo " $region " | sed -e ' s/\([A-Z]\)/ \1/g' -e ' s/^ //' )
447462
448463 echo " creating region=$region and pool_name=$pool_name "
@@ -500,6 +515,7 @@ main() {
500515 verify_pool_creation " $region "
501516
502517 # Check the status of the services
518+ sleep 5
503519 check_services_status
504520
505521 echo " Setup complete. Please review the logs and verify the services are running correctly."
0 commit comments