Skip to content

Commit

Permalink
Revert "fixed conf test failure in 4.3+"
Browse files Browse the repository at this point in the history
This reverts commit 98af46a.
  • Loading branch information
jennyowen committed Jun 9, 2021
1 parent 98af46a commit 1ce4aac
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 515 deletions.
2 changes: 1 addition & 1 deletion docker-image-src/3.3/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ if [[ "${cmd}" == *"neo4j"* ]]; then
echo >&2 "
In order to use Neo4j Enterprise Edition you must accept the license agreement.
(c) Neo4j Sweden AB. 2021. All Rights Reserved.
(c) Neo4j Sweden AB. 2019. All Rights Reserved.
Use of this Software without a proper commercial license with Neo4j,
Inc. or its affiliates is prohibited.
Expand Down
2 changes: 1 addition & 1 deletion docker-image-src/3.4/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ if [[ "${cmd}" == *"neo4j"* ]]; then
echo >&2 "
In order to use Neo4j Enterprise Edition you must accept the license agreement.
(c) Neo4j Sweden AB. 2021. All Rights Reserved.
(c) Neo4j Sweden AB. 2019. All Rights Reserved.
Use of this Software without a proper commercial license with Neo4j,
Inc. or its affiliates is prohibited.
Expand Down
203 changes: 79 additions & 124 deletions docker-image-src/3.5/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function check_mounted_folder_readable
fi
}

function check_mounted_folder_writable_with_chown
function check_mounted_folder_with_chown
{
# The /data and /log directory are a bit different because they are very likely to be mounted by the user but not
# necessarily writable.
Expand Down Expand Up @@ -213,79 +213,6 @@ function install_neo4j_labs_plugins
rm "${_old_config}"
}

function add_docker_default_to_conf
{
# docker defaults should NOT overwrite values already in the conf file
local _setting="${1}"
local _value="${2}"
local _neo4j_home="${3}"

if ! grep -q "^${_setting}=" "${_neo4j_home}"/conf/neo4j.conf
then
echo -e "\n"${_setting}=${_value} >> "${_neo4j_home}"/conf/neo4j.conf
fi
}

function add_env_setting_to_conf
{
# settings from environment variables should overwrite values already in the conf
local _setting=${1}
local _value=${2}
local _neo4j_home=${3}

if grep -q -F "${_setting}=" "${_neo4j_home}"/conf/neo4j.conf; then
# Remove any lines containing the setting already
sed --in-place "/^${_setting}=.*/d" "${_neo4j_home}"/conf/neo4j.conf
fi
# Then always append setting to file
echo "${_setting}=${_value}" >> "${_neo4j_home}"/conf/neo4j.conf
}

function set_initial_password
{
local _neo4j_auth="${1}"

# set the neo4j initial password only if you run the database server
if [ "${cmd}" == "neo4j" ]; then
if [ "${_neo4j_auth:-}" == "none" ]; then
add_env_setting_to_conf "dbms.security.auth_enabled" "false" "${NEO4J_HOME}"
# NEO4J_dbms_security_auth__enabled=false
elif [[ "${_neo4j_auth:-}" =~ ^([^/]+)\/([^/]+)/?([tT][rR][uU][eE])?$ ]]; then
admin_user="${BASH_REMATCH[1]}"
password="${BASH_REMATCH[2]}"
do_reset="${BASH_REMATCH[3]}"

if [ "${password}" == "neo4j" ]; then
echo >&2 "Invalid value for password. It cannot be 'neo4j', which is the default."
exit 1
fi
if [ "${admin_user}" != "neo4j" ]; then
echo >&2 "Invalid admin username, it must be neo4j"
exit 1
fi

if running_as_root; then
# 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
# creating the folder first will avoid that
mkdir -p /data/dbms
chown "${userid}":"${groupid}" /data/dbms
fi

# Will exit with error if users already exist (and print a message explaining that)
# we probably don't want the message though, since it throws an error message on restarting the container.
if [ "${do_reset}" == "true" ]; then
neo4j-admin set-initial-password "${password}" --require-password-change 2>/dev/null || true
else
neo4j-admin set-initial-password "${password}" 2>/dev/null || true
fi
elif [ -n "${_neo4j_auth:-}" ]; then
echo "$_neo4j_auth is invalid"
echo >&2 "Invalid value for NEO4J_AUTH: '${_neo4j_auth}'"
exit 1
fi
fi
}

