Skip to content

Commit 4f02682

Browse files
committed
Use different configurations for Neo4j v4 and v5
1 parent a62eb91 commit 4f02682

File tree

3 files changed

+82
-40
lines changed

3 files changed

+82
-40
lines changed

scripts/setupNeo4j.sh

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -74,54 +74,78 @@ if [ ! -d "${NEO4J_INSTALLATION_DIRECTORY}" ] ; then
7474
echo "setupNeo4j: ${NEO4J_INSTALLATION_NAME} already downloaded"
7575
fi
7676

77+
downloaded_neo4j_archive="${SHARED_DOWNLOADS_DIRECTORY}/${NEO4J_INSTALLATION_NAME}-unix.tar.gz"
78+
79+
# Check downloaded file size to be at least 100 bytes
80+
downloaded_file_size=$(wc -c "${downloaded_neo4j_archive}")
81+
if [[ "$downloaded_file_size" -le 100 ]]; then
82+
echo "setupNeo4j: Error: Failed to download ${NEO4J_INSTALLATION_NAME}: Invalid Filesize."
83+
rm -f "${downloaded_neo4j_archive}"
84+
exit 1
85+
fi
86+
7787
# Extract the tar file
78-
tar -xf "${SHARED_DOWNLOADS_DIRECTORY}/${NEO4J_INSTALLATION_NAME}-unix.tar.gz" --directory "${TOOLS_DIRECTORY}"
88+
tar -xf "${downloaded_neo4j_archive}" --directory "${TOOLS_DIRECTORY}"
7989

8090
# Fail if Neo4j hadn't been downloaded successfully
8191
if [ ! -d "${NEO4J_INSTALLATION_DIRECTORY}" ] ; then
8292
echo "setupNeo4j: Error: Failed to download ${NEO4J_INSTALLATION_NAME} from ${NEO4J_DOWNLOAD_BASE_URL} into ${TOOLS_DIRECTORY}"
8393
exit 1
8494
fi
8595

