Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WP cron in development needs to use curl -k #353

Closed
erikbelusic opened this issue Sep 13, 2015 · 18 comments
Closed

WP cron in development needs to use curl -k #353

erikbelusic opened this issue Sep 13, 2015 · 18 comments
Labels

Comments

@erikbelusic
Copy link

noticed my WPcrons werent running. bedrock disables them, but my trellis config has

system_cron: true

in the wordpress_sites.yml

i checked the production server, and found that no crons were set up with the following:

MYUSER@MYHOSTNAME:~$ for user in $(cut -f1 -d: /etc/passwd); do sudo crontab -u $user -l; done
no crontab for root
no crontab for daemon
no crontab for bin
no crontab for sys
no crontab for sync
no crontab for games
no crontab for man
no crontab for lp
no crontab for mail
no crontab for news
no crontab for uucp
no crontab for proxy
no crontab for www-data
no crontab for backup
no crontab for list
no crontab for irc
no crontab for gnats
no crontab for nobody
no crontab for libuuid
no crontab for syslog
no crontab for messagebus
no crontab for landscape
no crontab for sshd
no crontab for colord
no crontab for ntp
no crontab for web
no crontab for MYUSER
no crontab for mysql
no crontab for memcache

am i doing something wrong or is this a bug?

@swalkinshaw
Copy link
Member

We use a separate cron file for this. See here.

The path it exists at is something like /etc/cron.d/wordpress-example_com.

I just tested a default Trellis install and this file exists. Running your script says "no crontab" for all users though so I'm not sure that command finds files in cron.d.

Is the cron actually not working? Or you just couldn't find it?

@erikbelusic
Copy link
Author

i do not believe that the cron is working. i have a backup plugin thats supposed to run once a day and it hasn't ran. it could be a plugin issue.

i have found the file in the cron.d folder and it looks to be set up correctly. is there a log for the cron that i can look at to see if its being run successfully or not? or should i write something dumb in a wordpress plugin that sends me an email when the cron runs?

@swalkinshaw
Copy link
Member

Try /var/log/syslog and grep for CRON. But yeah you can always do that test. Or schedule a post to be published.

@louim
Copy link
Contributor

louim commented Sep 15, 2015

Don't forget that the default cron is set to run each 15 minutes. So there may be a delay of up to 15 minutes after the time you set you post to be published before it actually is processed.

@erikbelusic
Copy link
Author

i have found the issue! i am using a self signed certificate and the curl request is failing. is there an appropriate way to add the -k flag to my cron via trellis, rather than editing the cron directly?

@austinpray
Copy link
Contributor

@erikbelusic this looks like it needs to be fixed in the upstream. I'm guessing we need to add -k for all self-signed cert users. I don't think you are the only person to be susceptible to this bug.

edit: or we could add the self-signed cert to the machine's root CAs.

@swalkinshaw swalkinshaw changed the title crontabs don't seem to be provisioned correctly WP cron in development need to use curl -k Sep 15, 2015
@swalkinshaw
Copy link
Member

@erikbelusic great debugging! @austinpray is correct that this needs to be fixed in Trellis. We'll need to check for SSL on development in here

job="curl -s {{ item.value.env.wp_siteurl }}/wp-cron.php"
.

I renamed this issue to reflect the problem.

@austinpray austinpray changed the title WP cron in development need to use curl -k WP cron in development needs to use curl -k Sep 15, 2015
@austinpray austinpray reopened this Sep 15, 2015
@swalkinshaw
Copy link
Member

@austinpray also had a good idea to add the self-signed certificate as a root cert so it's recognized as valid.

@austinpray austinpray added this to the 1.0.0 milestone Sep 15, 2015
@louim
Copy link
Contributor

louim commented Sep 15, 2015

Haven't tried, but can't we call php directly without making an http request?

Something like

*/15 * * * * php /srv/website/current/web/wp/wp-cron.php

@austinpray
Copy link
Contributor

I'd prefer to keep curl. php-cli scripts do not timeout. So if WordPress or a plugin does something horrible you can possibly get stuck with a hung process. Also curl runs the code through fpm.

@erikbelusic
Copy link
Author

Which route do you think you want to go? I have no problem helping out. Especially since u guys did all this awesome work for the community this far =]

@swalkinshaw
Copy link
Member

Looking at this: http://unix.stackexchange.com/questions/90450/adding-a-self-signed-certificate-to-the-trusted-list

@austinpray I'm not even sure that the curl command would support the "trusted" route.

@erikbelusic it would be great if you could test out the two methods in that post. See if curl works after doing the ca-certificates method and also using the curl --cacert /path/to/CA/cert.file https://... method.

@erikbelusic
Copy link
Author

