Skip to content

Instantly share code, notes, and snippets.

@u8sand
Last active November 15, 2022 21:34
Show Gist options
  • Save u8sand/a20393708861912e4ca0ef89150542fd to your computer and use it in GitHub Desktop.
Save u8sand/a20393708861912e4ca0ef89150542fd to your computer and use it in GitHub Desktop.
A more convenient neo4j container which allows you to import dumps inplace

NEO4J Extended Docker Container

This overrides public neo4j container on dockerhub to make it more convenient to override the operating database at runtime.

To that effect it:

  • uses supervisord configured with supervisorctl support to maintain the neo4j process
  • it defines a script: neo4j-load which can import dumps from network endpoints

Usage

Loading dumps with neo4j-load

docker exec -it container neo4j-load https://some-neo4j.dump

Managing neo4j with supervisord

docker exec -it container supervisorctl status
docker exec -it container supervisorctl restart neo4j

Details

neo4j-load:

  • fetch the dump from the url
  • check it with neo4j-admin load --info
  • get user confirmation (y/n)
  • stop neo4j
  • load dump
  • start neo4j
FROM neo4j:4.4
RUN apt update -y && apt install -y supervisor
ADD supervisord.conf /etc/supervisor/supervisord.conf
ADD neo4j-load.sh /var/lib/neo4j/bin/neo4j-load
RUN chmod +x /var/lib/neo4j/bin/neo4j-load
ENTRYPOINT []
CMD ["supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"]
#!/bin/bash
DB=$1
if [ -z "${DB}" ]; then
echo "Usage: neo4j-load https://your-db"
exit 1
fi
echo "Fetching..."
wget ${DB} -O db.dump
if [[ $? -ne 0 ]]; then
echo "Error fetching from ${DB}"
exit 1
fi
echo "Statistics:"
neo4j-admin load --info --from=db.dump
if [[ $? -ne 0 ]]; then
echo "Error detected reading db dump"
exit 1
fi
while true; do
read -p "Continue? [y/n]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
echo "Loading..."
supervisorctl stop neo4j
neo4j-admin load --force --from=db.dump
supervisorctl start neo4j
[supervisord]
user=root
[unix_http_server]
file=/tmp/supervisor.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock
[program:neo4j]
numprocs=1
startsecs=1
startretries=3
autostart=true
directory=/var/lib/neo4j
command=/startup/docker-entrypoint.sh neo4j
autorestart=true
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
[eventlistener:quit_on_failure]
command=bash -c "printf 'READY\n' && while read line; do kill -SIGQUIT $PPID; done < /dev/stdin"
events=PROCESS_STATE_FATAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment