github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/ops/terraform/remote_files/scripts/start-bacalhau.sh (about)

     1  #!/bin/bash
     2  # shellcheck disable=SC1091,SC2312
     3  set -euo pipefail
     4  IFS=$'\n\t'
     5  
     6  # import the terraform vars
     7  source /terraform_node/variables
     8  
     9  # mount the disk - wait for /dev/sdb to exist
    10  # NB: do not reformat the disk if we can't mount it, unlike the initial
    11  # install/upgrade script!
    12  while [[ ! -e /dev/sdb ]]; do
    13    sleep 1
    14    echo "waiting for /dev/sdb to exist"
    15  done
    16  # mount /dev/sdb at /data
    17  mkdir -p /data
    18  mount /dev/sdb /data || true
    19  
    20  # import the secrets
    21  source /data/secrets.sh
    22  
    23  function getMultiaddress() {
    24    echo -n "/ip4/${1}/tcp/${BACALHAU_PORT}/p2p/${2}"
    25  }
    26  
    27  # we start with none as the default ("none" prevents the node connecting to our default bootstrap list)
    28  export CONNECT_PEER="none"
    29  
    30  # if we are node0 then we do not connect to anything
    31  if [[ "${TERRAFORM_NODE_INDEX}" != "0" ]]; then
    32    # if we are in unsafe mode - then we connect to a single node and it's ID
    33    # is pre-determined by the $BACALHAU_NODE0_UNSAFE_ID variable
    34    if [[ -n "${BACALHAU_UNSAFE_CLUSTER}" ]]; then
    35      export UNSAFE_NODE0_ID="$BACALHAU_NODE_ID_0"
    36      if [[ -z "$UNSAFE_NODE0_ID" ]]; then
    37        export UNSAFE_NODE0_ID="$BACALHAU_NODE0_UNSAFE_ID"
    38      fi
    39      export CONNECT_PEER=$(getMultiaddress "$TERRAFORM_NODE0_IP" "$UNSAFE_NODE0_ID")
    40    # otherwise we will construct our connect string based on
    41    # what node index we are
    42    else
    43      # we are > node0 so we can connect to node0
    44      export CONNECT_PEER=$(getMultiaddress "$TERRAFORM_NODE0_IP" "$BACALHAU_NODE_ID_0")
    45      # we are > node1 so we can also connect to node1
    46      if [[ "${TERRAFORM_NODE_INDEX}" -ge "2" ]]; then
    47        export CONNECT_PEER="$CONNECT_PEER,$(getMultiaddress "$TERRAFORM_NODE1_IP" "$BACALHAU_NODE_ID_1")"
    48      fi
    49      # we are > node2 so we can also connect to node2
    50      if [[ "${TERRAFORM_NODE_INDEX}" -ge "3" ]]; then
    51        export CONNECT_PEER="$CONNECT_PEER,$(getMultiaddress "$TERRAFORM_NODE2_IP" "$BACALHAU_NODE_ID_2")"
    52      fi
    53    fi
    54  fi
    55  
    56  BACALHAU_PROBE_EXEC='/terraform_node/apply-http-allowlist.sh'
    57  
    58  bacalhau serve \
    59    --node-type requester,compute \
    60    --job-selection-data-locality anywhere \
    61    --job-selection-accept-networked \
    62    --job-selection-probe-exec "${BACALHAU_PROBE_EXEC}" \
    63    --ipfs-connect /ip4/127.0.0.1/tcp/5001 \
    64    --swarm-port "${BACALHAU_PORT}" \
    65    --api-port 1234 \
    66    --peer "${CONNECT_PEER}" \
    67    --labels owner=bacalhau