# If we're running as root, then run as the neo4j user. Otherwise
# docker is running with --user and we simply use that user. Note
# that su-exec, despite its name, does not replicate the functionality
Expand Down Expand Up @@ -319,15 +246,13 @@ if running_as_root; then
fi

# Only prompt for license agreement if command contains "neo4j" in it
# ==== CHECK LICENSE AGREEMENT ====

if [[ "${cmd}" == *"neo4j"* ]]; then
if [ "${NEO4J_EDITION}" == "enterprise" ]; then
if [ "${NEO4J_ACCEPT_LICENSE_AGREEMENT:=no}" != "yes" ]; then
echo >&2 "
In order to use Neo4j Enterprise Edition you must accept the license agreement.
(c) Neo4j Sweden AB. 2021. All Rights Reserved.
(c) Neo4j Sweden AB. 2019. All Rights Reserved.
Use of this Software without a proper commercial license with Neo4j,
Inc. or its affiliates is prohibited.
Expand All @@ -349,8 +274,6 @@ To do this you can use the following docker argument:
fi

# Env variable naming convention:
# ==== RENAME LEGACY ENVIRONMENT CONF VARIABLES ====

# - prefix NEO4J_
# - double underscore char '__' instead of single underscore '_' char in the setting name
# - underscore char '_' instead of dot '.' char in the setting name
Expand All @@ -360,7 +283,7 @@ fi

# Backward compatibility - map old hardcoded env variables into new naming convention (if they aren't set already)
# Set some to default values if unset
: ${NEO4J_dbms_tx__log_rotation_retention__policy:=${NEO4J_dbms_txLog_rotation_retentionPolicy:-}}
: ${NEO4J_dbms_tx__log_rotation_retention__policy:=${NEO4J_dbms_txLog_rotation_retentionPolicy:-"100M size"}}
: ${NEO4J_wrapper_java_additional:=${NEO4J_UDC_SOURCE:-"-Dneo4j.ext.udc.source=docker"}}
: ${NEO4J_dbms_unmanaged__extension__classes:=${NEO4J_dbms_unmanagedExtensionClasses:-}}
: ${NEO4J_dbms_allow__format__migration:=${NEO4J_dbms_allowFormatMigration:-}}
Expand All @@ -370,9 +293,13 @@ if [ "${NEO4J_EDITION}" == "enterprise" ];
then
: ${NEO4J_causal__clustering_expected__core__cluster__size:=${NEO4J_causalClustering_expectedCoreClusterSize:-}}
: ${NEO4J_causal__clustering_initial__discovery__members:=${NEO4J_causalClustering_initialDiscoveryMembers:-}}
: ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-}}
: ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-}}
: ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-}}
: ${NEO4J_causal__clustering_discovery__advertised__address:=${NEO4J_causalClustering_discoveryAdvertisedAddress:-"$(hostname):5000"}}
: ${NEO4J_causal__clustering_transaction__advertised__address:=${NEO4J_causalClustering_transactionAdvertisedAddress:-"$(hostname):6000"}}
: ${NEO4J_causal__clustering_raft__advertised__address:=${NEO4J_causalClustering_raftAdvertisedAddress:-"$(hostname):7000"}}
# Custom settings for dockerized neo4j
: ${NEO4J_causal__clustering_discovery__advertised__address:=$(hostname):5000}
: ${NEO4J_causal__clustering_transaction__advertised__address:=$(hostname):6000}
: ${NEO4J_causal__clustering_raft__advertised__address:=$(hostname):7000}
fi

# unset old hardcoded unsupported env variables
Expand All @@ -388,9 +315,6 @@ unset NEO4J_dbms_txLog_rotation_retentionPolicy NEO4J_UDC_SOURCE \
NEO4J_causalClustering_raftListenAddress \
NEO4J_causalClustering_raftAdvertisedAddress


# ==== CHECK FILE PERMISSIONS ON MOUNTED FOLDERS ====

