1

I wanted to run cron and run a few script started at a time set in crontab. I've installed cron on my docker container and wanted to add some crontab lines and cron starting in separate script. Here are fragments of my configuration

supervisord.conf

[program:cron]
command=/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

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

I wonder how I can run script by cron on docker container. 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

Thank you for your help

konradm
  • 73
  • 1
  • 12
  • 2
    I would remove the supervisor entirely. Run the cron daemon as a foreground process as the main container process; don't even install supervisord in your Dockerfile. – David Maze Feb 01 '22 at 23:29
  • But I need supervisor to run other processes in container – konradm Feb 02 '22 at 10:58
  • 1
    Focus on the cron process itself: could you run cron, on its own, without supervisord, in a separate single-process container? If the script you show is reading from the database and writing statistics back into the database, is there anything that would force it to be in the same container? – David Maze Feb 02 '22 at 14:06
  • Yes, I wanted to close all logic in one container, because of our project requirements. I know, that it would be better to have database and scripts which read and write data to it in separate containers, but I have to stick to requirements. So that is why I need supervisor and I wanted to also cron working as a third process on that container. – konradm Feb 02 '22 at 18:00
  • I've run it like you suggested and problem is the same. Even this log wasn't show – konradm Feb 05 '22 at 01:00

1 Answers1

-1

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?

but I've resolved my problem with adding that line at the start of 'run-crontabs.sh' script

crontab -l | { cat; echo "$(env)"; } | crontab -
konradm
  • 73
  • 1
  • 12
  • Actually ... no you didn't "have to" post an answer. You could have just deleted the question. Think about it this way - your real problem wasn't the supervisor killing jobs. So other people who genuinely do have that problem are liable to encounter your Q&A (via a google search for example) only to discover that your solution is completely inapplicable to them ... because it is a solution to a different problem. – Stephen C Feb 05 '22 at 02:59