generated from ddev/ddev-addon-template
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from rfay/20220529_auto_install
Use supervisord to launch cron daemon
- Loading branch information
Showing
9 changed files
with
53 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,53 @@ | ||
[![tests](https://github.com/drud/ddev-ddev-cron/actions/workflows/tests.yml/badge.svg)](https://github.com/drud/ddev-ddev-cron/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2022.svg) | ||
[![tests](https://github.com/tyler36/ddev-cron/actions/workflows/tests.yml/badge.svg)](https://github.com/tyler36/ddev-cron/actions/workflows/tests.yml) ![project is maintained](https://img.shields.io/maintenance/yes/2022.svg) | ||
|
||
# DDEV-CRON <!-- omit in toc --> | ||
|
||
- [Intro](#intro) | ||
- [Getting started](#getting-started) | ||
- [Implementation](#implementation) | ||
|
||
## Intro | ||
|
||
This extension helps to execute a command based on a schedule. | ||
This DDEV add-on helps to execute a command in the web container based on a cron schedule. Cron is a classic Linux/Unix service with a well-known configuration syntax. | ||
|
||
The add-on | ||
* Installs and runs the cron service inside the web container | ||
* Adds a sample cron configuration that adds to a file every minute. | ||
|
||
**Warning** | ||
If you already have a `.ddev/web-build/Dockerfile` in your project, you'll want to adapt it with | ||
the one provided here, and `ddev get` will override the one you have. | ||
|
||
It does this by a creating a new crontab job at startup and executing it at the specified time. | ||
|
||
This extension is designed to be a generic implentation. See [Running TYPO3 Cron inside the web container](https://github.com/drud/ddev-contrib/tree/master/recipes/cronjob) for a specific example of a manual setup. | ||
|
||
## Getting started | ||
|
||
- Install the service | ||
- Install the add-on | ||
|
||
```shell | ||
ddev get tyler36/cron | ||
``` | ||
|
||
- Update `./.ddev/config.cron.yml` with your requirments. | ||
- Restart DDEV | ||
- Update the provided `./.ddev/config.cron.yaml` as you see fit with your expected cron jobs (and remove the demonstration line). You can also just add the demonstration lines to your `.ddev/config.yaml`. | ||
- `ddev restart` | ||
|
||
```shell | ||
ddev restart | ||
``` | ||
|
||
## Implementation | ||
|
||
The `config.cron.yml` is a simple implentation of cron within the DDEV web container. | ||
|
||
It has 3 main parts: | ||
|
||
- Install the cron package | ||
- Write a crontab file | ||
- Update the permissions and start the cron service. | ||
The provided `web-build/Dockerfile` and `web-build/cron.conf` configure the traditional cron daemon to run inside the web container. | ||
|
||
```yml | ||
# Install required packages | ||
webimage_extra_packages: [cron] | ||
The `config.cron.yaml` is a simple implentation of cron within the DDEV web container. It writes a crontab file to configure the cron daemon. | ||
|
||
```yaml | ||
hooks: | ||
post-start: | ||
# This line creates a job, ddev-cron-time, and configures it to run every minute | ||
# This line creates a cron job, ddev-cron-time, and configures it to run every minute | ||
- exec: echo '*/1 * * * * root date | tee -a /var/www/html/time.log' | sudo tee -a /etc/cron.d/ddev-cron-time | ||
# This line sets permissions ands starts the cron service | ||
- exec: sudo chmod 0600 /etc/cron.d/ddev-cron-time && sudo service cron start | ||
``` | ||
The default file configures a job (`ddev-cron-time`) to write the date to a log file `time.log` every minute. | ||
It is a simple arbitary example to show the service is working, and remind the user to change it to something more appropriate. | ||
It is a simple arbitary example to show the service is working, and remind the user to change it to something more appropriate. You can add additional files into /etc/cron.d, or add additional lines to this one. | ||
|
||
**Contributed and maintained by [@tyler36](https://github.com/tyler36) based on the original [Running TYPO3 Cron inside the web container](https://github.com/drud/ddev-contrib/tree/master/recipes/cronjob) by [@thomaskieslich](https://github.com/thomaskieslich)** | ||
|
||
**Originally Contributed by [@thomaskieslich](https://github.com/thomaskieslich) in <https://github.com/drud/ddev-contrib/tree/master/recipes/cronjob>) | ||
**Originally Contributed by [@thomaskieslich](https://github.com/thomaskieslich) in <https://github.com/drud/ddev-contrib/tree/master/recipes/cronjob>)** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
hooks: | ||
# This will be executed at the whenever DDEV starts | ||
post-start: | ||
# This line creates a job, ddev-cron-time, and configures it to run every minute | ||
# You can just `ls -l time.log` or `tail time.log` to see it happening. | ||
- exec: echo '* * * * * root date | tee -a /var/www/html/time.log' | sudo tee -a /etc/cron.d/ddev-cron-time |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ARG BASE_IMAGE | ||
FROM $BASE_IMAGE | ||
# Install cron package; this can be done in webimage_extra_packages, but put it here for now. | ||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests cron | ||
# Tell supervisord to start cron service in cron.conf | ||
ADD cron.conf /etc/supervisor/conf.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[program:cron] | ||
command=sudo /usr/sbin/cron -f | ||
autorestart=true | ||
startretries=10 |