@@ -95,7 +95,7 @@ function check_mounted_folder_readable
9595 fi
9696}
9797
98- function check_mounted_folder_writable_with_chown
98+ function check_mounted_folder_with_chown
9999{
100100# The /data and /log directory are a bit different because they are very likely to be mounted by the user but not
101101# necessarily writable.
@@ -213,79 +213,6 @@ function install_neo4j_labs_plugins
213213 rm " ${_old_config} "
214214}
215215
216- function add_docker_default_to_conf
217- {
218- # docker defaults should NOT overwrite values already in the conf file
219- local _setting=" ${1} "
220- local _value=" ${2} "
221- local _neo4j_home=" ${3} "
222-
223- if ! grep -q " ^${_setting} =" " ${_neo4j_home} " /conf/neo4j.conf
224- then
225- echo -e " \n" ${_setting} =${_value} >> " ${_neo4j_home} " /conf/neo4j.conf
226- fi
227- }
228-
229- function add_env_setting_to_conf
230- {
231- # settings from environment variables should overwrite values already in the conf
232- local _setting=${1}
233- local _value=${2}
234- local _neo4j_home=${3}
235-
236- if grep -q -F " ${_setting} =" " ${_neo4j_home} " /conf/neo4j.conf; then
237- # Remove any lines containing the setting already
238- sed --in-place " /^${_setting} =.*/d" " ${_neo4j_home} " /conf/neo4j.conf
239- fi
240- # Then always append setting to file
241- echo " ${_setting} =${_value} " >> " ${_neo4j_home} " /conf/neo4j.conf
242- }
243-
244- function set_initial_password
245- {
246- local _neo4j_auth=" ${1} "
247-
248- # set the neo4j initial password only if you run the database server
249- if [ " ${cmd} " == " neo4j" ]; then
250- if [ " ${_neo4j_auth:- } " == " none" ]; then
251- add_env_setting_to_conf " dbms.security.auth_enabled" " false" " ${NEO4J_HOME} "
252- # NEO4J_dbms_security_auth__enabled=false
253- elif [[ " ${_neo4j_auth:- } " =~ ^([^/]+)\/ ([^/]+)/? ([tT][rR][uU][eE])? $ ]]; then
254- admin_user=" ${BASH_REMATCH[1]} "
255- password=" ${BASH_REMATCH[2]} "
256- do_reset=" ${BASH_REMATCH[3]} "
257-
258- if [ " ${password} " == " neo4j" ]; then
259- echo >&2 " Invalid value for password. It cannot be 'neo4j', which is the default."
260- exit 1
261- fi
262- if [ " ${admin_user} " != " neo4j" ]; then
263- echo >&2 " Invalid admin username, it must be neo4j"
264- exit 1
265- fi
266-
267- if running_as_root; then
268- # running set-initial-password as root will create subfolders to /data as root, causing startup fail when neo4j can't read or write the /data/dbms folder
269- # creating the folder first will avoid that
270- mkdir -p /data/dbms
271- chown " ${userid} " :" ${groupid} " /data/dbms
272- fi
273-
274- # Will exit with error if users already exist (and print a message explaining that)
275- # we probably don't want the message though, since it throws an error message on restarting the container.
276- if [ " ${do_reset} " == " true" ]; then
277- neo4j-admin set-initial-password " ${password} " --require-password-change 2> /dev/null || true
278- else
279- neo4j-admin set-initial-password " ${password} " 2> /dev/null || true
280- fi
281- elif [ -n " ${_neo4j_auth:- } " ]; then
282- echo " $_neo4j_auth is invalid"
283- echo >&2 " Invalid value for NEO4J_AUTH: '${_neo4j_auth} '"
284- exit 1
285- fi
286- fi
287- }
288-
289216# If we're running as root, then run as the neo4j user. Otherwise
290217# docker is running with --user and we simply use that user. Note
291218# that su-exec, despite its name, does not replicate the functionality
@@ -319,15 +246,13 @@ if running_as_root; then
319246fi
320247
321248# Only prompt for license agreement if command contains "neo4j" in it
322- # ==== CHECK LICENSE AGREEMENT ====
323-
324249if [[ " ${cmd} " == * " neo4j" * ]]; then
325250 if [ " ${NEO4J_EDITION} " == " enterprise" ]; then
326251 if [ " ${NEO4J_ACCEPT_LICENSE_AGREEMENT:= no} " != " yes" ]; then
327252 echo >&2 "
328253In order to use Neo4j Enterprise Edition you must accept the license agreement.
329254
330- (c) Neo4j Sweden AB. 2021 . All Rights Reserved.
255+ (c) Neo4j Sweden AB. 2019 . All Rights Reserved.
331256Use of this Software without a proper commercial license with Neo4j,
332257Inc. or its affiliates is prohibited.
333258
@@ -349,8 +274,6 @@ To do this you can use the following docker argument:
349274fi
350275
351276# Env variable naming convention:
352- # ==== RENAME LEGACY ENVIRONMENT CONF VARIABLES ====
353-
354277# - prefix NEO4J_
355278# - double underscore char '__' instead of single underscore '_' char in the setting name
356279# - underscore char '_' instead of dot '.' char in the setting name
360283
361284# Backward compatibility - map old hardcoded env variables into new naming convention (if they aren't set already)
362285# Set some to default values if unset
363- : ${NEO4J_dbms_tx__log_rotation_retention__policy:= ${NEO4J_dbms_txLog_rotation_retentionPolicy:- } }
286+ : ${NEO4J_dbms_tx__log_rotation_retention__policy:= ${NEO4J_dbms_txLog_rotation_retentionPolicy:- " 100M size " } }
364287: ${NEO4J_wrapper_java_additional:= ${NEO4J_UDC_SOURCE:- " -Dneo4j.ext.udc.source=docker" } }
365288: ${NEO4J_dbms_unmanaged__extension__classes:= ${NEO4J_dbms_unmanagedExtensionClasses:- } }
366289: ${NEO4J_dbms_allow__format__migration:= ${NEO4J_dbms_allowFormatMigration:- } }
@@ -370,9 +293,13 @@ if [ "${NEO4J_EDITION}" == "enterprise" ];
370293 then
371294 : ${NEO4J_causal__clustering_expected__core__cluster__size:= ${NEO4J_causalClustering_expectedCoreClusterSize:- } }
372295 : ${NEO4J_causal__clustering_initial__discovery__members:= ${NEO4J_causalClustering_initialDiscoveryMembers:- } }
373- : ${NEO4J_causal__clustering_discovery__advertised__address:= ${NEO4J_causalClustering_discoveryAdvertisedAddress:- } }
374- : ${NEO4J_causal__clustering_transaction__advertised__address:= ${NEO4J_causalClustering_transactionAdvertisedAddress:- } }
375- : ${NEO4J_causal__clustering_raft__advertised__address:= ${NEO4J_causalClustering_raftAdvertisedAddress:- } }
296+ : ${NEO4J_causal__clustering_discovery__advertised__address:= ${NEO4J_causalClustering_discoveryAdvertisedAddress:- " $( hostname) :5000" } }
297+ : ${NEO4J_causal__clustering_transaction__advertised__address:= ${NEO4J_causalClustering_transactionAdvertisedAddress:- " $( hostname) :6000" } }
298+ : ${NEO4J_causal__clustering_raft__advertised__address:= ${NEO4J_causalClustering_raftAdvertisedAddress:- " $( hostname) :7000" } }
299+ # Custom settings for dockerized neo4j
300+ : ${NEO4J_causal__clustering_discovery__advertised__address:= $(hostname): 5000}
301+ : ${NEO4J_causal__clustering_transaction__advertised__address:= $(hostname): 6000}
302+ : ${NEO4J_causal__clustering_raft__advertised__address:= $(hostname): 7000}
376303fi
377304
378305# unset old hardcoded unsupported env variables
@@ -388,9 +315,6 @@ unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \
388315 NEO4J_causalClustering_raftListenAddress \
389316 NEO4J_causalClustering_raftAdvertisedAddress
390317
391-
392- # ==== CHECK FILE PERMISSIONS ON MOUNTED FOLDERS ====
393-
394318if [ -d /conf ]; then
395319 if secure_mode_enabled; then
396320 check_mounted_folder_readable " /conf"
@@ -409,7 +333,7 @@ if [ -d /plugins ]; then
409333 if secure_mode_enabled; then
410334 if [[ ! -z " ${NEO4JLABS_PLUGINS:- } " ]]; then
411335 # We need write permissions
412- check_mounted_folder_writable_with_chown " /plugins"
336+ check_mounted_folder_with_chown " /plugins"
413337 fi
414338 check_mounted_folder_readable " /plugins"
415339 fi
@@ -431,41 +355,78 @@ if [ -d /metrics ]; then
431355fi
432356
433357if [ -d /logs ]; then
434- check_mounted_folder_writable_with_chown " /logs"
358+ check_mounted_folder_with_chown " /logs"
435359 : ${NEO4J_dbms_directories_logs:= " /logs" }
436360fi
437361
438362if [ -d /data ]; then
439- check_mounted_folder_writable_with_chown " /data"
363+ check_mounted_folder_with_chown " /data"
440364 if [ -d /data/databases ]; then
441- check_mounted_folder_writable_with_chown " /data/databases"
365+ check_mounted_folder_with_chown " /data/databases"
442366 fi
443367 if [ -d /data/dbms ]; then
444- check_mounted_folder_writable_with_chown " /data/dbms"
368+ check_mounted_folder_with_chown " /data/dbms"
445369 fi
446370fi
447371
448- # ==== SET CONFIGURATIONS ====
449372
450- # # == DOCKER SPECIFIC DEFAULT CONFIGURATIONS ===
451- # # these should not override *any* configurations set by the user
373+ # set the neo4j initial password only if you run the database server
374+ if [ " ${cmd} " == " neo4j" ]; then
375+ if [ " ${NEO4J_AUTH:- } " == " none" ]; then
376+ NEO4J_dbms_security_auth__enabled=false
377+ elif [[ " ${NEO4J_AUTH:- } " == neo4j/* ]]; then
378+ password=" ${NEO4J_AUTH# neo4j/ } "
379+ if [ " ${password} " == " neo4j" ]; then
380+ echo >&2 " Invalid value for password. It cannot be 'neo4j', which is the default."
381+ exit 1
382+ fi
452383
453- add_docker_default_to_conf " dbms.tx_log.rotation.retention_policy" " 100M size" " ${NEO4J_HOME} "
454- add_docker_default_to_conf " dbms.memory.pagecache.size" " 512M" " ${NEO4J_HOME} "
455- add_docker_default_to_conf " dbms.default_listen_address" " 0.0.0.0" " ${NEO4J_HOME} "
456- add_docker_default_to_conf " dbms.connector.https.listen_address" " 0.0.0.0:7473" " ${NEO4J_HOME} "
457- add_docker_default_to_conf " dbms.connector.http.listen_address" " 0.0.0.0:7474" " ${NEO4J_HOME} "
458- add_docker_default_to_conf " dbms.connector.bolt.listen_address" " 0.0.0.0:7687" " ${NEO4J_HOME} "
459- # set enterprise only docker defaults
460- if [ " ${NEO4J_EDITION} " == " enterprise" ];
461- then
462- add_docker_default_to_conf " causal_clustering.discovery_advertised_address" " $( hostname) :5000" " ${NEO4J_HOME} "
463- add_docker_default_to_conf " causal_clustering.transaction_advertised_address" " $( hostname) :6000" " ${NEO4J_HOME} "
464- add_docker_default_to_conf " causal_clustering.raft_advertised_address" " $( hostname) :7000" " ${NEO4J_HOME} "
384+ if running_as_root; then
385+ # running set-initial-password as root will create subfolders to /data as root, causing startup fail when neo4j can't read or write the /data/dbms folder
386+ # creating the folder first will avoid that
387+ mkdir -p /data/dbms
388+ chown " ${userid} " :" ${groupid} " /data/dbms
389+ fi
390+ # Will exit with error if users already exist (and print a message explaining that)
391+ # we probably don't want the message though, since it throws an error message on restarting the container.
392+ neo4j-admin set-initial-password " ${password} " 2> /dev/null || true
393+ elif [ -n " ${NEO4J_AUTH:- } " ]; then
394+ echo >&2 " Invalid value for NEO4J_AUTH: '${NEO4J_AUTH} '"
395+ exit 1
396+ fi
465397fi
466398
467- # # == ENVIRONMENT VARIABLE CONFIGURATIONS ===
468- # # these override BOTH defaults and any existing values in the neo4j.conf file
399+ declare -A COMMUNITY
400+ declare -A ENTERPRISE
401+
402+ COMMUNITY=(
403+ [dbms.tx_log.rotation.retention_policy]=" 100M size"
404+ [dbms.memory.pagecache.size]=" 512M"
405+ [dbms.connectors.default_listen_address]=" 0.0.0.0"
406+ [dbms.connector.https.listen_address]=" 0.0.0.0:7473"
407+ [dbms.connector.http.listen_address]=" 0.0.0.0:7474"
408+ [dbms.connector.bolt.listen_address]=" 0.0.0.0:7687"
409+ )
410+
411+ ENTERPRISE=(
412+ )
413+
414+ for conf in ${! COMMUNITY[@]} ; do
415+ if ! grep -q " ^$conf " " ${NEO4J_HOME} " /conf/neo4j.conf
416+ then
417+ echo -e " \n" $conf =${COMMUNITY[$conf]} >> " ${NEO4J_HOME} " /conf/neo4j.conf
418+ fi
419+ done
420+
421+ for conf in ${! ENTERPRISE[@]} ; do
422+ if [ " ${NEO4J_EDITION} " == " enterprise" ];
423+ then
424+ if ! grep -q " ^$conf " " ${NEO4J_HOME} " /conf/neo4j.conf
425+ then
426+ echo -e " \n" $conf =${ENTERPRISE[$conf]} >> " ${NEO4J_HOME} " /conf/neo4j.conf
427+ fi
428+ fi
429+ done
469430
470431# The udc.source=tarball should be replaced by udc.source=docker in both dbms.jvm.additional and wrapper.java.additional
471432# Using sed to replace only this part will allow the custom configs to be added after, separated by a ,.
@@ -478,38 +439,32 @@ if ! grep -q "dbms.jvm.additional=-Dunsupported.dbms.udc.source=docker" "${NEO4J
478439 sed -i -e ' s/dbms.jvm.additional=/dbms.jvm.additional=-Dunsupported.dbms.udc.source=docker,/g' " ${NEO4J_HOME} " /conf/neo4j.conf
479440fi
480441
481- # save NEO4J_HOME and NEO4J_AUTH to temp variables that don't begin with NEO4J_ so they don't get added to the conf
482- temp_neo4j_home=" ${NEO4J_HOME} "
483- temp_neo4j_auth=" ${NEO4J_AUTH:- } "
484442# list env variables with prefix NEO4J_ and create settings from them
485- unset NEO4J_AUTH NEO4J_SHA256 NEO4J_TARBALL NEO4J_EDITION NEO4J_ACCEPT_LICENSE_AGREEMENT NEO4J_HOME
443+ unset NEO4J_AUTH NEO4J_SHA256 NEO4J_TARBALL
486444for i in $( set | grep ^NEO4J_ | awk -F' =' ' {print $1}' | sort -rn ) ; do
487- setting=$( echo " ${i} " | sed ' s|^NEO4J_||' | sed ' s|_|.|g' | sed ' s|\.\.|_|g' )
488- value=$( echo " ${! i} " )
445+ setting=$( echo ${i} | sed ' s|^NEO4J_||' | sed ' s|_|.|g' | sed ' s|\.\.|_|g' )
446+ value=$( echo ${! i} )
489447 # Don't allow settings with no value or settings that start with a number (neo4j converts settings to env variables and you cannot have an env variable that starts with a number)
490448 if [[ -n ${value} ]]; then
491449 if [[ ! " ${setting} " =~ ^[0-9]+.* $ ]]; then
492- add_env_setting_to_conf " ${setting} " " ${value} " " ${temp_neo4j_home} "
450+ if grep -q -F " ${setting} =" " ${NEO4J_HOME} " /conf/neo4j.conf; then
451+ # Remove any lines containing the setting already
452+ sed --in-place " /^${setting} =.*/d" " ${NEO4J_HOME} " /conf/neo4j.conf
453+ fi
454+ # Then always append setting to file
455+ echo " ${setting} =${value} " >> " ${NEO4J_HOME} " /conf/neo4j.conf
493456 else
494457 echo >&2 " WARNING: ${setting} not written to conf file because settings that start with a number are not permitted"
495458 fi
496459 fi
497460done
498- export NEO4J_HOME=" ${temp_neo4j_home} "
499- unset temp_neo4j_home
500-
501- # ==== SET PASSWORD AND PLUGINS ====
502-
503- set_initial_password " ${temp_neo4j_auth} "
504461
505462
506463if [[ ! -z " ${NEO4JLABS_PLUGINS:- } " ]]; then
507464 # NEO4JLABS_PLUGINS should be a json array of plugins like '["graph-algorithms", "apoc", "streams", "graphql"]'
508465 install_neo4j_labs_plugins
509466fi
510467
511- # ==== INVOKE NEO4J STARTUP ====
512-
513468[ -f " ${EXTENSION_SCRIPT:- } " ] && . ${EXTENSION_SCRIPT}
514469
515470if [ " ${cmd} " == " dump-config" ]; then
@@ -528,4 +483,4 @@ if [ "${cmd}" == "neo4j" ]; then
528483 ${exec_cmd} neo4j console
529484else
530485 ${exec_cmd} " $@ "
531- fi
486+ fi
0 commit comments