General help

 
 
Picture of Jason De Donno
Setting up crontab
 

Hi

Using Ubuntu. I did the following in the command line interface:

php /opt/bitnami/apps/moodle/htdocs/admin/cli/cron.php

but it said I didn't have permission for that and I guess that's because php is owned by "root root" and I am "bitnami"

So I did:

sudo php /opt/bitnami/apps/moodle/htdocs/admin/cli/cron.php

And this worked.

Question is, when I set up crontab, what do I user as the user?

 

 

 
Average of ratings: -
Picture of Ken Task
Re: Setting up crontab
Group Particularly helpful Moodlers

If the php application is located in a directory accessible by all users on the system (/usr/local/bin/ is one of those locations), then anyone logged onto the system can run a php command.

Thought that when running sudo on Ubuntu, one has to give the 'root' password.

To see how the cron.php file is tagged (owner/group), from a terminal window type:

ls -l /opt/bitnami/apps/moodle/htdocs/admin/cli/cron.php

run as that user.  Think you've answered your own question, however, as your 'test' from the command line could be executed by one user.

A question concerning Bitnami on Ubuntu:  IF/when there is a security update to PHP, MySQL, or Apache, does Bitnami provide that?  How difficult is it to update any of those using Bitnami?  Reason asking, Ubuntu comes ready to install and maintain updates to PHP, MySQL, Apache.  Since nothing is install it once and forget it am wondering if it's more difficult to update the bitnami package or learn how to use 'standard' Ubuntu package manager.

Realize Bitnami is pretty slick in that it installs all that is needed to get Moodle up and running, but that's really tip of the iceburg ... maintaining and updates then come into play.

My 2 cents, of course.

'spirit of sharing', Ken

 
Average of ratings:Useful (1)
Picture of Jason De Donno
Re: Setting up crontab
 

Hi

Thanks for the help again, Ken.

That's a good question you asked concerning updates. All I have got from Bitnami is an Ubuntu image with Moodle installed on it. presumably you can do the updates as on any other Ubuntu machine? I'll ask about updates over at the Bitnami forums, and let you know.

Installing Bitnami was not problem free. It has its own config.php file that you need to change, but when you reboot the server it tries to change it back, so any time you reboot you have re-do the config file. If Bitnami setup is changing application settings at bootime, one wonders what else it's doing. It makes me uncomfortable.

I would have gone for a normal lamp stack, and did originally, but when I ran the Moodle test I had so many errors that I just gave up. Actually it wasn't that bad - just failed to create a UTF database and then there a many extensions not turned on. I'll have another go at it may be in the future, just for fun.

 
Average of ratings: -
Picture of Jason De Donno
Re: Setting up crontab
 

I just updtaed Ubuntu manually and there seemed to be no problem. I used the command:

sudo aptitude safe -upgrade

 
Average of ratings: -
Picture of Ken Task
Re: Setting up crontab
Group Particularly helpful Moodlers

As am I unfamiliar with EC2 let alone Bitnami on EC2, guess you've many discoveries to sort out.  If Moodle docs lacks explanations/clarity, maybe you could take the time to assist in correcting/clarifying so that others who follow won't have issues.

'spirit of sharing', Ken

 
Average of ratings: -
Picture of Jason De Donno
Re: Setting up crontab
 

I'll certainly do that once I'm convinced that my installation is sound, but that involves testing many things.

The Moodle 2.2.2 Bitnami stack seems to be working fine so far, although I have had some problems with the theme selector, and I'm not getting any blocks to appear on the Front Page pre-log on, despite asking nicely ! 

 

 
Average of ratings: -
Picture of Michael Schultz
Re: Setting up crontab
 

Hi Jason,


I'm trying to setup the cron on EC2 Bitnami install as well. Were you ever able to determine the proper procedure for this?


Thank you.

 
Average of ratings: -
Gmads
Re: Setting up crontab
Group Particularly helpful MoodlersGroup Testers

Hi Michael,

Doesn't it work if you edit the crontab:

$ sudo crontab -e

 

Add the following line:

*/15 * * * *  su daemon -c '/opt/bitnami/php/bin/php /opt/bitnami/apps/moodle/htdocs/admin/cli/cron.php >/dev/null

And save the file?

The string "/15" means that cron will run every 15 minutes. You need to check the correct path to "php". The string ">/dev/null" means that the output from the cron job will be discarded.

 
Average of ratings: -
Picture of Michael Schultz
Re: Setting up crontab
 

Hi Guillermo, it actually doesn't work when editing the crontab. I've been discussing it at the Bitnami forums for a few days: http://answers.bitnami.org/questions/4955/running-cron-in-moodle-stack

It appears that the "/opt/bitnami/php/bin/php" directory doesn't exist. I haven't modified the directory structure at all. Unfortunately this is for a large instance and I need to be sure the cron job is running regularly. Right now I'm running it as a task from a separate Windows machine.

 
Average of ratings: -
Gmads
Re: Setting up crontab
Group Particularly helpful MoodlersGroup Testers

Hi Michael,

I saw the post, though they don't get much into the actual location of PHP. Anyway, did you actually check the "/opt..." path? If Moodle is running, then PHP must be somewhere:

find /opt -name php

It could also be related to an owner permission problem.

 
Average of ratings: -
Picture of Michael Schultz
Re: Setting up crontab
 

Hi Guillermo,

I was able to get cron running finally using the following: "*/2 * * * * sudo php /opt/bitnami/apps/moodle/htdocs/admin/cli/cron.php >/dev/null"

PHP is actually located here: /usr/bin/php, but I left the directory structure out of the final line. It's not the best line I've ever written, but it appears to be working. I'm surprised no one has ever encountered this issue, but I hope that by resolving this it will help anyone else looking to build this same type of configuration.

It may indeed be a permissions issue. I tried writing the line above using "su daemon", "su bitnami" and "su apache" as well, but the log.txt file said "user is unavailable."

Let me know your thoughts!

 
Average of ratings:Useful (1)
Picture of Visvanath Ratnaweera
Re: Setting up crontab
Group Particularly helpful Moodlers
Hi Michael

There are two issues here:

1. Whether the PHP cli interpreter is in the $PATH of the owner of the process triggered by cron.

The Moodle docs advice not to take any risks by calling php with absolute path
http://docs.moodle.org/en/Cron_with_Unix_or_Linux#Method_1:_The_command_line_.28cli.29_cron.

2. Whether the owner of the process triggered by the cron has all the permissions required (and no more).

Depending on your distribution (su based or sudo based) many solutions are possible. The usual advice in the moodle.org forums is to run the owner of the PHP cli process the same as the apache process http://docs.moodle.org/en/Cron_with_Unix_or_Linux#Using_the_crontab_program_on_Unix.2FLinux.
 
Average of ratings:Useful (1)
Picture of Michael Schultz
Re: Setting up crontab
 

Hi Visvanath,
I appreciate the input and ideally I'd like to run the cron job as recommended by the Moodle community. However; all of the recommended settings failed to execute the task with the Bitnami Moodle installer. Given my timeframe I needed to get cron working and it worked, though I'd like to use the most accurate settings.

Ultimately it's going to be up to the Bitnami community to identify just who the correct owner is and what the correct path to PHP is to run the cron job.

As you can see from the link in the thread above to the Bitnami forums I've had a lot of paths and owners recommended, unfortunately none of them worked.

Thank you.

 
Average of ratings: -
Picture of Visvanath Ratnaweera
Re: Setting up crontab
Group Particularly helpful Moodlers
Hi Michael

Trial and error methods are tedious, specially if you have to wait for cron. Try this.

If bitnami is sudo based, do this
$ sudo -i
[sudo] password for nonprivuser:
#

otherwise become root the usual way, either logging on straight as root or by
$ su -
Password:
#

