如果默认CMD是shell脚本,则Docker停止退出代码-1

时间:2014-10-06 19:17:17

标签: shell docker supervisor sigterm

我正在使用supervisord在Docker中构建一个tomcat容器。如果Dockerfile中的默认命令是

CMD supervisord -c /etc/supervisord.conf

当我发送docker stop命令时,容器以退出代码0成功退出。

但相反,如果我有

CMD ["/run"] 

并在run.sh中,

supervisord -c /etc/supervisord.conf

docker stop命令给出了退出代码-1。在查看日志时,似乎supervisord没有收到指示退出请求的SIGTERM。

2014-10-06 19:48:54,420 CRIT Supervisor running as root (no user in config file)
2014-10-06 19:48:54,450 INFO RPC interface 'supervisor' initialized
2014-10-06 19:48:54,451 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2014-10-06 19:48:54,451 INFO supervisord started with pid 6
2014-10-06 19:48:55,457 INFO spawned: 'tomcat' with pid 9
2014-10-06 19:48:56,503 INFO success: tomcat entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

与以前的日志相反,它接收sigterm并优雅地退出。

2014-10-06 20:02:59,527 CRIT Supervisor running as root (no user in config file)
2014-10-06 20:02:59,556 INFO RPC interface 'supervisor' initialized
2014-10-06 20:02:59,556 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2014-10-06 20:02:59,557 INFO supervisord started with pid 1
2014-10-06 20:03:00,561 INFO spawned: 'tomcat' with pid 9
2014-10-06 20:03:01,602 INFO success: tomcat entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-10-06 20:05:11,690 WARN received SIGTERM indicating exit request
2014-10-06 20:05:11,690 INFO waiting for tomcat to die
2014-10-06 20:05:12,450 INFO stopped: tomcat (exit status 143)

任何帮助表示感谢。

谢谢, KARTHIK

更新

supervisord.conf文件

[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log

[program:mysql]
command=/usr/bin/pidproxy /var/run/mysqld/mysqld.pid /usr/bin/mysqld_safe --pid-file=/var/run/mysqld/mysqld.pid
stdout_logfile=/tmp/mysql.log
stderr_logfile=/tmp/mysql_err.log

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[unix_http_server]
file=/tmp/supervisor.sock ; path to your socket file

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

1 个答案:

答案 0 :(得分:2)

当您通过run.sh运行该过程时,信号仅发送到该进程。除非你是

  1. 不遗余力地向子进程发送信号,例如:陷阱
  2. 向进程组发送信号。
  3. 在run.sh中执行exec supervisord ...
  4. 儿童过程无法获得信号。