【发布时间】:2015-12-07 07:25:36
【问题描述】:
我想由主管执行 python 脚本。
我在 supervisord.conf 中设置了目录选项 我在这样的命令选项中使用了相对路径。
[supervisord]
http_port=/var/tmp/supervisor.sock ; (default is to run a UNIX domain socket server)
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (logging level;default info; others: debug,warn)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
directory=/root ; (default is not to cd during start)
[supervisorctl]
serverurl=unix:///var/tmp/supervisor.sock ; use a unix:// URL for a unix socket
[program:test]
directory=/root/test
command=python ./test.py
autostart=true
在 python 脚本中,我使用了这样的相对路径。
textfile = open('./textfile')
我可以通过python ./test.py 在/root/test 目录上成功执行这个python 脚本。
但是当我启动主管时,我得到了这个错误。
python: can't open file './test.py': [Errno 2] No such file or directory
接下来,我像这样在 supervisor.conf 的命令选项中使用了绝对路径。
[program:test]
directory=/root/test
command=python /root/test/test.py
我得到了这个错误。
Traceback (most recent call last):
File "/root/test/test.py", line 6, in <module>
textfile = open('./textfile')
IOError: [Errno 2] No such file or directory: './textfile'
有没有办法设置脚本执行的目录?
【问题讨论】:
-
您更改
test.py将密码更改为脚本stackoverflow.com/questions/1432924/… 的密码 -
这似乎是解决我的问题的最简单方法,至少现在是这样。谢谢。
标签: python supervisord