docker-whmcs icon indicating copy to clipboard operation
docker-whmcs copied to clipboard

Cron not started

Open wiryonolau opened this issue 4 years ago • 7 comments

Hi on my latest deployment, cron is not started ( no pid ).

I check that there is no longer cron and sshd in the /root/etc/service. Have you remove it on the latest commit ?

wiryonolau avatar Mar 25 '20 23:03 wiryonolau

Hi, I have create a pull request to fix this issue. But in the meantime you could try see if this works for you.

  • Clone my repo: https://github.com/crossworth/docker-whmcs
  • Inside the directory run docker build -t fauzie/docker-whmcs:latest .
  • Run the docker-compose or docker run -it --rm fauzie/docker-whmcs:latest sh to see the filesystem directly.

The services should start: see

crossworth avatar Apr 10 '20 15:04 crossworth

adding additional /etc/service/cron/run with exec "cron -f" should also works. I'll test further.

Last time I test with two container one run whmcs, one run cron using same fauzie/docker-whmcs image. The cron is running but in whmcs always shown automatic job not running. Not sure what cause it.

Currently I move back to single service per container. Will check later.

wiryonolau avatar Apr 11 '20 01:04 wiryonolau

Thank you, is it possible to run command: from docker-compose for this image to make cron run automatically with each docker-compose up -d or docker-compose up -d --force-recreate? I mean, not by building image but simply adding line of code to docker-compose.yml?

yashodhank avatar May 30 '20 08:05 yashodhank

WORKAROUND

OK, I found the way to get cron working even without building image with existing image itself.

Workaround using docker-compose

On Docker Host

touch /edit/this/path/to/your/docker/service_cron_run

cat <<'EOF' >>/edit/this/path/to/your/docker/service_cron_run
#!/bin/sh
exec /usr/sbin/cron -f
EOF

chmod +x /edit/this/path/to/your/docker/whmcs/service_cron_run

Add under volumes: in your docker-compose.yml

volumes:
- /edit/this/path/to/docker/whmcs/service_cron_run:/etc/service/cron/run:Z

Now, if you do docker-compose up -d --force-recreate whmcs you will able get cron gradually running as expected.

To check cron is running

docker exec -it <whmcs-container-id> bash /etc/init.d/cron status

I have also copied and mounting cron file called app so that I can edit it directly on host for various non-standard cron scheduling.

My docker-compose volume look like following:

    volumes:
      - ${USERDIR}/docker/whmcs/service_cron_run:/etc/service/cron/run:Z
      - ${USERDIR}/docker/whmcs/crontab:/etc/cron.d/app:ro
      - ${USERDIR}/docker/whmcs/public_html:/var/www/whmcs
      - ${USERDIR}/docker/whmcs/Private:/var/www/private

yashodhank avatar May 31 '20 14:05 yashodhank

I tried @crossworth solution and initially it didn't work. After some digging I found it's becuase the ubuntu image defaults to 7.4 for php-cli, while this Dockerfile only installs ioncube for 7.3. I solved this by adding the following lines near the end of my setup.sh.

# Set default php-cli version to match $PHP_VERSION
update-alternatives --set php /usr/bin/php$PHP_VERSION

I tried but haven't been able to get @yashodhank solution working, I've tried the same fixes as above so not really sure what's going wrong.


Also mildly related, I added the following line in my Dockerfile to solve the INSECURE_MODE cron notices.

RUN     chmod 600 /etc/cron.d/app

Spunkie avatar Jun 08 '20 18:06 Spunkie

I am a complete newbie to whmcs and php but another workaround option that worked for me: On the HOST system create a cronjob like this: */5 * * * * docker exec whmcs-container php -q /var/www/whmcs/crons/cron.php where whmcs-container is the name of your whmcs docker container and /var/www/whmcs/crons/cron.php is the path to cron from inside the container, not the host. This worked for me and cleared the error in the system health status page.

edrock200 avatar Jun 17 '20 20:06 edrock200

Just to add to my prevous post, this is what my cron jobs look like. The daily has to fire between 11 and 11:59pm for WHMCS to not complain about it not running. The every 5m cron is: */5 * * * * /bin/bash -c "/opt/scripts/whmcscron.sh" and the daily is: 0 23 * * * /bin/bash -c "opt/scripts/whmcscrondaily.sh"

The cronjob which runs every 5 minutes is just a shell script like this (change WHMCS for the name of your container)

`docker exec WHMCS php -q /var/www/whmcs/crons/cron.ph`

The cronjob script for the daily looks like this:

`docker exec WHMCS php -q /var/www/whmcs/crons/cron.php all --force -vvv`

edrock200 avatar Aug 03 '20 13:08 edrock200