2
2
3
3
# osmosis tuning: https://wiki.openstreetmap.org/wiki/Osmosis/Tuning,https://lists.openstreetmap.org/pipermail/talk/2012-October/064771.html
4
4
if [ -z " $MEMORY_JAVACMD_OPTIONS " ]; then
5
- echo JAVACMD_OPTIONS=\" -server\" > ~/.osmosis
5
+ echo JAVACMD_OPTIONS=\" -server\" > ~/.osmosis
6
6
else
7
- memory=" ${MEMORY_JAVACMD_OPTIONS// i/ } "
8
- echo JAVACMD_OPTIONS=\" -server -Xmx$memory \" > ~/.osmosis
7
+ memory=" ${MEMORY_JAVACMD_OPTIONS// i/ } "
8
+ echo JAVACMD_OPTIONS=\" -server -Xmx$memory \" > ~/.osmosis
9
9
fi
10
10
11
11
workingDirectory=" /mnt/data"
@@ -14,91 +14,91 @@ mkdir -p $workingDirectory
14
14
# Check if state.txt exist in the workingDirectory,
15
15
# in case the file does not exist locally and does not exist in the cloud the replication will start from 0
16
16
if [ ! -f $workingDirectory /state.txt ]; then
17
- echo " File $workingDirectory /state.txt does not exist"
18
- # ## AWS
19
- if [ $CLOUDPROVIDER == " aws" ]; then
20
- aws s3 ls $AWS_S3_BUCKET /$REPLICATION_FOLDER /state.txt
21
- if [[ $? -eq 0 ]]; then
22
- echo " File exist, let's get it from $CLOUDPROVIDER - $AWS_S3_BUCKET "
23
- aws s3 cp $AWS_S3_BUCKET /$REPLICATION_FOLDER /state.txt $workingDirectory /state.txt
24
- fi
25
- fi
26
-
27
- # ## GCP
28
- if [ $CLOUDPROVIDER == " gcp" ]; then
29
- gsutil ls $GCP_STORAGE_BUCKET /$REPLICATION_FOLDER /state.txt
30
- if [[ $? -eq 0 ]]; then
31
- echo " File exist, let's get it from $CLOUDPROVIDER - $GCP_STORAGE_BUCKET "
32
- gsutil cp $GCP_STORAGE_BUCKET /$REPLICATION_FOLDER /state.txt $workingDirectory /state.txt
33
- fi
34
- fi
35
-
36
- # ## Azure
37
- if [ $CLOUDPROVIDER == " azure" ]; then
38
- state_file_exists=$( az storage blob exists --container-name $AZURE_CONTAINER_NAME --name $REPLICATION_FOLDER /state.txt --query=" exists" )
39
- if [[ $state_file_exists == " true" ]]; then
40
- echo " File exist, let's get it from $CLOUDPROVIDER - $AZURE_CONTAINER_NAME "
41
- az storage blob download \
42
- --container-name $AZURE_CONTAINER_NAME \
43
- --name $REPLICATION_FOLDER /state.txt \
44
- --file $workingDirectory /state.txt --query=" name"
45
- fi
46
- fi
47
- mkdir -p $workingDirectory
17
+ echo " File $workingDirectory /state.txt does not exist in local storage "
18
+ # ## AWS
19
+ if [ $CLOUDPROVIDER == " aws" ]; then
20
+ aws s3 ls $AWS_S3_BUCKET /$REPLICATION_FOLDER /state.txt
21
+ if [[ $? -eq 0 ]]; then
22
+ echo " File exist, let's get it from $CLOUDPROVIDER - $AWS_S3_BUCKET "
23
+ aws s3 cp $AWS_S3_BUCKET /$REPLICATION_FOLDER /state.txt $workingDirectory /state.txt
24
+ fi
25
+ fi
26
+
27
+ # ## GCP
28
+ if [ $CLOUDPROVIDER == " gcp" ]; then
29
+ gsutil ls $GCP_STORAGE_BUCKET /$REPLICATION_FOLDER /state.txt
30
+ if [[ $? -eq 0 ]]; then
31
+ echo " File exist, let's get it from $CLOUDPROVIDER - $GCP_STORAGE_BUCKET "
32
+ gsutil cp $GCP_STORAGE_BUCKET /$REPLICATION_FOLDER /state.txt $workingDirectory /state.txt
33
+ fi
34
+ fi
35
+
36
+ # ## Azure
37
+ if [ $CLOUDPROVIDER == " azure" ]; then
38
+ state_file_exists=$( az storage blob exists --container-name $AZURE_CONTAINER_NAME --name $REPLICATION_FOLDER /state.txt --query=" exists" )
39
+ if [[ $state_file_exists == " true" ]]; then
40
+ echo " File exist, let's get it from $CLOUDPROVIDER - $AZURE_CONTAINER_NAME "
41
+ az storage blob download \
42
+ --container-name $AZURE_CONTAINER_NAME \
43
+ --name $REPLICATION_FOLDER /state.txt \
44
+ --file $workingDirectory /state.txt --query=" name"
45
+ fi
46
+ fi
47
+ mkdir -p $workingDirectory
48
48
fi
49
49
50
50
# Creating the replication files
51
51
function generateReplication() {
52
- osmosis -q \
53
- --replicate-apidb \
54
- iterations=0 \
55
- minInterval=60000 \
56
- maxInterval=120000 \
57
- host=$POSTGRES_HOST \
58
- database=$POSTGRES_DB \
59
- user=$POSTGRES_USER \
60
- password=$POSTGRES_PASSWORD \
61
- validateSchemaVersion=no \
62
- --write-replication \
63
- workingDirectory=$workingDirectory &
64
- while true ; do
65
- for local_file in $( find $workingDirectory / -cmin -1) ; do
66
- if [ -f " $local_file " ]; then
67
-
68
- cloud_file=$REPLICATION_FOLDER /${local_file#* " $workingDirectory /" }
69
- echo $( date +%F_%H:%M:%S) " : Copy file...$local_file to $cloud_file "
70
-
71
- # ## AWS
72
- if [ $CLOUDPROVIDER == " aws" ]; then
73
- aws s3 cp $local_file $AWS_S3_BUCKET /$cloud_file --acl public-read
74
- fi
75
-
76
- # ## GCP
77
- if [ $CLOUDPROVIDER == " gcp" ]; then
78
- # TODO, emable public acces
79
- gsutil cp -a public-read $local_file $GCP_STORAGE_BUCKET /$cloud_file
80
- fi
81
-
82
- # ## Azure
83
- if [ $CLOUDPROVIDER == " azure" ]; then
84
- # TODO, emable public acces
85
- az storage blob upload \
86
- --container-name $AZURE_CONTAINER_NAME \
87
- --file $local_file \
88
- --name $cloud_file \
89
- --output none
90
- fi
91
- fi
92
- done
93
- sleep 15s
94
- done
52
+ osmosis -q \
53
+ --replicate-apidb \
54
+ iterations=0 \
55
+ minInterval=60000 \
56
+ maxInterval=120000 \
57
+ host=$POSTGRES_HOST \
58
+ database=$POSTGRES_DB \
59
+ user=$POSTGRES_USER \
60
+ password=$POSTGRES_PASSWORD \
61
+ validateSchemaVersion=no \
62
+ --write-replication \
63
+ workingDirectory=$workingDirectory &
64
+ while true ; do
65
+ for local_file in $( find $workingDirectory / -cmin -1) ; do
66
+ if [ -f " $local_file " ]; then
67
+
68
+ cloud_file=$REPLICATION_FOLDER /${local_file#* " $workingDirectory /" }
69
+ echo $( date +%F_%H:%M:%S) " : Copy file...$local_file to $cloud_file "
70
+
71
+ # ## AWS
72
+ if [ $CLOUDPROVIDER == " aws" ]; then
73
+ aws s3 cp $local_file $AWS_S3_BUCKET /$cloud_file --acl public-read
74
+ fi
75
+
76
+ # ## GCP
77
+ if [ $CLOUDPROVIDER == " gcp" ]; then
78
+ # TODO, emable public acces
79
+ gsutil cp -a public-read $local_file $GCP_STORAGE_BUCKET /$cloud_file
80
+ fi
81
+
82
+ # ## Azure
83
+ if [ $CLOUDPROVIDER == " azure" ]; then
84
+ # TODO, emable public acces
85
+ az storage blob upload \
86
+ --container-name $AZURE_CONTAINER_NAME \
87
+ --file $local_file \
88
+ --name $cloud_file \
89
+ --output none
90
+ fi
91
+ fi
92
+ done
93
+ sleep 15s
94
+ done
95
95
}
96
96
97
97
# Check if Postgres is ready
98
98
flag=true
99
99
while " $flag " = true ; do
100
- pg_isready -h $POSTGRES_HOST -p 5432 > /dev/null 2>&2 || continue
101
- # Change flag to false to stop ping the DB
102
- flag=false
103
- generateReplication
100
+ pg_isready -h $POSTGRES_HOST -p 5432 > /dev/null 2>&2 || continue
101
+ # Change flag to false to stop ping the DB
102
+ flag=false
103
+ generateReplication
104
104
done
0 commit comments