Page 1 of 1
cron question
Posted: Sat Jan 26, 2008 8:51 am
by alex.barylski
Having read this article:
http://www.debian-administration.org/articles/56
Seems setting up a cron would be a trivial task...with one caveat which is confusing me...
My system is actually a web host for several sites each with their own directories and PHP scripts which need to be invoked via CLI and run until completion.
It seems that article shows how to create cron tabs specific to a user...I need these crons to run all the time, regardless of whether I sign in as root or normal user or no one at all...
Is this what the
/etc/crontab file is for?
I essentially need to invoke a script at a set time 1 one minute apart for each site/domain:
Code: Select all
mydomain1.com/scripts/cleanup.php = 1:00 PM
mydomain2.com/scripts/cleanup.php = 1:01 PM
mydomain3.com/scripts/cleanup.php = 1:02 PM
...
How would I best handle this?
Re: cron question
Posted: Sat Jan 26, 2008 9:15 am
by arjan.top
Crontab will work all the time, even if you are not logged in
EDIT:
so just use crontab -e to edit crontab file
Re: cron question
Posted: Sat Jan 26, 2008 9:37 am
by alex.barylski
Edit: Just found this (
http://en.wikipedia.org/wiki/Crontab)
I see why editing the file manually will be difficult...as the cron daemon needs to be notified of a changed configuration file. Shoot!!! ANy ideas on how I could automate the task of adding schedules?
Oh it does? That article made it sound as though cron tabs were run on a per user basis as they logged in, etc...
p.s-The problem with using
crontab -e is that I now have to manually add/update crontab settings...Ideally I could setup crontabs inside a single file, so I can could automate the task using PHP...
Is there not a standard name or location for a file which houses the cron table information?
Cheers

Re: cron question
Posted: Sat Jan 26, 2008 9:43 am
by VladSun
Te reload config:
Re: cron question
Posted: Sat Jan 26, 2008 9:59 am
by alex.barylski
VladSun wrote:
Te reload config:
I've read the man pages...still not totally clear how to solve my problem though...
I need seperate cron jobs for each web site hosted. Web sites do not correspond to user accounts however...I do not know (or think it's possible) to login as user
www-data. There is only a single user account and root of course.
I need a PHP script (ideally) to be able to update a single crontab file which houses the commands and their schedules...something like:
Code: Select all
5 * * * * => php /var/www/mysite1/scripts/cleanup.php
5 * * * * => php /var/www/mysite2/scripts/cleanup.php
5 * * * * => php /var/www/mysite3/scripts/cleanup.php
As a site is removed or added it is then a trivial matter of parsing the crontab file above and add or remove new jobs...
Is something like the above possible? I'm not sure how I would go abouts doing something like that, I would need a separate file which was
owner: www-data but still read into the cron execution...
Another issue which just came to light...cron syntax above requires each job to be executed every 5 minutes...does each job spawn a new crond thread or process? Is there any way to separate each invocation by a few seconds just so I don't flood the system with a hundred cron jobs all at once???
Cheers

Re: cron question
Posted: Sat Jan 26, 2008 10:19 am
by VladSun
Hockey wrote:I need seperate cron jobs for each web site hosted. Web sites do not correspond to user accounts however...
You mean that you will allow every "hosting" user to have his own crontab config?
Hockey wrote:I do not know (or think it's possible) to login as user www-data. There is only a single user account and root of course.
it's possible - just
although it's not recommended.
Hockey wrote:I need a PHP script (ideally) to be able to update a single crontab file which houses the commands and their schedules...something like:
Code: Select all
5 * * * * => php /var/www/mysite1/scripts/cleanup.php
5 * * * * => php /var/www/mysite2/scripts/cleanup.php
5 * * * * => php /var/www/mysite3/scripts/cleanup.php
As a site is removed or added it is then a trivial matter of parsing the crontab file above and add or remove new jobs...
Is something like the above possible? I'm not sure how I would go abouts doing something like that, I would need a separate file which was
owner: www-data but still read into the cron execution...
It's seems that you perform the same action on each account - or it isn't true?
Hockey wrote:Another issue which just came to light...cron syntax above requires each job to be executed every 5 minutes...does each job spawn a new crond thread or process?
No - just the process thread is spawned.
Hockey wrote:Is there any way to separate each invocation by a few seconds just so I don't flood the system with a hundred cron jobs all at once???
How intensive will be running these scripts?
Re: cron question
Posted: Sat Jan 26, 2008 2:19 pm
by alex.barylski
It's seems that you perform the same action on each account - or it isn't true?
It's the same action yes. However it has to be, by design. Hard to explain why, but I cannot centralize the cleanup.php script and invoke it once through a single cron job. Basically, each web site has it's own installation of a custom applications. Each application has scheduled activities. So although the cleanup scripts do *exactly* the same thing - they operate on different databases. In order to centralize the cron scripts I would need to have the cleanup scripts look up each database, etc, etc...
By design of existing applications it's just to much work. It's easier to just setup multiple identical (albeit different) cron jobs for each site.
How intensive will be running these scripts?
Potentially huge, but typically a single conditional is all that is executed and an exit follows.
The way I see it...I either centralize the code for cleanup inside a single script by basically iterating a array of database connections, cleaning up and moving onto the next required cleanup or ignoring cleanup all togather and moving onto the next one. Or I let the OS handle that iteration by having multiple processes spawned, each to handle it's own cleanup. This would surely allow me to more effectively take advantage of dual/quad core processing power, as opposed to having a single monolithic script process do everything.
So, is it possible to configure cron to use a file created by PHP (www-data) as it's table (in addition to defaults) so that I may automate the process of adding/removing cron jobs??? Even if they are fired every 5 minutes??? No way to hack in a offset of sorts eh???
Cheers

Re: cron question
Posted: Sat Jan 26, 2008 2:26 pm
by VladSun
Hockey wrote:It's seems that you perform the same action on each account - or it isn't true?
It's the same action yes. However it has to be, by design. Hard to explain why, but I cannot centralize the cleanup.php script and invoke it once through a single cron job. Basically, each web site has it's own installation of a custom applications. Each application has scheduled activities. So although the cleanup scripts do *exactly* the same thing - they operate on different databases. In order to centralize the cron scripts I would need to have the cleanup scripts look up each database, etc, etc...
By design of existing applications it's just to much work. It's easier to just setup multiple identical (albeit different) cron jobs for each site.
How intensive will be running these scripts?
Potentially huge, but typically a single conditional is all that is executed and an exit follows.
The way I see it...I either centralize the code for cleanup inside a single script by basically iterating a array of database connections, cleaning up and moving onto the next required cleanup or ignoring cleanup all togather and moving onto the next one. Or I let the OS handle that iteration by having multiple processes spawned, each to handle it's own cleanup. This would surely allow me to more effectively take advantage of dual/quad core processing power, as opposed to having a single monolithic script process do everything.
So, is it possible to configure cron to use a file created by PHP (www-data) as it's table (in addition to defaults) so that I may automate the process of adding/removing cron jobs??? Even if they are fired every 5 minutes??? No way to hack in a offset of sorts eh???
Cheers

I would go with a hybrid version - centralized cron script spawning multiple processes. Somtehing like:
Code: Select all
while (data in accounts)
{
exec_in_background('clean_up', data);
sleep(15);
}
Re: cron question
Posted: Sat Jan 26, 2008 2:57 pm
by alex.barylski
I would go with a hybrid version - centralized cron script spawning multiple processes. Somtehing like:
Hmmmm...thats one way of solving the problem of lack of offsets in the cron, isn't it?
Could this be done with a shell script?
Whats really cool about this approach, is that I could implement a heuristics system and monitor what time interval results in best overall system performance - which is uber cool.
Hmmmm....this is a sexy solution...I like this. Damn dude I wish you noticed that earlier you would have saved me a half day in tinkering with process control functions.
Re: cron question
Posted: Sat Jan 26, 2008 3:01 pm
by VladSun
Hockey wrote:Could this be done with a shell script?
Yes - e.g. bash scripting.
Hockey wrote:Damn dude I wish you noticed that earlier you would have saved me a half day in tinkering with process control functions.
Sorry about that
