github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/deploy/neon-cluster/scripts/compute.sh (about) 1 #!/bin/bash 2 set -ex 3 export PAGESERVER=neon-cluster-neon-pageserver-headless.default.svc.cluster.local 4 export SAFEKEEPERS=neon-cluster-neon-safekeeper-headless.default.svc.cluster.local:5454 5 SPEC_FILE_ORG=/spec_prep_docker.json 6 SPEC_FILE=/spec.json 7 PG_VERSION=14 8 echo "Waiting pageserver become ready." 9 while ! nc -z $PAGESERVER 6400; do 10 sleep 1; 11 done 12 echo "Page server is ready." 13 14 echo "Create a tenant and timeline" 15 if [ -z "$TENANT" ]; then 16 PARAMS=( 17 -sb 18 -X POST 19 -H "Content-Type: application/json" 20 -d "{}" 21 "http://${PAGESERVER}:9898/v1/tenant/" 22 ) 23 tenant_id=$(curl "${PARAMS[@]}" | sed 's/"//g') 24 else 25 tenant_id=$TENANT 26 fi 27 28 if [ -z "$TIMELINE" ]; then 29 PARAMS=( 30 -sb 31 -X POST 32 -H "Content-Type: application/json" 33 -d "{\"tenant_id\":\"${tenant_id}\", \"pg_version\": ${PG_VERSION}}" 34 "http://${PAGESERVER}:9898/v1/tenant/${tenant_id}/timeline/" 35 ) 36 result=$(curl "${PARAMS[@]}") 37 echo $result | jq . 38 39 echo "Overwrite tenant id and timeline id in spec file" 40 tenant_id=$(echo ${result} | jq -r .tenant_id) 41 timeline_id=$(echo ${result} | jq -r .timeline_id) 42 43 else 44 45 #If not empty CREATE_BRANCH 46 #we create branch with given ancestor_timeline_id as TIMELINE 47 48 if [ ! -z "$CREATE_BRANCH" ]; then 49 50 PARAMS=( 51 -sb 52 -X POST 53 -H "Content-Type: application/json" 54 -d "{\"tenant_id\":\"${tenant_id}\", \"pg_version\": ${PG_VERSION}, \"ancestor_timeline_id\":\"${TIMELINE}\"}" 55 "http://${PAGESERVER}:9898/v1/tenant/${tenant_id}/timeline/" 56 ) 57 58 result=$(curl "${PARAMS[@]}") 59 echo $result | jq . 60 61 echo "Overwrite tenant id and timeline id in spec file" 62 tenant_id=$(echo ${result} | jq -r .tenant_id) 63 timeline_id=$(echo ${result} | jq -r .timeline_id) 64 65 else 66 timeline_id=$TIMELINE 67 fi #end if CREATE_BRANCH 68 69 fi 70 71 sed "s/TENANT_ID/${tenant_id}/" ${SPEC_FILE_ORG} > ${SPEC_FILE} 72 sed -i "s/TIMELINE_ID/${timeline_id}/" ${SPEC_FILE} 73 sed -i "s/PAGESERVER_SPEC/${PAGESERVER}/" ${SPEC_FILE} 74 sed -i "s/SAFEKEEPERS_SPEC/${SAFEKEEPERS}/" ${SPEC_FILE} 75 76 cat ${SPEC_FILE} 77 78 echo "Start compute node" 79 whoami 80 echo $PWD 81 if [ ! -d "data" ]; then 82 mkdir data 83 fi 84 ls -lah /data 85 86 if [ ! -d "/data/pgdata" ]; then 87 mkdir -p /data/pgdata 88 fi 89 chown -R postgres:postgres /data 90 nohup su - postgres -c "/usr/local/bin/compute_ctl --pgdata /data/pgdata -C 'postgresql://cloud_admin@localhost:55432/postgres' -b /usr/local/bin/postgres -S ${SPEC_FILE}" &