-
Notifications
You must be signed in to change notification settings - Fork 2
/
neo4j.sh
executable file
·56 lines (43 loc) · 1.38 KB
/
neo4j.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
#!/usr/bin/bash
set -eou pipefail
usage() {
echo "Usage: $0 [start|status] CONFIG [CONTAINER_NAME]"
echo "Examples:"
echo " $0 start neo4j.json neo4j"
echo " $0 status neo4j.json"
exit 1
}
error() {
echo "$@" >&2
exit 1
}
[[ ${1:-} =~ ^(start|status)$ ]] || usage
cmd=$1
config=${2:-}
name=${3:-neo4j}
[[ -f "$config" ]] || error "Missing config file $config"
# Get settings from config file
apiport=$(jq -r '.uri|split(":")[2] // 7687' "$config")
webport=$(jq -r '.url|split(":")[2] // 7474' "$config")
user=$(jq -r .user "$config")
password=$(jq -r .password "$config")
# start new docker container
if [[ $cmd == "start" ]]; then
cwd=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
mkdir -p "$cwd/data"
mkdir -p "$cwd/import"
echo "Starting Neo4j container $name at port $apiport and http://localhost:$webport/"
docker run -d \
--name=$name \
--publish=$webport:7474 --publish=$apiport:7687 \
--env NEO4J_AUTH=none \
--user $(id -u):$(id -g) \
--volume=$cwd/data:/data \
--volume=$cwd/import:/var/lib/neo4j/import \
neo4j
else
bolt=$(jq -r '.uri|sub("^neo4j";"http")|if test(":[0-9]+";"i") then . else (.+":7687") end' "$config")
curl -s "$bolt" || error "No Neo4j API available at $bolt"
echo "Neo4j API seems to be available at $bolt"
# TODO: check docker container?
fi