I have a Bash script, currently run a couple times an hour from cron, that pulls data from an old Windows DB by rsync, converts it to SQL, and injects it into a MySQL DB for display in a LAMP-based app. (Make and Perl are also involved to minimize the number of tables touched and to clean up the SQL generated by Pxlib.)
I'd like to add the ability to refresh the data immediately from the web app, but I don't want it to trample on the periodic script and corrupt the data.
I figure the ideal way to do this is to run the script in a loop in its own process, waiting on a semaphore that times out at the refresh period, and poke the semaphore from the web app to have it run before the next periodic cycle.
Are there existing frameworks to wrap this kind of thing in? Something that handles starting the loop at server startup, shutting it down at server halt, and handles the IPC between the web server and the service script.
On Fri, 8 Jul 2011, Kenneth Porter wrote:
To: CentOS mailing list centos@centos.org From: Kenneth Porter shiva@sewingwitch.com Subject: [CentOS] Triggering script from cron or web client
I have a Bash script, currently run a couple times an hour from cron, that pulls data from an old Windows DB by rsync, converts it to SQL, and injects it into a MySQL DB for display in a LAMP-based app. (Make and Perl are also involved to minimize the number of tables touched and to clean up the SQL generated by Pxlib.)
I'd like to add the ability to refresh the data immediately from the web app, but I don't want it to trample on the periodic script and corrupt the data.
I figure the ideal way to do this is to run the script in a loop in its own process, waiting on a semaphore that times out at the refresh period, and poke the semaphore from the web app to have it run before the next periodic cycle.
Is this something you could do with AJAX?
Keith
----------------------------------------------------------------- Websites: http://www.karsites.net http://www.php-debuggers.net http://www.raised-from-the-dead.org.uk
All email addresses are challenge-response protected with TMDA [http://tmda.net] -----------------------------------------------------------------
On Friday, July 08, 2011 11:05 PM +0100 Keith Roberts keith@karsites.net wrote:
Is this something you could do with AJAX?
You mean JavaScript on the web client? That won't do anything for me on the server.
Note that the problem isn't strictly a web server problem. That just happens to be the place where I want to initially trigger this from. But I might also do it from a shell login. What I need is a way to kick a service so it doesn't wait for the next periodic interval to run a script. It would also be useful to have the "kick" block until the script finishes so I know when the results are available.
Kenneth Porter wrote:
On Friday, July 08, 2011 11:05 PM +0100 Keith Roberts keith@karsites.net wrote:
Is this something you could do with AJAX?
You mean JavaScript on the web client? That won't do anything for me on the server.
Note that the problem isn't strictly a web server problem. That just happens to be the place where I want to initially trigger this from. But I might also do it from a shell login. What I need is a way to kick a service so it doesn't wait for the next periodic interval to run a script. It would also be useful to have the "kick" block until the script finishes so I know when the results are available.
Read about Webmin. it's web interface for Linux administration that has as a part the cron job manipulation. You can change parameters disable/enable and run at once any cron job or service.
Ljubomir
On 7/8/2011 5:43 PM, Ljubomir Ljubojevic wrote:
Kenneth Porter wrote:
On Friday, July 08, 2011 11:05 PM +0100 Keith Robertskeith@karsites.net wrote:
Is this something you could do with AJAX?
You mean JavaScript on the web client? That won't do anything for me on the server.
Note that the problem isn't strictly a web server problem. That just happens to be the place where I want to initially trigger this from. But I might also do it from a shell login. What I need is a way to kick a service so it doesn't wait for the next periodic interval to run a script. It would also be useful to have the "kick" block until the script finishes so I know when the results are available.
Read about Webmin. it's web interface for Linux administration that has as a part the cron job manipulation. You can change parameters disable/enable and run at once any cron job or service.
That's not going to give him atomic operations if the web/cron jobs hit at the same time or a bunch of web users all click the update button at once.
Les Mikesell wrote:
On 7/8/2011 5:43 PM, Ljubomir Ljubojevic wrote:
Kenneth Porter wrote:
On Friday, July 08, 2011 11:05 PM +0100 Keith Robertskeith@karsites.net wrote:
Is this something you could do with AJAX?
You mean JavaScript on the web client? That won't do anything for me on the server.
Note that the problem isn't strictly a web server problem. That just happens to be the place where I want to initially trigger this from. But I might also do it from a shell login. What I need is a way to kick a service so it doesn't wait for the next periodic interval to run a script. It would also be useful to have the "kick" block until the script finishes so I know when the results are available.
Read about Webmin. it's web interface for Linux administration that has as a part the cron job manipulation. You can change parameters disable/enable and run at once any cron job or service.
That's not going to give him atomic operations if the web/cron jobs hit at the same time or a bunch of web users all click the update button at once.
Yeah, I got that latter, when I read it the second time and some of the replies. I misunderstood him at first read.
Ljubomir
On Fri, 8 Jul 2011, Kenneth Porter wrote:
To: CentOS mailing list centos@centos.org From: Kenneth Porter shiva@sewingwitch.com Subject: Re: [CentOS] Triggering script from cron or web client
On Friday, July 08, 2011 11:05 PM +0100 Keith Roberts keith@karsites.net wrote:
Is this something you could do with AJAX?
You mean JavaScript on the web client? That won't do anything for me on the server.
Well the AJAX would be running on the server side, and the results would be received by the client running the server-sided code over your network.
Here's a nice little demo of using The XMLHttpRequest Object:
http://www.w3schools.com/xml/xml_http.asp
HTH
Keith
----------------------------------------------------------------- Websites: http://www.karsites.net http://www.php-debuggers.net http://www.raised-from-the-dead.org.uk
All email addresses are challenge-response protected with TMDA [http://tmda.net] -----------------------------------------------------------------
On 7/9/11, Keith Roberts keith@karsites.net wrote:
Well the AJAX would be running on the server side, and the results would be received by the client running the server-sided code over your network.
AJAX is a browser/client side method, it doesn't solve his fundamental server side requirements which remains the same whether it's triggered by traditional synchronous methods or through AJAX methods.
On 7/8/2011 4:58 PM, Kenneth Porter wrote:
I have a Bash script, currently run a couple times an hour from cron, that pulls data from an old Windows DB by rsync, converts it to SQL, and injects it into a MySQL DB for display in a LAMP-based app. (Make and Perl are also involved to minimize the number of tables touched and to clean up the SQL generated by Pxlib.)
I'd like to add the ability to refresh the data immediately from the web app, but I don't want it to trample on the periodic script and corrupt the data.
I figure the ideal way to do this is to run the script in a loop in its own process, waiting on a semaphore that times out at the refresh period, and poke the semaphore from the web app to have it run before the next periodic cycle.
Are there existing frameworks to wrap this kind of thing in? Something that handles starting the loop at server startup, shutting it down at server halt, and handles the IPC between the web server and the service script.
You already have a DB connection in common - can't the update script itself lock something in the DB while it works? Or just make the web script wait for the cron job to complete if you are anywhere near the time for it to run.
On Fri, 8 Jul 2011, Les Mikesell wrote:
To: centos@centos.org From: Les Mikesell lesmikesell@gmail.com Subject: Re: [CentOS] Triggering script from cron or web client
...snip...
You already have a DB connection in common - can't the update script itself lock something in the DB while it works? Or just make the web script wait for the cron job to complete if you are anywhere near the time for it to run.
Sounds like it needs to be one main script, that branches depending on how it is called - ie from cron or ssh or curl or whatever?
Maybe saving the current state of the script in an ENV variable whenever the script is run, check for the current status of the script before making a decision on what to do, when it is called next time?
Keith Roberts
----------------------------------------------------------------- Websites: http://www.karsites.net http://www.php-debuggers.net http://www.raised-from-the-dead.org.uk
All email addresses are challenge-response protected with TMDA [http://tmda.net] -----------------------------------------------------------------