96+
# Extract the first component of the version number (=major version number)
97+
NEO4J_MAJOR_VERSION_NUMBER=$(echo "$NEO4J_VERSION" | cut -d'.' -f1)
98+
8699
# Configure all paths with data that changes (database data, logs, ...) to be in the outside "data" directory
87100
# instead of inside the neo4j directory
88101
echo "setupNeo4j: Configuring dynamic settings (data directories, ports, ...)"
89-
{
90-
echo ""
91-
echo "# Paths of data directories in the installation"
92-
echo "dbms.directories.data=${NEO4J_DATA_PATH}"
93-
echo "dbms.directories.logs=${NEO4J_RUNTIME_PATH}/logs"
94-
echo "dbms.directories.dumps.root=${NEO4J_RUNTIME_PATH}/dumps"
95-
echo "dbms.directories.run=${NEO4J_RUNTIME_PATH}/run"
96-
echo "dbms.directories.transaction.logs.root=${NEO4J_DATA_PATH}/transactions"
97-
echo ""
98-
echo "# Ports Configuration"
99-
echo "dbms.connector.bolt.listen_address=:${NEO4J_BOLT_PORT}"
100-
echo "dbms.connector.bolt.advertised_address=:${NEO4J_BOLT_PORT}"
101-
echo "dbms.connector.http.listen_address=:${NEO4J_HTTP_PORT}"
102-
echo "dbms.connector.http.advertised_address=:${NEO4J_HTTP_PORT}"
103-
echo "dbms.connector.https.listen_address=:${NEO4J_HTTPS_PORT}"
104-
echo "dbms.connector.https.advertised_address=:${NEO4J_HTTPS_PORT}"
105-
echo ""
106-
echo "# Paths of data directories in the installation (v5)"
107-
echo "server.directories.data=${NEO4J_DATA_PATH}"
108-
echo "server.directories.logs=${NEO4J_RUNTIME_PATH}/logs"
109-
echo "server.directories.dumps.root=${NEO4J_RUNTIME_PATH}/dumps"
110-
echo "server.directories.run=${NEO4J_RUNTIME_PATH}/run"
111-
echo "server.directories.transaction.logs.root=${NEO4J_DATA_PATH}/transactions"
112-
echo ""
113-
echo "# Ports Configuration (v5)"
114-
echo "server.bolt.listen_address=:${NEO4J_BOLT_PORT}"
115-
echo "server.bolt.advertised_address=:${NEO4J_BOLT_PORT}"
116-
echo "server.http.listen_address=:${NEO4J_HTTP_PORT}"
117-
echo "server.http.advertised_address=:${NEO4J_HTTP_PORT}"
118-
echo "server.https.listen_address=:${NEO4J_HTTPS_PORT}"
119-
echo "server.https.advertised_address=:${NEO4J_HTTPS_PORT}"
120102

121-
} >> "${NEO4J_CONFIG}"
103+
if [[ "$NEO4J_MAJOR_VERSION_NUMBER" -ge 5 ]]; then
104+
echo "setupNeo4j: Neo4j v5 or higher detected"
105+
{
106+
echo ""
107+
echo "# Paths of data directories in the installation (v5)"
108+
echo "server.directories.data=${NEO4J_DATA_PATH}"
109+
echo "server.directories.logs=${NEO4J_RUNTIME_PATH}/logs"
110+
echo "server.directories.dumps.root=${NEO4J_RUNTIME_PATH}/dumps"
111+
echo "server.directories.run=${NEO4J_RUNTIME_PATH}/run"
112+
echo "server.directories.transaction.logs.root=${NEO4J_DATA_PATH}/transactions"
113+
echo ""
114+
echo "# Ports Configuration (v5)"
115+
echo "server.bolt.listen_address=:${NEO4J_BOLT_PORT}"
116+
echo "server.bolt.advertised_address=:${NEO4J_BOLT_PORT}"
117+
echo "server.http.listen_address=:${NEO4J_HTTP_PORT}"
118+
echo "server.http.advertised_address=:${NEO4J_HTTP_PORT}"
119+
echo "server.https.listen_address=:${NEO4J_HTTPS_PORT}"
120+
echo "server.https.advertised_address=:${NEO4J_HTTPS_PORT}"
121+
} >> "${NEO4J_CONFIG}"
122+
else
123+
echo "setupNeo4j: Neo4j v4 or lower detected"
124+
{
125+
echo ""
126+
echo "# Paths of data directories in the installation"
127+
echo "dbms.directories.data=${NEO4J_DATA_PATH}"
128+
echo "dbms.directories.logs=${NEO4J_RUNTIME_PATH}/logs"
129+
echo "dbms.directories.dumps.root=${NEO4J_RUNTIME_PATH}/dumps"
130+
echo "dbms.directories.run=${NEO4J_RUNTIME_PATH}/run"
131+
echo "dbms.directories.transaction.logs.root=${NEO4J_DATA_PATH}/transactions"
132+
echo ""
133+
echo "# Ports Configuration"
134+
echo "dbms.connector.bolt.listen_address=:${NEO4J_BOLT_PORT}"
135+
echo "dbms.connector.bolt.advertised_address=:${NEO4J_BOLT_PORT}"
136+
echo "dbms.connector.http.listen_address=:${NEO4J_HTTP_PORT}"
137+
echo "dbms.connector.http.advertised_address=:${NEO4J_HTTP_PORT}"
138+
echo "dbms.connector.https.listen_address=:${NEO4J_HTTPS_PORT}"
139+
echo "dbms.connector.https.advertised_address=:${NEO4J_HTTPS_PORT}"
140+
} >> "${NEO4J_CONFIG}"
141+
fi
122142

123143
echo "setupNeo4j: Configuring static settings (memory, procedure permittions, ...)"
124-
cat "${SCRIPTS_DIR}/templates/template-neo4j.conf" >> "${NEO4J_CONFIG}"
144+
if [[ "$NEO4J_MAJOR_VERSION_NUMBER" -ge 5 ]]; then
145+
cat "${SCRIPTS_DIR}/templates/template-neo4j.conf" >> "${NEO4J_CONFIG}"
146+
else
147+
cat "${SCRIPTS_DIR}/templates/template-neo4j-v4.conf" >> "${NEO4J_CONFIG}"
148+
fi
125149