@swalkinshaw @austinpray - my findings thus far...

WORKING: (same command)

curl --insecure https://mysite.com/wp/wp-cron.php

OR

curl -k https://mysite.com/wp/wp-cron.php

ALSO WORKING:

curl --cacert /etc/nginx/ssl/mysite.com_self_signed.pem https://mysite.com/wp/wp-cron.php

NOT WORKING:

cp /etc/nginx/ssl/mysite.com_self_signed.pem /usr/share/ca-certificates

followed by

dpkg-reconfigure ca-certificates

followed by choosing "ask" presents a list of certificates, however the self signed certificate does not appear. i may have did something wrong though... not sure

out of the two above options, the --cacert flag looks like the best option because it explicitly allowing our self signed certificate whereas the other --insecure or -k flag will allow any connection with an untrusted certificate.

we should check for a self signed cert and alter cron command to include the --cacert flag with the path to the self signed cert.

i am not exactly sure how to do this. i know control structures aren't supported in .yml files, but i see you can trigger different tasks conditionally using the when directive within ansible. i could use some guidance here....

@swalkinshaw
Copy link
Member

@erikbelusic this is great. Thanks for testing these out.

I agree that the best solution is the --cacert for curl for the reason you mentioned.

You can actually can use control structures/Jinja in the YML files. It just gets ugly and should ideally be avoided. Example: https://github.com/nickjj/ansible-ferm/blob/v0.1.2/tasks/main.yml#L33-L37

The solution is probably to duplicate the Cron task and modify the when conditional. Maybe register the Generate self-signed certificates task as a variable and check if its defined in the cron task. If its not, then there's no self-signed cert. If it is, then there is and use the --cacert option.

@erikbelusic
Copy link
Author

ill give it a shot and see if i can make it work.

@erikbelusic
Copy link
Author

i am not completely understanding register the Generate self-signed certificates task as a variable and check if its defined in the cron task. where would that be done? in the group_vars or else where?

what i am currently thinking is that in the existing cron task, we can check if ssl: true and key and cert are both undefined and add on the --cacert flag that way, but it does look quite messy.

{% if item.value.ssl is defined and item.value.ssl and item.value.ssl.key is not defined and item.value.ssl.cert is not defined %}
job="curl -s --cacert /etc/nginx/ssl/{{ item.key }}_self_signed.pem {{ item.value.env.wp_siteurl }}/wp-cron.php"
{% else %}
job="curl -s {{ item.value.env.wp_siteurl }}/wp-cron.php"
{% endif %}

currently untested

@swalkinshaw
Copy link
Member

@erikbelusic the registration would be done where the task is done. Just by adding register: <var_name>.

I believe that variable would be available during the cron task. See http://docs.ansible.com/ansible/playbooks_variables.html#registered-variables

I suggested the variable method because as you figured out that conditional is quite messy.

@swalkinshaw swalkinshaw removed this from the 1.0.0 milestone Oct 15, 2015
@retlehs retlehs modified the milestone: 1.0.0 Oct 15, 2015
@swalkinshaw swalkinshaw removed this from the 1.0.0 milestone Oct 15, 2015
swalkinshaw added a commit that referenced this issue Dec 29, 2015
Fix #353 - Allow insecure curl reqs for cron
@swalkinshaw
Copy link
Member

@erikbelusic thanks for reporting and debugging this. Decided to go with the simple -k solution.

primozcigler pushed a commit to proteusthemes/pt-ops that referenced this issue Mar 10, 2016
In development with an https site, the curl command for WP cron will
fail due to the "insecure" self-signed certificate.

Adding the `-k` flag means curl will ignore this and continue on.
primozcigler added a commit to proteusthemes/pt-ops that referenced this issue Mar 10, 2016
* bringing-up-to-date:
  Added cherry-picking notice to future-me.
  Added TODO commit.
  Replace strip_www with optional redirect to www/non-www
  Added TODO commit.
  Fix roots#353 - Allow insecure curl reqs for cron
  Fixes roots#374 - Remove composer vendor/bin from $PATH
  Added 2 TODO commits.
  Fix roots#436 - Let WP handle 404s for PHP files
  Fix roots#297 - Use `php_flag` vs `php_admin_flag`
  Update CHANGELOG
  Add wp-cli command to enable permalinks when none are set
  Use https://api.ipify.org for IP lookup
  Fix bug in Vagrantfile where VMware provider variable was encapsulated as a string
  Add HTTP/2 notes to README
  WP-CLI role improvements
  Fix CHANGELOG entry regarding roots#435
  Add variable for whitelisted IPs
  Switch to mainline Nginx, replaces SPDY with HTTP2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants