【发布时间】:2022-08-21 20:37:15
【问题描述】:
我创建了一个自定义 docker 映像,以便启动一个包装脚本来加载初始数据。我第一次启动容器时我有点工作,有时会失败,但我猜有一些缓存或者我没有等待足够的时间让 neo4j 启动。
当我停止容器并重新启动它时,问题就出现了。它下载插件然后似乎挂起并且无法将进程带到前台。
./wrapper.sh: line 57: fg: job has terminated
在/logs/debug.log 中,当我重新启动容器时没有日志。所以很难理解发生了什么。一些权限问题?
这是我的包装文件
#!/bin/bash
# THANK YOU! Special shout-out to @marcellodesales on GitHub
# https://github.com/marcellodesales/neo4j-with-cypher-seed-docker/blob/master/wrapper.sh for such a great example script
# Log the info with the same format as NEO4J outputs
log_info() {
# https://www.howtogeek.com/410442/how-to-display-the-date-and-time-in-the-linux-terminal-and-use-it-in-bash-scripts/
# printf \'%s %s\\n\' \"$(date -u +\"%Y-%m-%d %H:%M:%S:%3N%z\") INFO Wrapper: $1\" # Display UTC time
printf \'%s %s\\n\' \"$(date +\"%Y-%m-%d %H:%M:%S:%3N%z\") INFO Wrapper: $1\" # Display local time (PST/PDT)
return
}
# Adapted from https://github.com/neo4j/docker-neo4j/issues/166#issuecomment-486890785
# Alpine is not supported anymore, so this is newer
# Refactoring: Marcello.deSales+github@gmail.com
# turn on bash\'s job control
# https://stackoverflow.com/questions/11821378/what-does-bashno-job-control-in-this-shell-mean/46829294#46829294
set -m
# Start the primary process and put it in the background
/docker-entrypoint.sh neo4j &
# Wait for Neo4j
log_info \"Checking to see if Neo4j has started at http://${DB_HOST}:${DB_PORT}...\"
wget --quiet --tries=20 --waitretry=10 -O /dev/null http://${DB_HOST}:${DB_PORT}
log_info \"Neo4j has started ????\"
log_info \"Importing data with auth ${NEO4J_AUTH}\"
# Import data
log_info \"Loading and importing Cypher file(s)...\"
for cypherFile in /var/lib/neo4j/import/*.data.cypher; do
[ -f \"$cypherFile\" ] || break
log_info \"Running cypher ${cypherFile}\"
cat ${cypherFile} | bin/cypher-shell -u ${NEO4J_USER} -p ${NEO4J_PASSWORD} --fail-fast --format plain
log_info \"Renaming import file ${cypherFile}\"
mv ${cypherFile} ${cypherFile}.applied
done
log_info \"Finished loading data\"
log_info \"Running startup cypher script...\"
for cypherFile in /var/lib/neo4j/import/*.startup.cypher; do
[ -f \"$cypherFile\" ] || break
log_info \"Running cypher ${cypherFile}\"
cat ${cypherFile} | bin/cypher-shell -u ${NEO4J_USER} -p ${NEO4J_PASSWORD} --fail-fast --format plain
done
log_info \"Finished running startup script\"
# now we bring the primary process back into the foreground
# and leave it there
fg %1
这里是我的 dockerfile
FROM neo4j
ENV NEO4J_USER=neo4j
ENV NEO4J_PASSWORD=s3cr3t
ENV NEO4J_AUTH=${NEO4J_USER}/${NEO4J_PASSWORD}
ENV NEO4JLABS_PLUGINS=\'[\"apoc\", \"graph-data-science\"]\'
ENV NEO4J_HOME=\'/var/lib/neo4j\'
ENV DB_HOST=\'localhost\'
ENV DB_PORT=7474
ENV NEO4J_dbms_logs_debug_level=\'DEBUG\'
ENV NEO4J_dbms_logs_user_stdout__enabled=\'true\'
EXPOSE 7474 7473 7687
COPY initial-data/ /var/lib/neo4j/import/
COPY ./docker-scripts/wrapper.sh wrapper.sh
ENTRYPOINT [\"./wrapper.sh\"]
任何想法如何解决这个问题或至少了解什么是错的?
-
log_info 中的最后一个条目是什么?这些文件(startup.cypher)是干什么用的?
-
最后一项显示“已完成运行启动脚本”,因为即使数据库未启动,wget 也会在重试后运行代码。这些文件是用于导入初始数据的文件,它被重命名,因此它不会在每次容器启动时运行,*startup.cypher 为 gds 库重新创建内存图,因为它是内存中的,一旦集装箱停靠
-
谢谢。那么 ./wrapper.sh: 第 57 行在做什么?请分享第 57 行正在运行的脚本/代码。谢谢。
-
我在问题中分享了脚本,失败的行现在实际上是 53:
fg %1,试图将可能崩溃的进程引入前台