126150
# Set initial password for user "neo4j" otherwise the default password "neo4j" would need to be changed immediately (prompt).
127151
# This needs to be done after the configuration changes.
@@ -142,6 +166,7 @@ if [ ! -f "${NEO4J_INSTALLATION_DIRECTORY}/plugins/${NEO4J_APOC_PLUGIN_ARTIFACT}
142166
echo "setupNeo4j: ${NEO4J_APOC_PLUGIN_ARTIFACT} already downloaded"
143167
fi
144168

169+
# Check downloaded file size to be at least 100 bytes
145170
downloaded_file_size=$(wc -c "${SHARED_DOWNLOADS_DIRECTORY}/${NEO4J_APOC_PLUGIN_ARTIFACT}")
146171
if [[ "$downloaded_file_size" -le 100 ]]; then
147172
echo "setupNeo4j: Error: Failed to download ${NEO4J_APOC_PLUGIN_ARTIFACT}: Invalid Filesize."
@@ -185,6 +210,7 @@ if [ ! -f "${NEO4J_INSTALLATION_DIRECTORY}/plugins/${NEO4J_GDS_PLUGIN_ARTIFACT}"
185210
echo "setupNeo4j: ${NEO4J_GDS_PLUGIN_ARTIFACT} already downloaded"
186211
fi
187212

213+
# Check downloaded file size to be at least 100 bytes
188214
downloaded_file_size=$(wc -c "${SHARED_DOWNLOADS_DIRECTORY}/${NEO4J_GDS_PLUGIN_ARTIFACT}" | awk '{print $1}')
189215
if [[ "$downloaded_file_size" -le 100 ]]; then
190216
echo "setupNeo4j: Error: Failed to download ${NEO4J_GDS_PLUGIN_ARTIFACT}. Invalid Filesize."
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
# The following static configuration entries were taken from "template-neo4j.conf".
3+
4+
# List of procedures and user defined functions that are allowed
5+
# full access to the database through unsupported/insecure internal APIs.
6+
dbms.security.procedures.unrestricted=apoc.*,gds.*
7+
8+
# Memory: Java Heap Size
9+
dbms.memory.heap.initial_size=1024m
10+
dbms.memory.heap.max_size=1024m
11+
12+
# Memory: The amount of memory to use for mapping the store files.
13+
dbms.memory.pagecache.size=16m
14+
15+
# Memory: Exits JVM on the first occurrence of an out-of-memory error.
16+
dbms.jvm.additional=-XX:+ExitOnOutOfMemoryError
17+
18+
# Memory: Limit the amount of memory that all of the running transaction can consume.
19+
dbms.memory.transaction.global_max_size=384m
20+
21+
# Memory: Limit the amount of memory that a single transaction can consume.
22+
dbms.memory.transaction.max_size=256m

scripts/templates/template-neo4j.conf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,17 @@
66
dbms.security.procedures.unrestricted=apoc.*,gds.*
77

88
# Memory: Java Heap Size
9-
dbms.memory.heap.initial_size=1024m
10-
dbms.memory.heap.max_size=1024m
119
server.memory.heap.initial_size=1024m
1210
server.memory.heap.max_size=1024m
1311

1412
# Memory: The amount of memory to use for mapping the store files.
15-
dbms.memory.pagecache.size=16m
1613
server.memory.pagecache.size=16m
1714

1815
# Memory: Exits JVM on the first occurrence of an out-of-memory error.
19-
dbms.jvm.additional=-XX:+ExitOnOutOfMemoryError
2016
server.jvm.additional=-XX:+ExitOnOutOfMemoryError
2117

2218
# Memory: Limit the amount of memory that all of the running transaction can consume.
23-
dbms.memory.transaction.global_max_size=384m
2419
db.memory.transaction.total.max=384m
2520

2621
# Memory: Limit the amount of memory that a single transaction can consume.
27-
dbms.memory.transaction.max_size=256m
2822
db.memory.transaction.max=256m

0 commit comments

Comments
 (0)