if [ -d /conf ]; then
if secure_mode_enabled; then
check_mounted_folder_readable "/conf"
Expand All @@ -409,7 +333,7 @@ if [ -d /plugins ]; then
if secure_mode_enabled; then
if [[ ! -z "${NEO4JLABS_PLUGINS:-}" ]]; then
# We need write permissions
check_mounted_folder_writable_with_chown "/plugins"
check_mounted_folder_with_chown "/plugins"
fi
check_mounted_folder_readable "/plugins"
fi
Expand All @@ -431,41 +355,78 @@ if [ -d /metrics ]; then
fi

if [ -d /logs ]; then
check_mounted_folder_writable_with_chown "/logs"
check_mounted_folder_with_chown "/logs"
: ${NEO4J_dbms_directories_logs:="/logs"}
fi

if [ -d /data ]; then
check_mounted_folder_writable_with_chown "/data"
check_mounted_folder_with_chown "/data"
if [ -d /data/databases ]; then
check_mounted_folder_writable_with_chown "/data/databases"
check_mounted_folder_with_chown "/data/databases"
fi
if [ -d /data/dbms ]; then
check_mounted_folder_writable_with_chown "/data/dbms"
check_mounted_folder_with_chown "/data/dbms"
fi
fi

# ==== SET CONFIGURATIONS ====

