简体   繁体   English

如何配置主管不杀死由 docker 容器中的 cron 启动的作业

[英]How to configure supervisor not to kill jobs started by cron in docker container

I wanted to run cron and run a few script started at a time set in crontab.我想运行 cron 并运行一些在 crontab 中设置的时间启动的脚本。 I've installed cron on my docker container and wanted to add some crontab lines and cron starting in separate script.我已经在我的 docker 容器上安装了 cron,并且想添加一些 crontab 行和 cron 从单独的脚本开始。 Here are fragments of my configuration这是我的配置片段

supervisord.conf supervisord.conf

[program:cron]
command=/stats/run-crontabs.sh

/stats/run-crontabs.sh /stats/run-crontabs.sh

#!/bin/bash

crontab -l | { cat; echo "11 1 * * * /stats/generate-year-rank.sh"; } | crontab -
crontab -l | { cat; echo "12 1 * * * /stats/generate-week-rank.sh"; } | crontab -
cron -f -L 15

and when it is time to run script by cron, I can see only that error in container logs当需要通过 cron 运行脚本时,我只能在容器日志中看到该错误

2022-01-29 01:12:01,920 INFO reaped unknown pid 691343

I wonder how I can run script by cron on docker container.我想知道如何通过 cron 在 docker 容器上运行脚本。 Do I need supervisor?我需要主管吗?

EDIT: As @david-maze suggested I've done it like he commented and run cron as container entrypoint and problem is the same编辑:正如@david-maze 所建议的那样,我已经像他评论的那样完成了它并将 cron 作为容器入口点运行,问题是一样的

Thank you for your help谢谢您的帮助

Ok, I have to post an answer.好的,我必须发布一个答案。 I've realized that scripts working well, but it saved reports in system root directory, not on directories that I wanted.我已经意识到脚本运行良好,但是它将报告保存在系统根目录中,而不是我想要的目录中。

It were because of lack of environment variables More you can read those topic, Where can I set environment variables that crontab will use?这是因为缺少环境变量更多您可以阅读这些主题, 我在哪里可以设置 crontab 将使用的环境变量?

but I've resolved my problem with adding that line at the start of 'run-crontabs.sh' script但我已经解决了在“run-crontabs.sh”脚本开头添加该行的问题

crontab -l | { cat; echo "$(env)"; } | crontab -

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM