我正在尝试在docker上下文中重新创建this tutorial中的步骤,在OS X上的virtualbox中运行的coreos下安装ubuntu映像。
我已经设置了一个Dockerfile,其中包含以下步骤:
# Install docker basics
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y
# Install supervisor
RUN apt-get install -y supervisor
RUN mkdir -p /var/run/sshd
RUN mkdir -p /var/log/supervisor
RUN mkdir -p /etc/supervisor/conf.d
# tutorial suite
ADD ./etc/long.sh /usr/local/bin/long.sh
RUN /bin/chmod 0777 /usr/local/bin/long.sh
ADD ./etc/long_script.conf /etc/supervisor/conf.d/long_script.conf
# create supervisord user
RUN /usr/sbin/useradd --create-home --home-dir /usr/local/nonroot --shell /bin/bash nonroot
# start supervisord
RUN sudo service supervisor start
将以下文件复制到相对/etc/
目录中:
long.sh
:
#!/bin/bash
while true
do
# Echo current date to stdout
echo `date`
# Echo 'error!' to stderr
echo 'error!' >&2
sleep 1
done
和long_script.conf
:
[program:long_script]
command=/usr/local/bin/long.sh
autostart=true
autorestart=true
stderr_logfile=/var/log/long.err.log
stdout_logfile=/var/log/long.out.log
它正确地加载了所有内容,但是/var/log/long.out.log
或/var/log/long.err.log
中没有相应的输出,尽管这两个文件都存在于该目录中。
当我使用/bin/bash
/加载图片时,我会尝试以下操作:
我可以成功运行service supervisor restart
并获取Restarting supervisor:
作为输出。
但是当我尝试使用supervisorctl
运行任何功能时,我会收到错误,即unix:///var/run/supervisor.sock refused connection
我检查了/var/log/supervisor/supervisord.log
的输出,它给了我:
2014-03-17 08:54:48,090 CRIT Supervisor running as root (no user in config file)
2014-03-17 08:54:48,090 WARN Included extra file "/etc/supervisor/conf.d/long_script.conf" during parsing
2014-03-17 08:54:48,161 INFO RPC interface 'supervisor' initialized
2014-03-17 08:54:48,161 WARN cElementTree not installed, using slower XML parser for XML-RPC
2014-03-17 08:54:48,161 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2014-03-17 08:54:48,163 INFO daemonizing the supervisord process
2014-03-17 08:54:48,164 INFO supervisord started with pid 10
2014-03-17 08:54:49,165 INFO spawned: 'long_script' with pid 13
[error] client.go:2296 Error resize: Error: resize: bad file descriptor
谷歌搜索建议我包含一个明确指向应用程序supervisord.conf
文件的准系统supervisord.sock
文件,因此我将以下内容添加到Dockerfile中:
# Add supervisor config file
ADD ./etc/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
然后添加了一个supervisord.conf
文件,如下所示:
[supervisord]
logfile=/var/log/supervisor/supervisord.log
loglevel=error
nodaemon=false
[supervisorctl]
serverurl = unix:///var/run/supervisord.sock
包含此
long.err.log
填充long.out.log
或/var/log/
。 service supervisor restart
,但现在当我运行supervisorctl
时,我得到的错误更改为unix:///var/run/supervisord.sock no such file
。 我检查了/var/log/supervisor/supervisord.log
的输出,它给了我:
2014-03-17 08:48:29,715 CRIT Supervisor running as root (no user in config file)[error] client.go:2296 Error resize: Error: resize: bad file descriptor
认为这可能是用户权限问题,我尝试将supervisord.conf
文件切换为
[supervisord]
logfile=/var/log/supervisor/supervisord.log
loglevel=error
nodaemon=false
user=nonroot
[supervisorctl]
serverurl = unix:///var/run/supervisord.sock
将以下内容添加到Dockerfile
RUN /usr/sbin/useradd --create-home --home-dir /usr/local/nonroot --shell /bin/bash nonroot
但是在编译时会出现以下错误
Step XX : RUN service supervisor start
---> Running in fdcb12ff3cfa
Traceback (most recent call last):
File "/usr/bin/supervisord", line 9, in <module>
load_entry_point('supervisor==3.0a8', 'console_scripts', 'supervisord')()
File "/usr/lib/pymodules/python2.7/supervisor/supervisord.py", line 371, in main
go(options)
File "/usr/lib/pymodules/python2.7/supervisor/supervisord.py", line 381, in go
d.main()
File "/usr/lib/pymodules/python2.7/supervisor/supervisord.py", line 88, in main
info_messages)
File "/usr/lib/pymodules/python2.7/supervisor/options.py", line 1231, in make_logger
stdout = self.nodaemon,
File "/usr/lib/pymodules/python2.7/supervisor/loggers.py", line 325, in getLogger
handlers.append(RotatingFileHandler(filename,'a',maxbytes,backups))
File "/usr/lib/pymodules/python2.7/supervisor/loggers.py", line 180, in __init__
FileHandler.__init__(self, filename, mode)
File "/usr/lib/pymodules/python2.7/supervisor/loggers.py", line 106, in __init__
self.stream = open(filename, mode)
现在登录/bin/bash/
并在cat
上执行/var/log/supervisor/supervisord.log
会产生:
2014/03/17 08:57:36 build: The command [/bin/sh -c service supervisor start] returned a non-zero code: 1
2014-03-17 08:54:48,090 CRIT Supervisor running as root (no user in config file)
2014-03-17 08:54:48,090 WARN Included extra file "/etc/supervisor/conf.d/long_script.conf" during parsing
2014-03-17 08:54:48,161 INFO RPC interface 'supervisor' initialized
2014-03-17 08:54:48,161 WARN cElementTree not installed, using slower XML parser for XML-RPC
2014-03-17 08:54:48,161 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2014-03-17 08:54:48,163 INFO daemonizing the supervisord process
2014-03-17 08:54:48,164 INFO supervisord started with pid 10
2014-03-17 08:54:49,165 INFO spawned: 'long_script' with pid 13
[error] client.go:2296 Error resize: Error: resize: bad file descriptor
这是什么问题?我只是希望能够通过supervisord
运行这个shell脚本,并在日志文件中观察它的输出。
答案 0 :(得分:3)
您也在开始服务 - 但不要让它继续运行。
RUN sudo service supervisor start
您可能应该直接运行它:
CMD ["/usr/bin/supervisord"]
您可能还需要/需要向该CMD添加一些参数。请参阅:Docker/Supervisord example
答案 1 :(得分:3)
我也有这个问题而sudo
没有帮助。因此,我不是使用unix套接字,而是使用tcp套接字代替:
[inet_http_server]
port=:9001
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=http://localhost:9001
您也可以仅绑定到localhost(127.0.0.1:9001
)并添加可选的用户和密码。
答案 2 :(得分:1)
我知道这是一个过时的问题。但是我发布了,因为你还没有接受答案。使用docker和supervisor时,请确保在前台运行supervisord。你可以通过改变你的supervisord.conf来做到这一点。设置
nodaemon=true