## == DOCKER SPECIFIC DEFAULT CONFIGURATIONS ===
## these should not override *any* configurations set by the user
# set the neo4j initial password only if you run the database server
if [ "${cmd}" == "neo4j" ]; then
if [ "${NEO4J_AUTH:-}" == "none" ]; then
NEO4J_dbms_security_auth__enabled=false
elif [[ "${NEO4J_AUTH:-}" == neo4j/* ]]; then
password="${NEO4J_AUTH#neo4j/}"
if [ "${password}" == "neo4j" ]; then
echo >&2 "Invalid value for password. It cannot be 'neo4j', which is the default."
exit 1
fi

add_docker_default_to_conf "dbms.tx_log.rotation.retention_policy" "100M size" "${NEO4J_HOME}"
add_docker_default_to_conf "dbms.memory.pagecache.size" "512M" "${NEO4J_HOME}"
add_docker_default_to_conf "dbms.default_listen_address" "0.0.0.0" "${NEO4J_HOME}"
add_docker_default_to_conf "dbms.connector.https.listen_address" "0.0.0.0:7473" "${NEO4J_HOME}"
add_docker_default_to_conf "dbms.connector.http.listen_address" "0.0.0.0:7474" "${NEO4J_HOME}"
add_docker_default_to_conf "dbms.connector.bolt.listen_address" "0.0.0.0:7687" "${NEO4J_HOME}"
# set enterprise only docker defaults
if [ "${NEO4J_EDITION}" == "enterprise" ];
then
add_docker_default_to_conf "causal_clustering.discovery_advertised_address" "$(hostname):5000" "${NEO4J_HOME}"
add_docker_default_to_conf "causal_clustering.transaction_advertised_address" "$(hostname):6000" "${NEO4J_HOME}"
add_docker_default_to_conf "causal_clustering.raft_advertised_address" "$(hostname):7000" "${NEO4J_HOME}"
if running_as_root; then
# 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
# creating the folder first will avoid that
mkdir -p /data/dbms
chown "${userid}":"${groupid}" /data/dbms
fi
# Will exit with error if users already exist (and print a message explaining that)
# we probably don't want the message though, since it throws an error message on restarting the container.
neo4j-admin set-initial-password "${password}" 2>/dev/null || true
elif [ -n "${NEO4J_AUTH:-}" ]; then
echo >&2 "Invalid value for NEO4J_AUTH: '${NEO4J_AUTH}'"
exit 1
fi
fi

## == ENVIRONMENT VARIABLE CONFIGURATIONS ===
## these override BOTH defaults and any existing values in the neo4j.conf file
declare -A COMMUNITY
declare -A ENTERPRISE

COMMUNITY=(
[dbms.tx_log.rotation.retention_policy]="100M size"
[dbms.memory.pagecache.size]="512M"
[dbms.connectors.default_listen_address]="0.0.0.0"
[dbms.connector.https.listen_address]="0.0.0.0:7473"
[dbms.connector.http.listen_address]="0.0.0.0:7474"
[dbms.connector.bolt.listen_address]="0.0.0.0:7687"
)

ENTERPRISE=(
)

for conf in ${!COMMUNITY[@]} ; do
if ! grep -q "^$conf" "${NEO4J_HOME}"/conf/neo4j.conf
then
echo -e "\n"$conf=${COMMUNITY[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf
fi
done

for conf in ${!ENTERPRISE[@]} ; do
if [ "${NEO4J_EDITION}" == "enterprise" ];
then
if ! grep -q "^$conf" "${NEO4J_HOME}"/conf/neo4j.conf
then
echo -e "\n"$conf=${ENTERPRISE[$conf]} >> "${NEO4J_HOME}"/conf/neo4j.conf
fi
fi
done

#The udc.source=tarball should be replaced by udc.source=docker in both dbms.jvm.additional and wrapper.java.additional
#Using sed to replace only this part will allow the custom configs to be added after, separated by a ,.
Expand All @@ -478,38 +439,32 @@ if ! grep -q "dbms.jvm.additional=-Dunsupported.dbms.udc.source=docker" "${NEO4J
sed -i -e 's/dbms.jvm.additional=/dbms.jvm.additional=-Dunsupported.dbms.udc.source=docker,/g' "${NEO4J_HOME}"/conf/neo4j.conf
fi

# save NEO4J_HOME and NEO4J_AUTH to temp variables that don't begin with NEO4J_ so they don't get added to the conf
temp_neo4j_home="${NEO4J_HOME}"
temp_neo4j_auth="${NEO4J_AUTH:-}"
# list env variables with prefix NEO4J_ and create settings from them
unset NEO4J_AUTH NEO4J_SHA256 NEO4J_TARBALL NEO4J_EDITION NEO4J_ACCEPT_LICENSE_AGREEMENT NEO4J_HOME
unset NEO4J_AUTH NEO4J_SHA256 NEO4J_TARBALL
for i in $( set | grep ^NEO4J_ | awk -F'=' '{print $1}' | sort -rn ); do
setting=$(echo "${i}" | sed 's|^NEO4J_||' | sed 's|_|.|g' | sed 's|\.\.|_|g')
value=$(echo "${!i}")
setting=$(echo ${i} | sed 's|^NEO4J_||' | sed 's|_|.|g' | sed 's|\.\.|_|g')
value=$(echo ${!i})
# 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)
if [[ -n ${value} ]]; then
if [[ ! "${setting}" =~ ^[0-9]+.*$ ]]; then
add_env_setting_to_conf "${setting}" "${value}" "${temp_neo4j_home}"
if grep -q -F "${setting}=" "${NEO4J_HOME}"/conf/neo4j.conf; then
# Remove any lines containing the setting already
sed --in-place "/^${setting}=.*/d" "${NEO4J_HOME}"/conf/neo4j.conf
fi
# Then always append setting to file
echo "${setting}=${value}" >> "${NEO4J_HOME}"/conf/neo4j.conf
else
echo >&2 "WARNING: ${setting} not written to conf file because settings that start with a number are not permitted"
fi
fi
done
export NEO4J_HOME="${temp_neo4j_home}"
unset temp_neo4j_home

# ==== SET PASSWORD AND PLUGINS ====

set_initial_password "${temp_neo4j_auth}"


if [[ ! -z "${NEO4JLABS_PLUGINS:-}" ]]; then
# NEO4JLABS_PLUGINS should be a json array of plugins like '["graph-algorithms", "apoc", "streams", "graphql"]'
install_neo4j_labs_plugins
fi

# ==== INVOKE NEO4J STARTUP ====

[ -f "${EXTENSION_SCRIPT:-}" ] && . ${EXTENSION_SCRIPT}

if [ "${cmd}" == "dump-config" ]; then
Expand All @@ -528,4 +483,4 @@ if [ "${cmd}" == "neo4j" ]; then
${exec_cmd} neo4j console
else
${exec_cmd} "$@"
fi
fi
Loading

0 comments on commit 1ce4aac

Please sign in to comment.