简体   繁体   English

如何在 docker ubuntu 基础上启动 cron?

[英]How do I start cron on docker ubuntu base?

I have installed cron via apt-get install cron我已经通过apt-get install cron

Trying to start cron fails (as expected) because of upstart not running.由于upstart未运行,尝试启动 cron 失败(如预期)。

What is the command line for starting cron properly (ie it will read users' crontabs, will read /etc/crontab/* etc)?正确启动 cron 的命令行是什么(即它会读取用户的 crontab,会读取 /etc/crontab/* 等)?

Please note that I do not want to start the container as a "full" machine, so I don't want to run /sbin/init or upstart .请注意,我不想将容器作为“完整”机器启动,所以我不想运行/sbin/initupstart I manage the processes via supervisord , so what I 'm missing is the command line to add to its configuration file.我通过supervisord管理进程,所以我缺少的是添加到其配置文件的命令行。

You can run cron without daemon mode. 您可以在没有守护程序模式的情况下运行cron。

root@xxxxxx:~# cron -f

I was just trying to test it: 我只是想测试一下:

  • I started /bin/bash in a new container 我在一个新容器中启动了/ bin / bash
  • apt-get install cron nano screen
  • getty tty -a root
  • screen , in screen I created 2 terminals: screen ,在屏幕中,我创建了两个终端:
  • first: cron -f 第一: cron -f
  • second: crontab -e - edit your crontab, save and you can watch that the cron is working ... 第二个: crontab -e编辑您的crontab,保存,然后您就可以看到cron正在工作...

我只是使用普通的cron命令启动cron,它将作为守护程序启动它,而后来我使用tail -f <my logfile>阻止启动脚本的过程。

I use Matomo official container for my analytics for my websites.我使用 Matomo 官方容器对我的网站进行分析。 Most the time with Ubuntu containers I just install cron the most basic way.大多数时间使用 Ubuntu 容器,我只是以最基本的方式安装 cron。

apt update
apt install nano cron -y

And then just run crontab -e and add my cron.然后只需运行crontab -e并添加我的 cron。

For Matomo it would not work.对于 Matomo 来说,这是行不通的。 Then the light bulb moment hit me.然后灯泡瞬间击中了我。 Once I ran一旦我跑了

dpkg-reconfigure tzdata

the cron started working. cron 开始工作。

If you have install cron and it's not working.如果您安装了 cron 并且它不起作用。 Try running dpkg-reconfigure tzdata it may solve the problem.尝试运行dpkg-reconfigure tzdata可能会解决问题。

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

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