Cron Jobs & Tasks
Cron jobs are scheduled commands that execute automatically inside a service's containers based on defined timing rules.
In Zerops, these jobs are configured in the run
section of zerops.yml
file under the crontab
key.
Parametersβ
commandβ
string, REQUIRED
The shell command to execute at the scheduled time. This can be any valid command.
timingβ
string, REQUIRED
The schedule for when the task should run, specified in standard cron format using five space-separated fields:
- Minute (0β59)
- Hour (0β23)
- Day of the month (1β31)
- Month (1β12)
- Day of the week (0β7; both 0 and 7 represent Sunday)
Examplesβ
"0 5 * * *"
β Runs daily at 5:00 AM."*/10 * * * *"
β Runs every 10 minutes.
allContainersβ
boolean, REQUIRED
Options:
true
β Command runs on all containers.false
β Command runs on only one container.
workingDirβ
string, REQUIRED
Specifies the directory where the command will be executed. If not set, it defaults to /var/www
.
Example Configurationsβ
Hereβs a basic example of how to set up a cron job in your service's zerops.yml
:
This configuration logs the current date to /var/log/cron.log
every hour.
Running on Multiple Containersβ
By default, cron jobs run on a single container, even if multiple containers exist for the service. To execute a command across all containers, you can use the allContainers
parameter:
This example removes temporary files from all containers every day at midnight.
Custom Working Directoryβ
You can also specify a custom working directory for your commands using the workingDir
parameter:
In this case, the command runs every minute in the /var/www/html
directory.
Multiple Cronjobsβ
It is possible to define multiple cron jobs as a YAML object list under the crontab
key.