-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenCompose
More file actions
executable file
·814 lines (595 loc) · 22 KB
/
genCompose
File metadata and controls
executable file
·814 lines (595 loc) · 22 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
#!/bin/bash
# --------------------------------------------------------------------------------------------
# Name: genCompose
# Language: bash
# Author: Jorge Torralba
# Version: 1
# Date: May 9, 2024
# Location: https://github.com/jtorral/DockerPgHa
#
# This script will generate a docker-compose file based on the arguments passed to it.
# Since this is yaml based file creation, do not adjust the spacing you may see in the script.
# Very sensitive to spacing.
# It's a pain, but it works for now.
# --------------------------------------------------------------------------------------------
# -- show help info
function usage() {
echo -e
echo -e "Usage:"
echo -e "\t$0 [OPTION]"
echo -e
echo -e "\t-d Number of data centers to simulate. (default = 1)"
echo -e "\t-c number of Postgres nodes per data center. (default = 2)"
echo -e "\t-e number of ETCD nodes per data center. (default = 1)"
echo -e "\t-m Minimum number of data centers to support after a failure. (default = 1)"
echo -e "\t-n Prefix name to use for db containers (lower case no special characters)."
#echo -e "\t-v Postgres Major version number. i.e 16. -- Used to create datadir and volumes"
echo -e "\t-b Start patroni in background and keep container running even if it stops. "
echo -e "\t Good for upgrades and maintenance tasks."
echo -e
echo -e $yellow
echo -e "\t-Number of db nodes is capped at 9. So (-d * -c) should be <= 9 "
echo -e
echo -e "\t-By default, the minimum number of data centers that can remain running out of the number of data centers declared is 1. Meaning everything"
echo -e "\t still works as long as 1 data center is active."
echo -e "\t This can be change by using -m option and specifying a value of 2 which would essentially only work with a minimum of 2 data centers running."
echo -e
echo -e "\t-Keep in mind that if the majority of your data centers are down, you have bigger problems to worry about."
echo -e $white
echo -e
if [ ! -z "$usageMessage" ]; then
echo -e "\t${usageMessage}"
echo -e
fi
exit
}
# -- build depends_on list for start order of containers
# -- Not a reliable way to control starting but it's a start.
# -- Consider using scripts that check
buildDependList() {
# -- Which service block (nodename) are we building this depends on list for?
buildingListFor=$1
if [ -z $2 ]; then
addEtcd="etcd"
else
addEtcd=$2
fi
local etcdNode
pgDependList="depends_on: "
# -- lets add etcd nodes first
# -- Also add capabaility of not adding the etcd nodes with a value other than "etcd" passed
if [ "${addEtcd}" == "etcd" ]; then
for etcdNode in ${etcdNameList};
do
# -- Preserve spaces below
pgDependList="${pgDependList}\n - ${etcdNode}"
done
fi
# Build list for pgbackrest depends on first pgnode
#if [ "$buildingListFor" == "$pgBackrestNodeName" ]; then
#pgDependList="${pgDependList}\n - ${firstNode}"
#fi
# -- We build the depends_on list of postgres nodes. However, the first node does not depend on any other node
# -- So, we skip this for the first node
if [ "$buildingListFor" == "$firstNode" ]; then
return
fi
# -- For now lets just depend on first node. If we want others, we can build a loop instead
# -- Preserve spaces below
pgDependList="${pgDependList}\n - ${firstNode}"
}
# -- Lets check running containers so we don't duplicatethem with the same name and ports
function checkUsed() {
# -- Check for postgres ports already mapped
usedPgPorts=$(docker ps --format "{{.Ports}}" | grep ":" | grep 5432 | awk -F ":" '{print $2}' | awk -F "-" '{print $1}' | sort | tail -1)
# -- Lets grab a container number. We focus on etcd1- since we know that will always be running if we spin up pgha clusters
# -- using these scripts. Otherwise, the awk might fail and grab another name to check that does not match the naming convention used
# -- remember the first number after the first hyphen in the name represents the container number
usedContainers=$(docker ps --format "{{.Names}}" | grep "etcd1-" | awk -F "-" '{print $NF}' | sort | tail -1)
}
# -- Determin how many etcd nodes we need
function etcdHostsNeeded() {
# Startingnumber of etcd nodes needed.
etcdNeeded=$(( $etcdPerDataCenter * $numDataCenters ))
if [ $etcdNeeded -le 2 ]; then
etcdNeeded=3;
fi
# Another variubal to hold original value since it will change
originalEtcdNeeded=$etcdNeeded
# Number of etcd nodes needed for a quorm based on the starting number of etcd nodes
quorumNeeded=$(( ($etcdNeeded / 2 ) + 1))
# The minimumn number od data centers to keep alive. Lower means more resources when deploying
remainingDC=$minDcNeeded
# ====================================== Important logic to understand. ======================================
#
# We will need etcd nodes outside the data centers to vote. This is so we can maintain quorium as others go down,
# So this is basically, the original number of etcdnodes needed, plus 1 additional set of external nodes.
# The additional number of external nodes is based number of etcd nodes per data center.
# Then we get the quorum needed based on this new number of nodes. Subtract howmany nodes perdata center which leaves us
# with how many extra nodes we need externally.
# For example, if you have 3 data centers with 2 etcdnodes per data center. That means a quorum of 4. ( 3 * 2 ) / 2 + 1
# if all data centers but 1 were to go down, your are left with only 1 data center with 2 etcd nodes.
# which is not enough to be a quorum.
# Throw in the external data center, now you have a total of 3 original data centers + the external data center which equals 4.
# With 4 data centers, 2 etcd nodes per data center, that gives us a total of 8.
# The quorum of 8, is ( 8 / 2 ) + 1 = 5;
# So we need a total of 5 etcd nodes to have a quorum
# So a total of 5 etcd nodes -2 ( the number left in running data center ) = 3. This meanse the external data center
# will need 3 etcd nodes
# And below this is the math for it.
nodesForExternalDC=$(( ( ( ($etcdNeeded + $etcdPerDataCenter) / 2 ) + 1 ) - $etcdPerDataCenter ))
# The total number of etcd nodes needed including external ones
totalNodes=$(( $etcdNeeded + $nodesForExternalDC ))
# Based on the total nodes and external data center, we get a new quorum
newQuorum=$(( (($totalNodes)/2) + 1 ))
# The number of extra etcd nodes to build
extraNeeded=$(( $newQuorum - $etcdPerDataCenter ))
# Self explanatory
nodesForExternalDC=$extraNeeded
# -------------------------------------------- NOTE -------------------------------------------------
# I Think I am reclaulating total nodes twice unnecessarily. Im just to tired to sii if i am right now
# ----------------------------------------------------------------------------------------------------
totalNodes=$(( $etcdNeeded + $extraNeeded ))
etcdNeeded=$totalNodes
echo -e $bold
echo -e $yellow
echo -e "\tOverview ..."
echo -e $normal
echo -e "\tNumber of data centers: $numDataCenters"
echo -e "\tOriginal number of ETCD nodes needed: $originalEtcdNeeded"
echo -e "\tOriginal number od ETCD nodes needed for a quorum: $quorumNeeded"
echo -e "\tOriginal number od ETCD nodes to deploy per data center: $etcdPerDataCenter"
echo -e "\tThe number of data centers to maintain running after all others fail: $minDcNeeded"
echo -e "\tNumber of external ETCD nodes needed outside of data centers to maintain a quorum: $nodesForExternalDC"
echo -e "\tTotal ETCD nodes needed including the external ones: $totalNodes"
echo -e "\tThe new number of nodes needed to maintain a quorum: $newQuorum"
echo -e
}
# build etcd hosts names based on datacenters and number of etcd per data center
# structure of name is as follows
# pgh-etcd<number out of nodes needed>-<datacenter>-<containernumber>
function buildEtcdNodeNames() {
etcdHostsNeeded
local counter
local nn
local dc
counter=1
dcCounter=1
dc=1
# stop incrementing data centers when we reach number of data centers
for (( nn=1; nn<=$etcdNeeded; nn++ ))
do
etcdNameList="${etcdNameList} pgha-etcd${nn}-DC${dc}-${containerNumber}"
counter=$(( counter + 1 ))
dcCounter=$(( dcCounter + 1 ))
#if [ $counter -gt $etcdPerDataCenter ];
# This got a little hacky. But we only need 1 non DC network for the nodes outside of data centers
# So, basically, the loop will cap it an number of data centers + 1
if [ $counter -gt $etcdPerDataCenter ];
then
counter=1
dc=$(( dc + 1 ))
if [ $dc -gt $numDataCenters ];
then
dc=$(( $numDataCenters + 1 ))
fi
fi
done
}
# -- Build string of postgres node names to use
function buildPgNodeNames() {
local d
local c
local nodeCount
nodeCount=0
pgNameList=""
#for (( d=1; d<=$numDataCenters; d++ ))
#do
#for (( c=1; c<=$nodesPerDataCenter; c++ ))
#do
#if [ $d -eq 1 ] && [ $c -eq 1 ]; then
#firstNode="pgha-${nodeName}$d-DC${c}-${containerNumber}"
#fi
#nodeCount=$(( $nodeCount + 1 ))
#pgNameList="${pgNameList} pgha-${nodeName}$d-DC${c}-${containerNumber}"
#done
#done
for (( d=1; d<=$numDataCenters; d++ ))
do
for (( c=1; c<=$nodesPerDataCenter; c++ ))
do
if [ $d -eq 1 ] && [ $c -eq 1 ]; then
firstNode="pgha-${nodeName}$c-DC${d}-${containerNumber}"
fi
pgNameList="${pgNameList} pgha-${nodeName}$c-DC${d}-${containerNumber}"
done
done
}
# -- Build string of pgbackrest node names to use. In reality just 1. But you never know
function buildPgBackrestNodeNames() {
# -- Only one bgbackrest server is actually needed.
# -- So, just hardcoding the name here
pgBackrestNeeded=1
pgBackrestNameList="pgha-pgbackrest-DC0-${containerNumber}"
pgBackrestNodeName="pgha-pgbackrest-DC0-${containerNumber}"
# -- If you want to use the loop to build the server name, just uncomment the code below
# -- Which is what is used for building multiple server names for etcd and pg servers
#pgBackrestNeeded=1
#pgBackrestNameList=""
#for (( x=1; x<=$pgBackrestNeeded; x++ ))
#do
#pgBackrestNameList="${pgBackrestNameList} pgbackrest${x}-${containerNumber}"
#done
}
function buildEtcdEnv() {
local x
endPoints=""
initialCluster=""
etcdNodeList=""
for etcdNode in ${etcdNameList}
do
endPoints="${endPoints}${etcdNode}:2380,"
initialCluster="${initialCluster}${etcdNode}=http://${etcdNode}:2380,"
etcdNodeList="${etcdNodeList}${etcdNode}:2379,"
done
# - remove trailing commas
endPoints=$(echo $endPoints | sed 's/,$//g')
initialCluster=$(echo $initialCluster | sed 's/,$//g')
etcdNodeList=$(echo $etcdNodeList | sed 's/,$//g')
}
# -- Build the etcd service blocks for the yaml file. One for each etcd node
buildEtcdService() {
buildEtcdEnv
for etcdNode in ${etcdNameList};
do
# extract the data center out of the node name so we can assign it to the proper network based on data center number
dataCenter=$( echo $etcdNode | awk -F "-" '{print $3}')
echo -e "
${etcdNode}:
image: pgha-etcd-3.5
restart: unless-stopped
environment:
ENDPOINTS: $endPoints
command:
- '/usr/bin/etcd'
- '--name=${etcdNode}'
- '--initial-advertise-peer-urls=http://${etcdNode}:2380'
- '--listen-peer-urls=http://0.0.0.0:2380'
- '--listen-client-urls=http://0.0.0.0:2379'
- '--advertise-client-urls=http://${etcdNode}:2379'
- '--heartbeat-interval=250'
- '--election-timeout=1250'
- '--initial-cluster=$initialCluster'
- '--initial-cluster-state=new'
- '--initial-cluster-token=pgha'
networks:
- pgha-net-${dataCenter}-${containerNumber} " >> $composeFile
# lets loop through networks. Need to stop the echo above, generate the networks, append them to compose file
# then resume the rest of the echo to finish up
networksNeeded=$(( numDataCenters + 1 ))
# skip this data center network since its define above as the first network
# basicallyjust adding remaining networks to list
for (( n=1; n<=$networksNeeded; n++ ))
do
x="DC$n"
#if [ $n == $dataCenter ]; then
if [ "$x" == "$dataCenter" ]; then
continue;
fi
echo -e " - pgha-net-DC${n}-${containerNumber} " >> $composeFile
done
echo -e "
ports:
- 2379
- 2380
volumes:
- ${etcdNode}:/etcd_data
hostname: ${etcdNode}
container_name: ${etcdNode}
" >> $composeFile
done
}
function getNodeInfo() {
local NodeName
nodeName=$1
dataCenter=$(echo $nodeName | awk -F "-" '{print $1}' | grep -o -E '[0-9]+')
nodeNumber=$(echo $nodeName | awk -F "-" '{print $3}' | grep -o -E '[0-9]+')
}
buildPgBackrestService() {
local nodeCount
local pgNode
local backrestNode
nodeCount=1
pgBackrestEnvList="environment:"
local nonDcNetwork=$(( numDataCenters + 1 ))
for backrestNode in ${pgBackrestNameList};
do
buildDependList $backrestNode "noEtcd"
# -- Lets build the pgBackrest node lists that will be used for the config
for pgNode in ${pgNameList};
do
pgBackrestEnvList="${pgBackrestEnvList}\n NODE${nodeCount}: ${pgNode}"
nodeCount=$(( $nodeCount + 1 ))
done
echo -e "
${backrestNode}:
${pgDependList}
${pgBackrestEnvList}
CFG_DIR: /pgha/config
REPO_PATH: /pgha/pgbackrest
DATADIR: /pgdata/${pgMajor}
STANZA_NAME: pgha_db
PGPORT: 5432
image: pgha-pgbackrest
restart: unless-stopped
networks:
- pgha-net-DC${nonDcNetwork}-${containerNumber} " >> $composeFile
# lets loop through networks. Need to stop the echo above, generate the networks, append them to compose file
# then resume the rest of the echo to finish up
networksNeeded=$(( numDataCenters + 1 ))
# skip the non dc data center network since its define above as the first network
# basicallyjust adding remaining networks to list
for (( n=1; n<=$networksNeeded; n++ ))
do
x="DC$n"
#if [ $n == $nonDcNetwork ]; then
if [ "$n" == "$nonDcNetwork" ]; then
continue;
fi
echo -e " - pgha-net-DC${n}-${containerNumber} " >> $composeFile
done
echo -e "
volumes:
- ${backrestNode}-data:/pgha/pgbackrest
- ${backrestNode}-home:/var/lib/postgresql
hostname: ${backrestNode}
container_name: ${backrestNode}
cap_add:
- SYS_ADMIN
entrypoint: /entrypoint.sh
" >> $composeFile
done
}
function buildNetworks() {
local d
local c
local nodeCount
nodeCount=0
pgNameList=""
networkList="networks: "
# Add one more network for etcd outside of dc's. ( quorum )
networksNeeded=$(( numDataCenters + 1 ))
for (( d=1; d<=$networksNeeded; d++ ))
do
networkList="${networkList}\n pgha-net-DC${d}-${containerNumber}:"
done
echo -e "
$networkList
" >> $composeFile
}
buildVolumes() {
volumeList=""
etcdVolumeList=""
pgbackrestVolumeList=""
# -- Build volumes used by pg containers
for pgNode in ${pgNameList};
do
v1="${pgNode}-data:"
v2="${pgNode}-home:"
v3="${pgNode}-conf:"
volumeList="${volumeList}\n ${v1}\n ${v2}\n ${v3}"
done
# -- Build volumes used by etcd containers
etcdVolumes=""
for etcdNode in ${etcdNameList};
do
etcdVolumeList="${etcdVolumeList}\n ${etcdNode}:"
done
# -- Build volumes used by pgbackrest containers
pgbackrestVolumeList=""
for pgBackrestNode in ${pgBackrestNameList};
do
pgbackrestVolumeList="${pgbackrestVolumeList}\n ${pgBackrestNode}-data:";
pgbackrestVolumeList="${pgbackrestVolumeList}\n ${pgBackrestNode}-home:";
done
echo -e "volumes: $etcdVolumeList $volumeList $pgbackrestVolumeList " >> $composeFile
}
buildPgService() {
buildEtcdEnv
local nodeCount
local dataCenter
nodeCount=0
for pgNode in ${pgNameList};
do
nodeCount=$(( $nodeCount + 1 ))
# -- We know the nodename has the datacenter number at the end of it. So lets pull that out since we need
# -- that data center to assign network priority
# -- So the call sets dataCenter and NodeNumber. We only use dataCenter here
getNodeInfo $pgNode
# -- lets generate unique ports to map
portMap=$(( startingPort + $nodeCount ))
# - Lets build the depend_on list. We let it know which service we are builing it for by passing the node
# - We also pass a 2nd argument "etcd" so that the function adss the etcd nodes to the depends on list
buildDependList $pgNode "etcd"
# extract the data center out of the node name so we can assign it to the proper network based on data center number
dataCenter=$( echo $pgNode | awk -F "-" '{print $3}')
echo -e "
${pgNode}:
${pgDependList}
environment:
ETCD_NODES: $etcdNodeList
NODE_NAME: ${pgNode}
CFG_DIR: /pgha/config
PATRONI_CFG: /pgha/config/patroni.conf
DATADIR: /pgdata/${pgMajor}
PG_BIN_DIR: /usr/lib/postgresql/${pgMajor}/bin
NAMESPACE: pgha
SCOPE: pgha_cluster
STANZA_NAME: pgha_db
PGBACKREST_SERVER: ${pgBackrestNodeName}
BACKGROUND: $backGround
image: pgha-pg16-patroni
restart: unless-stopped
cap_add:
- SYS_ADMIN
entrypoint: /entrypoint.sh
networks:
- pgha-net-${dataCenter}-${containerNumber} " >> $composeFile
# lets loop through networks. Need to stop the echo above, generate the networks, append them to compose file
# then resume the rest of the echo to finish up
networksNeeded=$(( numDataCenters + 1 ))
# skip this data center network since its define above as the first network
# basicallyjust adding remaining networks to list
for (( n=1; n<=$networksNeeded; n++ ))
do
x="DC$n"
#if [ $n == $dataCenter ]; then
if [ "$x" == "$dataCenter" ]; then
continue;
fi
echo -e " - pgha-net-DC${n}-${containerNumber} " >> $composeFile
done
echo -e "
ports:
- "${portMap}:5432"
volumes:
- ${pgNode}-data:/pgdata
- ${pgNode}-home:/var/lib/postgresql
- ${pgNode}-conf:/pgha/config
hostname: ${pgNode}
container_name: ${pgNode}
" >> $composeFile
done
}
# --- Validate its a number
function checkNumber() {
num=$1
var=$2
valid=0
regexp='^[0-9]+$'
if ! [[ $num =~ $regexp ]] ; then
echo -e
echo -e "Invalid number format of \"$num\" entered for \"$var\". Please correct and try again"
echo -e
exit
fi
}
function checkAlpha() {
str=$1
var=$2
valid=0
regexp='^[a-z]+$'
if ! [[ $str =~ $regexp ]] ; then
echo -e
echo -e "Only lower case letters are allowed. No special characters. Invalid format of \"$str\" entered for \"$var\". Please correct and try again"
echo -e
exit
fi
}
composeFile='docker-compose.yaml'
nodeName=""
numDataCenters=1
maxDataCenters=3
nodesPerDataCenter=2
etcdPerDataCenter=1
minDcNeeded=1
backGround=0
force=0
pgMajor=16 # Hard code for this version of postgres in this image
#bold=$(tput bold)
#normal=$(tput sgr0)
#white=$(tput setaf 7)
white="\033[00m"
red="\033[91m"
yellow="\033[93m"
bold="\033[1m"
normal="\033[0m"
while getopts fbn:d:c:e:m:v: name
do
case $name in
n) nodeName="$OPTARG";;
v) pgMajor="$OPTARG";;
b) backGround="1";;
f) force="1";;
d) numDataCenters="$OPTARG";;
c) nodesPerDataCenter="$OPTARG";;
e) etcdPerDataCenter="$OPTARG";;
m) minDcNeeded="$OPTARG";;
*) usage;;
?) usage;;
esac
done
shift $(($OPTIND - 1))
if [ -z "$nodeName" ] || [ -z "$pgMajor" ]; then
usage
fi
originalNodeName=$nodeName
checkAlpha $nodeName "-n"
checkNumber $pgMajor "-v"
checkNumber $numDataCenters "-d"
checkNumber $nodesPerDataCenter "-c"
composeFile="docker-compose.${nodeName}.yaml"
maxNodes=12
totalNodes=$(($numDataCenters * $nodesPerDataCenter))
if [ $totalNodes -gt $maxNodes ]; then
usageMessage="$bold You have exceeded the max number of nodes (${maxNodes}) allowed. "
usage
fi
if [ $numDataCenters -gt $maxDataCenters ] && [ $force -eq 0 ]; then
usageMessage="$bold You are requesting to deploy more than ${maxDataCenters} data centers. This will require more resources which could be problematic.\n\r\t If you wish to move forward, run genCompose with a -f $normal"
usage
fi
if [ $totalNodes -lt 2 ]; then
usageMessage="$bold You must have at least 2 nodes for Patroni. You have specified $numDataCenters data center and $nodesPerDataCenter node per data center."
usage
fi
# -- Lets find used ports and container numbers
checkUsed
if [ -z $usedPgPorts ]; then
startingPort=5432
else
startingPort=$usedPgPorts
fi
if [ -z $usedContainers ]; then
containerNumber=1
else
containerNumber=$(( $usedContainers + 1 ))
fi
# -- Lets start populating the compose file
echo "services:" > $composeFile
buildEtcdNodeNames
buildPgNodeNames
buildPgBackrestNodeNames
buildEtcdService
buildPgService
buildPgBackrestService
buildVolumes
buildNetworks
echo -e
echo -e $bold
echo -e "\tFile $composeFile generated"
echo -e
echo -e $bold $yellow
echo -e "\tTo get started, run ..."
echo -e $normal
echo -e
echo -e "\t\tdocker-compose -f $composeFile create"
echo -e "\t\tdocker-compose -f $composeFile start"
echo -e
echo -e $bold $yellow
echo -e "\tTo stop and delete the containers run ..."
echo -e $normal
echo -e
echo -e "\t\tdocker-compose -f $composeFile down"
echo -e
echo -e $bold $yellow
echo -e "\tTo remove associated volumes for good run ..."
echo -e $normal
echo -e
echo -e '\t\tdocker volume rm $(docker volume ls | grep pgha- | awk '\''{print $2}'\'') '
echo -e
echo -e $bold $yellow
echo -e "\tTry running the foloowing for a deploy status ..."
echo -e $normal
echo -e "\t\t./pghastat $originalNodeName"
echo -e