通过Docker上Supervisor的Cron任务查看NodeJS应用程序日志

所以设置是…

Docker> Supervisor> Cron> NodeJS任务。

目前我正在让我的主pipe将当前pipe理员设置的日志和错误日志输出到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任务,即

 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 index.js应用程序从terminal与nodejs index.js我得到console.log输出,我所期望的。

我知道如何得到我的NodeJS输出,如果我是从主pipe运行它(这将是相同的cron设置上面),但即时触发从cron它是不同的。

现在我怀疑我要去哪里错了是我的日志redirect在我的crontab中…?

我的crontab目前看起来像以下(运行简单的ubuntu:14.04docker形象)…

 * * * * * cd /home/app && nodejs /home/app/index.js >> /var/log/supervisor/supervisord.log 2>&1 

这完美地启动应用程序。

我也可以通过跳转到容器并运行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.logg 2>&1 

然后,我添加了一个部分到我的主pipeconfiguration尾巴日志…

 [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试图写入它。

期待如果这个解决scheme有问题,或者如果有人有更好的…