roots / docs

📝 Documentation for Roots projects
https://roots.io/docs/
168 stars 181 forks source link

💡 Document "provisioning" crons on deploy #482

Open chrillep opened 1 year ago

chrillep commented 1 year ago

Summary

One could argue that crons should be part of the deploy. 😄 How do we accomplish this? It would really help me if this was part of the trellis docs. 🙏🏼

AC: (feel free to change them) ❤️

Docs

Additional context

On most of our servers we dont have root access, so we only use the deploy part of trellis. This is from what i gather a common practice?

It would be simpler (for us 😄 ) if the cron was part of the deploy. It would be simpler (for us 😄 ) if the user owning the crons was the deploy user.

refs

chrillep commented 2 months ago

working yaml if you want || need the crons to be setup as part of the deploy chain.

trellis/deploy-hooks/build-before.yml

- name: Setup WP system cron using crontab
  shell: |
    (crontab -l 2>/dev/null || echo '') | grep -v "{{ item.key }} WordPress cron" | crontab -
    (crontab -l; echo "*/{{ item.value.cron_interval | default('5') }} * * * * cd {{ www_root }}/{{ item.value.current_path | default('current') }} && wp cron event run --due-now > /dev/null 2>&1 # {{ item.key }} WordPress cron") | crontab -
  loop: "{{ wordpress_sites | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  when: not item.value.multisite.enabled

- name: Setup WP Multisite system cron using crontab
  shell: |
    (crontab -l 2>/dev/null || echo '') | grep -v "{{ item.key }} WordPress network cron" | crontab -
    (crontab -l; echo "*/{{ item.value.cron_interval_multisite | default('10') }} * * * * cd {{ www_root }}/{{ item.value.current_path | default('current') }} && (wp site list --field=url | xargs -n1 -I \\% wp --url=\\% cron event run --due-now) > /dev/null 2>&1 # {{ item.key }} WordPress network cron") | crontab -
  loop: "{{ wordpress_sites | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  when: item.value.multisite.enabled
swalkinshaw commented 1 week ago

@chrillep is this something you want to contribute? Even a basic starting page on this would be appreciated. No reason not to document it.

chrillep commented 1 week ago

@chrillep is this something you want to contribute? Even a basic starting page on this would be appreciated. No reason not to document it.

Ive started a new job where we only use laravel so im kinda out of the WP world however this is more of CD/CI so sure :)

I see now that the specific YAML i posted https://github.com/roots/docs/issues/482#issuecomment-2373735826

was specifically created for kinsta since they don't let you edit cron via file, you have to use crontab to get around it. Still works in general but thats the reason for crontab -l bloated command.