Welcome Guest, Not a member yet? Register   Sign In
Where to set CI_ENV for CI methods executed via cron?
#11

(04-11-2017, 09:57 PM)Diederik Wrote: Or you could just run wget with a url as a cron.


This answers is useful
Reply
#12

(This post was last modified: 04-13-2017, 11:11 AM by spjonez.)

(04-11-2017, 07:28 AM)sneakyimp Wrote: Thank you for your response!

This does in fact address the problem but is not ideal for two reasons:
1) one must specify the environment every single time one specifies a cron/cli command. My crontab is going to have a dozen commands in it, all of which would need to have this value specified.
2) edits to the index.php file can make upgrading CodeIgniter more difficult because you have to propagate these changes manually merge these changes with any made by the CI core.

Is there not one place we can specify this value that works for both cron jobs and for cli execution?

1) Yes you would need to do that. You have to specify it somewhere unless you change the code I posted to always set a specific CI_ENV when running from CLI which will make testing difficult. If you use a staging server it's CRON jobs need a different environment than production so hard coding it for all command line calls is not ideal.

2) You aren't wrong, but copy and pasting a single if/else block isn't going to make upgrades difficult. The upgrade guide says when you need to replace index.php which happens very infrequently.

(04-11-2017, 09:57 PM)Diederik Wrote: Or you could just run wget with a url as a cron.

You can but then your CRON jobs are web accessible and if someone finds a link to them they can run them over and over again which could cause problems if they are designed to run at specific intervals.
Reply
#13

When you open your .bashrc file, note this comment near the very top of the script:

Quote:# If not running interactively, don't do anything

Crontab jobs are non-interactive, and your .bashrc halts there - that's why you don't get your environment variables.

If you really insist on using CI_ENV for this (there's nothing wrong with changing a line or two in index.php), just put your exports above that comment line.
Reply
#14

(04-13-2017, 01:53 AM)VTCAhmedabad Wrote:
(04-11-2017, 09:57 PM)Diederik Wrote: Or you could just run wget with a url as a cron.


This answers is useful

No, that answer is spreading bad practice.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB