Hi everybody! I’m a newbie in server setup, i would like to know what’s the best practise on setting a custom cron job to trellis.
I’m playing with the wordpress-setup role and adding custom cron tasks to “/tasks/main.yml but i’d like to use a bash script to manage the cron job … something like job=”/some/job.sh"
the script should execute a “wp db export” command to backup daily the wordpress db…
Where can i put the bash script on the server? is it safe to put in the bedrock root directory or better in the “web” user home? can’t figure out how to handle in roots workflow also…
Sorry for my english and thanks to roots team for their work
really exciting project
I’d probably add the cron job as part of the deploy.
This means you could use the deploy hooks to run a custom task. Maybe on deploy_after.
Ansible has a cron module so use that and also use Ansible to put that job.sh file on the server. Or use a template so you have access to all the Trellis variables.
If you don’t want to add it as part of deploys, you can just modify wordpress-setup like you said or create a new role.
Then in your /group_vars/*/wordpress_sites.yml file add the following to the site you want to set the custom cron job:
cron:
cmd: "./bin/command-to-run.sh" # the cron tab will set the directory to your site root and then execute this command
hour: "*" # Runs every hour. Change this if you want to run at a specific hour
minute: "0" # run at minute 0 (once per hour)
Re-provision Trellis and you should be good to go!
@swalkinshaw I’m just curious, when I try to add a cron job as part of the deploy (deploy_after) like you suggested, I’m getting a permission denied error: