Skip to content

Commit f9b6a73

Browse files
committed
a
1 parent 0c01757 commit f9b6a73

File tree

4 files changed

+93
-43
lines changed

4 files changed

+93
-43
lines changed

main.json

+54-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"parameters": {
55
"tenantName": {
66
"type": "string",
7-
"defaultValue": "foo"
7+
"defaultValue": "barbaz"
88
},
99
"adminUsername": {
1010
"type": "string",
@@ -16,6 +16,15 @@
1616
"defaultValue": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAk/ViUPrGp7KoJLuN2PgofgMyw7SN9zfLYFDDR0TRYa8cOvJlE8NdZYt6Oqa4aL/fslKr9bmlMCdawhZRL7sHccIIS0I0zG7iD15rQL3/Y5aZOf3ML+bebpSj+SE5OeHT9iobgsYpK8gq72d8tmZZAfKhx6fRJsgC2j2xXH/GveoZ5GkHnhJUYuYPmNjEb/PK7LT43XuP+E9Rderr3LPUTuBeGVW9do0HS7X8I2uTn0+BqgkZLOO4FCnSXxh1u6fuD++ZgOZVmB6Q1xEdHSA7LLnPkjDZqbWezLIh5cSdNPUW2JG7tMxQTAZzVoNMb6vAVsfslB16rqZQ21EdIq+0pw== chgeuer-dcos-1",
1717
"metadata": { "description": "Admin SSH key for the Virtual Machines." }
1818
},
19+
"postgresqlUsername": {
20+
"type": "string",
21+
"defaultValue": "admin",
22+
"metadata": { "description": "PostgreSQL user name" }
23+
},
24+
"postgresqlPassword": {
25+
"type": "securestring",
26+
"metadata": { "description": "PostgreSQL password" }
27+
},
1928
"postgresqlInstanceCount": {
2029
"defaultValue": 2, "minValue": 2, "maxValue": 10, "type": "int",
2130
"metadata": { "description": "Number of postgreSQL servers in the cluster." }
@@ -31,17 +40,22 @@
3140
],
3241
"type": "string",
3342
"metadata": { "description": "Size of the postgreSQL server in the cluster." }
43+
},
44+
"postgresAzureVersion": {
45+
"defaultValue": "master",
46+
"type": "string"
3447
}
3548
},
3649
"variables": {
3750
"commonSettings": {
51+
"baseUrl": "[concat('https://raw.githubusercontent.com/chgeuer/postgres-azure/',parameters('postgresAzureVersion'),'/')]",
3852
"tenantName": "[parameters('tenantName')]",
3953
"constants": {
4054
"apiVersions": {
4155
"availabilitySets": "2016-04-30-preview"
4256
}
4357
},
44-
"vnet": {
58+
"vnet": {
4559
"name": "[concat(parameters('tenantName'),'-vnet')]",
4660
"address": "10.0.0.0/16",
4761
"subnet": {
@@ -65,7 +79,7 @@
6579
"patroni": "6eb2e2114453545256ac7cbfec55bda285ffb955",
6680
"postgres": "9.6"
6781
},
68-
"instanceCount": {
82+
"instanceCount": {
6983
"postgresql": 2,
7084
"postgresqlDataDiskCount": 3,
7185
"zookeeper": 2
@@ -334,8 +348,9 @@
334348
"apiVersion": "2016-04-30-preview",
335349
"location": "[resourceGroup().location]",
336350
"dependsOn": [
351+
"[concat('Microsoft.Compute/availabilitySets/', concat('availabilitySet-postgresql-', variables('commonSettings').tenantName))]",
337352
"[concat('Microsoft.Network/networkInterfaces/', concat('networkInterface-', 'postgresql', '-', copyIndex()))]",
338-
"[concat('Microsoft.Compute/availabilitySets/', concat('availabilitySet-postgresql-', variables('commonSettings').tenantName))]"
353+
"[concat('Microsoft.Compute/disks/', concat('osDisk-', 'postgresql', '-', copyIndex()))]"
339354
],
340355
"properties": {
341356
"hardwareProfile": { "vmSize": "[parameters('postgresqlInstanceSize')]" },
@@ -357,21 +372,47 @@
357372
}
358373
}
359374
},
375+
"storageProfile": {
376+
"imageReference":
377+
{
378+
"publisher": "[variables('commonSettings').vm.postgresql.publisher]",
379+
"offer": "[variables('commonSettings').vm.postgresql.offer]",
380+
"sku": "[variables('commonSettings').vm.postgresql.sku]",
381+
"version": "[variables('commonSettings').vm.postgresql.version]"
382+
},
383+
"osDisk": {
384+
"name": "[concat('osDisk-', 'postgresql', '-', copyIndex())]",
385+
"caching": "ReadWrite",
386+
"createOption": "FromImage"
387+
}
388+
},
360389
"networkProfile": {
361390
"networkInterfaces": [
362391
{
363392
"id": "[resourceId('Microsoft.Network/networkInterfaces', concat('networkInterface-', 'postgresql', '-', copyIndex()))]"
364393
}
365394
]
366-
},
367-
"storageProfile": {
368-
"osDisk": {
369-
"name": "[concat('osDisk-', 'postgresql', '-', copyIndex())]",
370-
"osType": "Linux",
371-
"caching": "ReadWrite",
372-
"createOption": "Attach",
373-
"managedDisk": { "id": "[resourceId('Microsoft.Compute/disks', concat('osDisk-', 'postgresql', '-', copyIndex()))]" }
374-
}
395+
}
396+
}
397+
},
398+
{
399+
"type": "Microsoft.Compute/virtualMachines/extensions",
400+
"name": "[concat('virtualMachine-', 'postgresql', '-', copyIndex(), '/extension')]",
401+
"apiVersion": "2015-05-01-preview",
402+
"location": "[resourceGroup().location]",
403+
"dependsOn": [ "[concat('Microsoft.Compute/virtualMachines/', concat('virtualMachine-', 'postgresql', '-', copyIndex()))]" ],
404+
"copy": { "name": "postgresqlVmExtensionCopy", "count": "[variables('commonSettings').instanceCount.postgresql]" },
405+
"properties": {
406+
"publisher": "Microsoft.OSTCExtensions",
407+
"type": "CustomScriptForLinux",
408+
"typeHandlerVersion": "1.2",
409+
"settings": {
410+
"fileUris": [
411+
"[concat(variables('baseUrl'), 'scripts/setup-raid.sh')]",
412+
"[concat(variables('baseUrl'), 'scripts/start-zk.sh')]",
413+
"[concat(variables('baseUrl'), 'scripts/start-pg.sh')]"
414+
],
415+
"commandToExecute": "[concat('./start-pg.sh ', parameters('clusterName'), ' ', concat(variables('commonSettings').vnet.subnet.zookeeper.addressRangePrefix, '.10'), ' ', variables('commonSettings').instanceCount.zookeeper, ' ', concat(variables('commonSettings').vnet.subnet.postgresql.addressRangePrefix, '.10'), ' ', variables('commonSettings').instanceCount.postgresql, ' ', copyIndex(), ' ', parameters('postgresqlUsername'), ' ', concat('\"', parameters('postgresqlPassword'), '\"'), ' ' variables('commonSettings').softwareversions.patroni, ' ',variables('commonSettings').softwareversions.postgres )]"
375416
}
376417
}
377418
}

postgresHAstandalone.json

+7-9
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313
"clusterName": {
1414
"type": "string"
1515
},
16-
"instanceCount": {
16+
"postgresqlInstanceCount": {
1717
"defaultValue": 2,
1818
"minValue": 2,
19-
"maxValue": 200,
19+
"maxValue": 10,
2020
"type": "int",
21-
"metadata": {
22-
"description": "Number of postgreSQL servers in the cluster."
23-
}
21+
"metadata": { "description": "Number of postgreSQL servers in the cluster." }
2422
},
2523
"instanceSize": {
2624
"type": "string",
@@ -262,6 +260,9 @@
262260
"name": "[concat('zookeeper', copyIndex(), '/zookeeperExtension')]",
263261
"apiVersion": "2015-05-01-preview",
264262
"location": "[resourceGroup().location]",
263+
"dependsOn": [
264+
"[concat('Microsoft.Compute/virtualMachines/', 'zookeeper', copyIndex())]"
265+
],
265266
"copy": {
266267
"name": "zookeeperExtLoop",
267268
"count": "[variables('zookeeperInstanceCount')]"
@@ -276,10 +277,7 @@
276277
],
277278
"commandToExecute": "[concat('./start-zk.sh ', copyIndex(), ' ', variables('zookeeperInstanceCount'), ' ', variables('zookeeperNetPrefix'), variables('zookeeperNetStartIP'))]"
278279
}
279-
},
280-
"dependsOn": [
281-
"[concat('Microsoft.Compute/virtualMachines/', 'zookeeper', copyIndex())]"
282-
]
280+
}
283281
},
284282
{
285283
"type": "Microsoft.Network/networkInterfaces",

scripts/start-pg.sh

+18-19
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ function createIp {
3030

3131
# "commandToExecute": "[concat('./start-pg.sh ',
3232
# parameters('clusterName'), ' ',
33-
# variables('zookeeperNetPrefix'), variables('zookeeperNetStartIP'), ' ',
34-
# variables('zookeeperInstanceCount'), ' ',
35-
# variables('postgresNetPrefix'), variables('postgresNetStartIP'), ' ',
36-
# variables('postgresInstanceCount'), ' ',
33+
# concat(variables('commonSettings').vnet.subnet.zookeeper.addressRangePrefix, '.10'), ' ',
34+
# variables('commonSettings').instanceCount.zookeeper, ' ',
35+
# concat(variables('commonSettings').vnet.subnet.postgresql.addressRangePrefix, '.10'), ' ',
36+
# variables('commonSettings').instanceCount.postgresql, ' ',
3737
# copyIndex(), ' ',
38-
# parameters('adminUsername'),
39-
# ' \"', parameters('adminPassword'), '\" ',
38+
# parameters('postgresqlUsername'), ' ',
39+
# concat('\"', parameters('postgresqlPassword'), '\"'), ' '
4040
# variables('commonSettings').softwareversions.patroni, ' ',
4141
# variables('commonSettings').softwareversions.postgres )]"
4242

@@ -46,12 +46,11 @@ amountZooKeepers=$3
4646
startIpPostgres=$4
4747
amountPostgres=$5
4848
myIndex=$6
49-
adminUsername=$7
50-
adminPassword=$8
49+
postgresqlUsername=$7
50+
postgresqlPassword=$8
5151
patroniversion=$9
5252
pgversion=$10
5353

54-
5554
patroniDir="/usr/local/patroni-${patroniversion}"
5655
patroniCfg="${patroniDir}/postgres.yml"
5756
hacfgFile="${patroniDir}/postgresha.cfg"
@@ -62,8 +61,8 @@ cat > startup.log <<-EOF
6261
Zookeepers: $amountZooKeepers
6362
Postgres start IP: $startIpPostgres
6463
Postgres: $amountPostgres
65-
Admin user: $adminUsername
66-
Admin password: $adminPassword
64+
PostgreSQL user: $postgresqlUsername
65+
PostgreSQL password: $postgresqlPassword
6766
MyIndex: $myIndex
6867
patroniversion: $patroniversion
6968
EOF
@@ -228,7 +227,7 @@ if [[ $myIndex -eq 0 ]]; then
228227
- host all all 0.0.0.0/0 md5
229228
users:
230229
admin:
231-
password: "$adminPassword"
230+
password: "$postgresqlPassword"
232231
options:
233232
- createrole
234233
- createdb
@@ -265,19 +264,19 @@ cat >> $patroniCfg <<-EOF
265264
- data-checksums
266265
pg_rewind:
267266
username: postgres
268-
password: "$adminPassword"
267+
password: "$postgresqlPassword"
269268
pg_hba:
270269
- host replication all 0.0.0.0/0 md5
271270
- host all all 0.0.0.0/0 md5
272271
replication:
273272
username: replicator
274-
password: "$adminPassword"
273+
password: "$postgresqlPassword"
275274
superuser:
276275
username: postgres
277-
password: "$adminPassword"
276+
password: "$postgresqlPassword"
278277
admin:
279278
username: admin
280-
password: "$adminPassword"
279+
password: "$postgresqlPassword"
281280
create_replica_method:
282281
- basebackup
283282
recovery_conf:
@@ -299,10 +298,10 @@ cat >> $patroniCfg <<-EOF
299298
authentication:
300299
replication:
301300
username: replicator
302-
password: "$adminPassword"
301+
password: "$postgresqlPassword"
303302
superuser:
304303
username: postgres
305-
password: "$adminPassword"
304+
password: "$postgresqlPassword"
306305
parameters:
307306
unix_socket_directories: '.'
308307
EOF
@@ -346,7 +345,7 @@ chmod +x ${patroniDir}/patroni_start.sh
346345
cat > /etc/supervisor/conf.d/patroni.conf <<-EOF
347346
[program:patroni]
348347
command=${patroniDir}/patroni_start.sh
349-
user=$adminUsername
348+
user=$postgresqlUsername
350349
autostart=true
351350
autorestart=true
352351
stderr_logfile=/var/log/patroni.err.log

scripts/start-zk.sh

+14-2
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,32 @@ function createIp {
2727
# "commandToExecute": "[concat('./start-zk.sh ',
2828
# copyIndex(), ' ',
2929
# variables('zookeeperInstanceCount'), ' ',
30-
# variables('zookeeperNetPrefix'), variables('zookeeperNetStartIP'))]"
30+
# variables('zookeeperNetPrefix'), variables('zookeeperNetStartIP'), ' '
31+
# variables('commonSettings').softwareversions.zookeeper, ' ',
32+
# variables('commonSettings').softwareversions.java4zookeeper1, ' ',
33+
# variables('commonSettings').softwareversions.java4zookeeper2)]"
34+
35+
36+
./start-zk.sh 1
3137

3238
#myIndex=$1
3339
#instanceCount=$2
3440
#startIp=$3
41+
#zkversion=$4
42+
#javaversion1=$5
43+
#javaversion2=$6
44+
45+
46+
3547

3648
myIndex=1
3749
instanceCount=3
3850
startIp=10.0.0.10
39-
4051
zkversion=3.4.9
4152
javaversion1=7u75
4253
javaversion2=b13
4354

55+
4456
apt-get -y install jq supervisor
4557

4658
#

0 commit comments

Comments
 (0)