在 Docker 上通过 Supervisor 的 Cron 任务查看 Node JS 应用程序日志
View NodeJS Application Logs Via Cron Tasks on Supervisor on Docker
所以设置是...
Docker > 主管 > Cron > NodeJS 任务。
我目前正在让我的主管使用当前主管设置将它的日志和错误日志输出到 docker。
[program:cron]
command=cron -f
startsecs=10
priority=100
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
这显示了 cron 任务 运行ning,即
app_1 | 'Supervisord is running as root and it is searching '
app_1 | 2016-08-26 12:54:30,519 CRIT Supervisor running as root (no user in config file)
app_1 | 2016-08-26 12:54:30,519 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
app_1 | 2016-08-26 12:54:30,536 INFO RPC interface 'supervisor' initialized
app_1 | 2016-08-26 12:54:30,536 CRIT Server 'unix_http_server' running without any HTTP authentication checking
app_1 | 2016-08-26 12:54:30,537 INFO supervisord started with pid 8
app_1 | 2016-08-26 12:54:31,542 INFO spawned: 'cron' with pid 11
app_1 | 2016-08-26 12:54:41,584 INFO success: cron entered RUNNING state, process has stayed up for > than 10 seconds (startsecs)
但是它没有显示我的 NodeJS 应用程序的任何内容。
如果我 运行 我的 NodeJS 应用程序从终端 nodejs index.js
我得到 console.log
输出,如我所料。
我知道如何从主管那里获取我的 NodeJS 输出(这与上面的 cron 设置相同)但是当我从 cron 触发它时它是不同的。
现在我怀疑我哪里出错了,我在我的 crontab 中将我的日志重定向到哪里...?
我的 crontab 目前看起来像下面这样(运行 简单 ubuntu:14.04
docker 图片)...
* * * * * cd /home/app && nodejs /home/app/index.js >> /var/log/supervisor/supervisord.log 2>&1
这会完美启动应用程序。
我也可以通过跳进容器和运行ning cat /var/log/supervisor/supervisord.log
查看日志。它显示了我的应用程序的输出以及我在上面粘贴的 cron 输出。但是它没有出现在 docker-compose logs -f
.
非常感谢帮助!
所以,这可能不是最好的方法,但对我来说很管用,嘿!
首先,在我的 Dockerfile
中,我生成了一个空白日志...
RUN touch /var/log/cron.log
然后我修改了我的crontab文件输出到这里...
* * * * * cd /home/app && nodejs /home/app/index.js >> /var/log/cron.log 2>&1
然后我在主管配置中添加了一个部分来跟踪日志...
[program:cronlogs]
command=tail -f /var/log/cron.log
startsecs=20
priority=200
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
请客,touch
的原因是文件不存在不会出错,因为在 cron 尝试写入之前不存在日志文件。
期待此解决方案是否存在问题或者是否有人有更好的解决方案...
所以设置是...
Docker > 主管 > Cron > NodeJS 任务。
我目前正在让我的主管使用当前主管设置将它的日志和错误日志输出到 docker。
[program:cron]
command=cron -f
startsecs=10
priority=100
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
这显示了 cron 任务 运行ning,即
app_1 | 'Supervisord is running as root and it is searching '
app_1 | 2016-08-26 12:54:30,519 CRIT Supervisor running as root (no user in config file)
app_1 | 2016-08-26 12:54:30,519 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
app_1 | 2016-08-26 12:54:30,536 INFO RPC interface 'supervisor' initialized
app_1 | 2016-08-26 12:54:30,536 CRIT Server 'unix_http_server' running without any HTTP authentication checking
app_1 | 2016-08-26 12:54:30,537 INFO supervisord started with pid 8
app_1 | 2016-08-26 12:54:31,542 INFO spawned: 'cron' with pid 11
app_1 | 2016-08-26 12:54:41,584 INFO success: cron entered RUNNING state, process has stayed up for > than 10 seconds (startsecs)
但是它没有显示我的 NodeJS 应用程序的任何内容。
如果我 运行 我的 NodeJS 应用程序从终端 nodejs index.js
我得到 console.log
输出,如我所料。
我知道如何从主管那里获取我的 NodeJS 输出(这与上面的 cron 设置相同)但是当我从 cron 触发它时它是不同的。
现在我怀疑我哪里出错了,我在我的 crontab 中将我的日志重定向到哪里...?
我的 crontab 目前看起来像下面这样(运行 简单 ubuntu:14.04
docker 图片)...
* * * * * cd /home/app && nodejs /home/app/index.js >> /var/log/supervisor/supervisord.log 2>&1
这会完美启动应用程序。
我也可以通过跳进容器和运行ning cat /var/log/supervisor/supervisord.log
查看日志。它显示了我的应用程序的输出以及我在上面粘贴的 cron 输出。但是它没有出现在 docker-compose logs -f
.
非常感谢帮助!
所以,这可能不是最好的方法,但对我来说很管用,嘿!
首先,在我的 Dockerfile
中,我生成了一个空白日志...
RUN touch /var/log/cron.log
然后我修改了我的crontab文件输出到这里...
* * * * * cd /home/app && nodejs /home/app/index.js >> /var/log/cron.log 2>&1
然后我在主管配置中添加了一个部分来跟踪日志...
[program:cronlogs]
command=tail -f /var/log/cron.log
startsecs=20
priority=200
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
请客,touch
的原因是文件不存在不会出错,因为在 cron 尝试写入之前不存在日志文件。
期待此解决方案是否存在问题或者是否有人有更好的解决方案...