After becoming root run
# ps uax | grep apache
root 1276 0.0 0.2 273960 14244 ? Ss Jul03 1:03 /usr/sbin/apache2 -k start
www-data 18200 0.2 1.1 305712 71344 ? S 16:39 0:17 /usr/sbin/apache2 -k start
....

You'll see one apache2 process owned by root and many other processes owned by somebody else, www-data in my case. Now become that user:

# su - that-somebody
$

Now try to run the cron.php in the command line:
$ /path/to/php /path/to/moodle/admin/cli/cron.php

I expect successful execution. Then you know whose crontab should execute cron.php. Othewise you have to dig further.

P.S. This is yet another case of a heavily packaged system, where you spend tons of time to get a small additional task done. If you do a vanilla installation like this http://docs.moodle.org/en/Installing_Moodle_on_Debian_based_distributions, you know what you did and as a result you simple after installation tasks remain simple. That is my personal opinion.
 
Average of ratings: -
Picture of Michael Schultz
Re: Setting up crontab
 

Hi Visvanath,
Pardon the delay in my reply. Since cron was working I had to set this problem aside and focus on some coursework projects we're working on. There seems to be quite a bit of interest in this issue, so I'm going to try your solution this weekend when traffic is lower on the LMS. I'll share the results as soon as I have them. Thanks for your help.

 
Average of ratings: -
Picture of Michael Schultz
Re: Setting up crontab
 

Hi Visvanath,

I executed your commands and as you indicated there is one process owned by root, and the user for the others is actually "apache"

When attempting to su - apache the response is "This account is currently not available"

As I recall I came across the fact that apache was the user when I was trying my original trial-and-error cron setup.

If I can't become apache what might my options be? I also still don't know the path to PHP. My cron is running with just "PHP" as the path. Let me know your thoughts.

 
Average of ratings: -
Picture of Visvanath Ratnaweera
Re: Setting up crontab
Group Particularly helpful Moodlers
Hi Michael

You wrote:
> there is one process owned by root, and the user for the others is actually "apache"

The question of the owner of the Apache process is answered: It is the user called "apache".

> When attempting to su - apache the response is "This account is currently not available"

That is possible, depending on how that user is configured. See /etc/passwd and /etc/shadow for details.

The question is, why do you want to be "apache"? To give him the ownership of a directory tree? That won't work for a second reason: A user cannot grab ownership, the super user has to give the ownership. See the chown command.

> I came across the fact that apache was the user when I was trying my original trial-and-error cron setup.

I repeat, you can not trail and error in Unix, that is the Windows world.
;-(

> If I can't become apache what might my options be?

See "chown" above.

> I also still don't know the path to PHP. My cron is running with just "PHP" as the path.

If cron is happy with just php, then it is in that users $PATH. If you want to get the full path explicitly try "which".

I'm sorry, that I can not give cut-and-paste solutions. You are trying to adapt Debian instrucitons to EC2, which looks like RedHat. That is doable and a stimulating exercise, but you need an understanding of the few Unix commands we have been using sofar, they are not just Mantras.
The first chapter of any popular book on Unix has these things explained.
 
Average of ratings:Useful (1)
Picture of Michael Schultz
Re: Setting up crontab
 

Hi again Visvanath,

I think you just resolved my concern. Your statement:

>If cron is happy with just php, then it is in that users $PATH.

That's all I needed to know. My concern was that this path might cause problems in the future. It sounds like that's not the case and my cron will continue to run fine as is. It's been running fine for 3 months now with no problems which is probably the best evidence that this is the case. It also means that anyone experiencing similar problems with the Bitnami package can use the cron I setup.

As for the owner being Apache, I think their might be a slight misunderstanding here. I didn't necessarily want the owner to be "Apache", that is what the Bitnami package already has it setup as. I honestly am not concerned about the owner now that I know the path is fine.

Thanks, you've been extraordinarily helpful.

 
Average of ratings: -