forked from rdkls/aws_infra_map_neo4j
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·92 lines (83 loc) · 3 KB
/
docker-entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
set -m
if [ -z "$AWS_DEFAULT_REGION" ] && [ -z "$AWS_TO_NEO4J_LIMIT_REGION" ] ; then
echo 'AWS_DEFAULT_REGION or AWS_TO_NEO4J_LIMIT_REGION must be set'
exit 1
fi
# Be kind and set default region if only limit was specified
if [[ -z "$AWS_DEFAULT_REGION" ]] ; then
export AWS_DEFAULT_REGION=$AWS_TO_NEO4J_LIMIT_REGION
fi
if [[ -z "$NEO4J_AUTH" ]] ; then
echo 'NEO4J_AUTH must be set to user/pass'
exit 1
fi
if [[ -z "$AWS_SECRET_ACCESS_KEY" ]] ; then
echo 'AWS_SECRET_ACCESS_KEY must be set'
exit 1
fi
if [[ -z "$AWS_ACCESS_KEY_ID" ]] ; then
echo 'AWS_ACCESS_KEY_ID must be set'
exit 1
fi
if [[ -z "$AWS_SESSION_TOKEN" ]] ; then
echo 'AWS_SESSION_TOKEN must be set'
exit 1
fi
THE_NEO4J_BASEDIR=/var/lib/neo4j
# Custom settings for dockerized neo4j
: ${NEO4J_dbms_tx__log_rotation_retention__policy:=100M size}
: ${NEO4J_dbms_memory_pagecache_size:=512M}
: ${NEO4J_wrapper_java_additional:=-Dneo4j.ext.udc.source=docker}
: ${NEO4J_dbms_memory_heap_initial__size:=512M}
: ${NEO4J_dbms_memory_heap_max__size:=512M}
: ${NEO4J_dbms_connectors_default__listen__address:=0.0.0.0}
: ${NEO4J_dbms_connector_http_listen__address:=0.0.0.0:7474}
: ${NEO4J_dbms_connector_https_listen__address:=0.0.0.0:7473}
: ${NEO4J_dbms_connector_bolt_listen__address:=0.0.0.0:7687}
# set the neo4j initial password only if you run the database server
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 "Invalid value for password. It cannot be 'neo4j', which is the default."
exit 1
fi
# Will exit with error if users already exist (and print a message explaining that)
$THE_NEO4J_BASEDIR/bin/neo4j-admin set-initial-password "${password}" || true
elif [ -n "${NEO4J_AUTH:-}" ]; then
echo "Invalid value for NEO4J_AUTH: '${NEO4J_AUTH}'"
exit 1
fi
# list env variables with prefix NEO4J_ and create settings from them
#unset NEO4J_AUTH
unset 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})
if [[ -n ${value} ]]; then
if grep -q -F "${setting}=" $THE_NEO4J_BASEDIR/conf/neo4j.conf; then
# Remove any lines containing the setting already
sed --in-place "/${setting}=.*/d" $THE_NEO4J_BASEDIR/conf/neo4j.conf
fi
# Then always append setting to file
echo "${setting}=${value}" >> $THE_NEO4J_BASEDIR/conf/neo4j.conf
fi
done
# Start neo4j with console in background
# so we can load aws data, then later fg it
neo4j console&
# Wait for neo4j to come up
neo4j_not_up=true
while $neo4j_not_up ; do
sleep 1
echo "waiting for neo4j to start ..."
if [[ 0 -eq `nc -z localhost 7474; echo $?` ]] ; then
neo4j_not_up=false
fi
done
# Load aws data
/usr/local/bin/awless_to_neo.py
# fg neo4j console
fg 1