Jobs
Run commands in containers or scripts on servers on a cron schedule, with a log entry for every run.
Scheduled jobs run a command or script on a cron expression. Each run writes a log entry with its output and status.
Job types
| Type | Runs | Input |
|---|---|---|
| Application | Inside an application container | A single command |
| Compose | Inside a Compose service container | A single command |
| Server | On the host of a remote server | A bash script |
| wtree Cloud Server | Inside the wtree Cloud container, not on the host | A bash script |
Application and Compose jobs use Docker exec, equivalent to:
docker exec -it <container_id> <command>wtree Cloud Server jobs have access to the Docker socket, so they can manage containers and images with commands such as docker ps or docker image prune.
Create a job
Open the service and go to Settings › Scheduled jobs. For server jobs, open Scheduled jobs in the sidebar.
Click Add schedule and enter the command or script. For example, nginx -v prints the version inside an nginx container.
Set the schedule as a cron expression and save.
Verify
Open the job's logs after the first run and check the output and status.
Requirements
The target container must be running when the job fires. For Compose jobs, don't change the COMPOSE_PROJECT_NAME environment variable: wtree Cloud uses it to find the project.
Install any tools your server scripts use on the target server beforehand.
Examples
Clean up Docker data
Remove unused Docker data every 15 minutes (*/15 * * * *):
#!/bin/bash
docker system prune --forcePrune unused images
Remove unused images from a wtree Cloud Server job:
#!/bin/bash
docker image prune -afBack up an unsupported database
Back up a database wtree Cloud doesn't support natively:
#!/bin/bash
backup_date=$(date +%Y%m%d_%H%M%S)
backup_file="database_${backup_date}.backup"
container_name=$(docker ps --filter "name=clickhouse" --format "{{.Names}}")
docker exec -it $container_name clickhouse-client --query "BACKUP DATABASE mydb TO '/backups/$backup_file'"
# aws s3 cp /backups/$backup_file s3://your-bucket/backups/Tips
- Run the command by hand before you schedule it.
- Handle errors in scripts so a failed step doesn't go unnoticed.
- Watch resource use: frequent heavy jobs compete with your services.
