【发布时间】:2022-01-25 17:18:45
【问题描述】:
我有使用 Dobby - RDK 实用程序运行的 OCI 运行时捆绑包(在后台使用 crun)。我已经指定我的自定义 entrypoint.sh 脚本在config.json 启动时运行:
"process": {
"args": [
"sh",
"entrypoint.sh"
],
"cwd": "/",
"env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM=xterm"
],
"terminal": true,
"user": {
"uid": 0,
"gid": 0
}
entrypoint.sh 脚本本身:
#!/bin/sh
while true;
do
sleep 1
lighttpd -v >> lighttpd_version.txt
which lighttpd >> lighttpd_which.txt
lighttpd -f /etc/lighttpd/lighttpd.conf
done
Bundle 结构没问题:
/path_to_bundle
/config.json
/rootfs
...
我的包基于用于 arm 架构的 Alpine 映像(我添加了一些需要的额外工具)。
让我的容器使用DobbyTool start mycontainer /path_to_bundle 命令运行,我使用nsenter -m -u -i -n -p -t $INIT_CONTAINER_PROCESS_PID 来“进入”容器。
虽然脚本本身正在被执行(我通过 ps 跟踪睡眠进程 - 每次使用不同的 pid,which lighttpd >> lighttpd_which.txt 命令也可以正常工作)但是像 lighttpd -f /etc/lighttpd/lighttpd.conf 或 lighttpd -v >> lighttpd_version.txt 这样的命令不会执行。
执行结果:
which lighttpd >> lighttpd_which.txt # shows valid path to command at /usr/sbin/lighttpd
lighttpd -f /etc/lighttpd/lighttpd.conf # neither echoing its result nor getting $! doesn`t work - emptiness
lighttpd -v >> lighttpd_version.txt # doesn`t even create a specified output file
当我在正在运行的容器中手动运行 lighttpd -f /etc/lighttpd/lighttpd.conf 或 entrypoint.sh 脚本时,一切正常 - 服务器已启动并正在运行。
编辑:
我也尝试在容器中运行脚本如下:
sh -x entrypoint.sh 2> debug.txt
它根本不会创建那个 debug.txt 文件。手动打字工作正常...
【问题讨论】:
-
为什么你认为
lighttpd -f没有运行?听起来它正在作为前台进程运行,并阻止脚本的其余部分执行直到它退出/ -
因为ps看不到。此外,我可以看到睡眠过程的 pid 不断变化。最后它默认在后台运行 - 我没有使用 -D 选项:
-D don't go to background (default: go to background) -
顺便说一句,我直接使用了 crun 并通过 lighttpd 发现了这个错误:
server.c.1391) setgid(): Operation not permitted。似乎这可能是一个问题。然而,尽管没有在脚本中执行,但运行lighttpd -v工作正常......
标签: bash