While using LAMP, you may wish to schedule events or scripts to run on a regular basis - for example, analysis scripts or scripts that schedule study participants for different studies based on different criteria.
If you are using Portainer to support LAMP, you can use the following method and the swarm-cronjob project to schedule these scripts to run regularly.
1. Create a manager service
To create a manager service, add the following service to a stack (if you do not have a dedicated cron stack, you may wish to create one).It should look something like this:
- Image should be
- Volume should be
- The TZ env variable should be set to your local timezone - this will affect the times your scripts run if you specify an hour for them to run.
Only do this step ONCE, regardless of how many services you plan to create.
2. Create the script service.
Second, create the service that will run your script. It should look similar to this:
ANALYSIS_NAME: "My Analysis"
swarm.cronjob.schedule: "0 3 * * *"
- To install additional modules not included with the standard python3.8 image (for example), you may wish to run pip install commands through a shell script.
- Use swarm.cronjob.schedule to enter your cron string
Do this step for each service you plan to create. After you update the stack, the script should begin running as scheduled. The service above, for instance, will run at daily at 3 AM.