-
Notifications
You must be signed in to change notification settings - Fork 8
/
init-db.sh
executable file
·62 lines (51 loc) · 1.68 KB
/
init-db.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
#!/bin/bash
# wait for Neo4j Bolt port is open
while ! nc -z $(hostname) 7687; do
sleep 0.1 # wait for 1/10 of the second before check again
done
sleep 10
# Run APOC's warmup.
warmup() {
query="CALL apoc.warmup.run();"
echo "Warmup: Running..."
echo
echo "===================="
echo ${query} | /var/lib/neo4j/bin/cypher-shell -d system
echo "===================="
echo
echo "Warmup: Done."
echo
}
# NOTE: for these tasks neo4j admin credentials are read from environment.
# create guest user
if [ "${GUEST_USERNAME}" != "" ] && [ "${GUEST_PASSWORD}" != "" ] ; then
query="CALL dbms.security.createUser('${GUEST_USERNAME}', '${GUEST_PASSWORD}', false);"
# XXX: this is commented now since 3.4 has a warmup mechanism built-in.
# if you want an older version, feel free to uncomment and use APOC's warmup.
# warmup
#
echo "Guest user: Creating user '${GUEST_USERNAME}'..."
# this may fail if user already exists. alright, fine.
echo "===================="
echo ${query} | /var/lib/neo4j/bin/cypher-shell -d system
status=$?
if [ "$status" -eq 0 ] ; then
echo "Guest user: Created."
else
echo "Guest user: Failed to create. Proceeding..."
fi
echo "===================="
echo
query="CALL dbms.security.addRoleToUser('reader', '${GUEST_USERNAME}');"
echo "Guest user: Adding 'reader' role."
echo "===================="
echo ${query} | /var/lib/neo4j/bin/cypher-shell -d system
status=$?
if [ "$status" -eq 0 ] ; then
echo "Guest user: Role added."
else
echo "Guest user: Failed to add role. Proceeding..."
fi
echo "===================="
echo
fi