sbin/start-stop-daemon 无法启动 python - ubuntu docker 容器

sbin/start-stop-daemon not able to start python - ubuntu docker container

我有一个简单的 python 脚本,我想在 docker 容器

的后台启动守护进程服务
/sbin/start-stop-daemon --start  --user root --make-pidfile --pidfile /var/lock/subsys/my-application.pid --exec 'python /opt/app/uc/monitor/bin/my-application.py'

当我在 shell 中执行此命令时,我得到

/sbin/start-stop-daemon: unable to stat //python /opt/app/uc/monitor/bin/my-application.py (No such file or directory)

然而,当在 shell 中执行以下命令时,它有效

python /opt/app/uc/monitor/bin/my-application.py 

我确定 python 已安装并且所有链接都已设置。

感谢您的帮助

该错误消息暗示 start-stop-daemon 正在寻找要打开的文件(stat 操作是在打开文件之前进行检查)并将您的 'python ... ' 参数视为这是一个文件。

请参阅 this example which confirms this. You may need to read the man page for start-stop-daemon,了解您的 Ubuntu 版本,以检查您的设置的有效命令。

最简单的解决方案可能是创建一个 shell 脚本(比如 /opt/app/uc/monitor/bin/run-my-application.sh),然后将其放入其中:

#!/bin/bash
python /opt/app/uc/monitor/bin/my-application.py

一定要对这个文件做chmod +x。如果找不到 python,请使用 which python 找到 python 的路径并在脚本中使用它。

现在试试:

/sbin/start-stop-daemon --start  --user root --make-pidfile --pidfile /var/lock/subsys/my-application.pid --exec '/opt/app/uc/monitor/bin/run-my-application.sh'