Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reloading Apache Problem 1

Status
Not open for further replies.

iaresean

Programmer
Mar 24, 2003
570
ZA
Hi all, me again, with another problem.

My cgi script works well at the moment and is almost complete. I only have one more hurdle to get over:
The user enters some info in a form and the form gets sent for processing. Using the information I modify the httpd.conf file. That goes all well. But now that I have modified the httpd.conf file a reload of apache is required so that it uses the updated configuration file. I have tried a few different commands, like:
/etc/rc.d/init.d/httpd restart
kill -HUP $(cat /var/run/httpd.pid)

The first one should have done it, but everytime I use one of these commands my webpage enters into an infinite loop where it keeps on saying connecting to... and then sending...

If I hash out the restart command the web page gets processed successfully, but apache isn't using the updated configuration file.

What must I do? I have searched the web long and hard. I only hope someone has the answer over here.

Thanks alot for all your time and effort.
A very inexperienced perl programmer.
 
You probably can not do this, unless of course your webhost has a severely insecure host. The apache user should never be able to restart the root owned process....

 
The web page is running as root so it does have root access to all files. The necessary security has been put in to place to prevent malicious attacks on the server via the web page. Any ideas now? I don't know if you can send a statement to restart apache from a web page while apache is processing the web page.
 
I tried it and an infinite loop occurs. Because the httpd.conf file is modified via the web page I created I have to restart apache so that it uses the new configuration file. The problem is as soon as the submit button is pressed and the processing starts taking place the restart apache command is executed in amongst the other various commands. So in effect I am restarting apache while it is loading/working with a page. This causes the web page to enter into an infinite loop of sending and connecting to....

Any ideas?
 
This has always been my experience.

I do not think apache can restart itself.

Another option is to run another apache daemon on a different port as the root user.

Click the user to that server for the 'restart' command. That server can then restart the primary server.

Generally speaking ,this is difficult because it is not a super great idea. Giving remote users control over your processes is asking for trouble.
 
Siberian;
Thanks alot for your quick response time and input concerning my problem. So far you are the first person that seems to understand my predicament, throughout all the various forums I have been to.

Your idea for the apache daemon sounds pretty good, but complicated at the same time. And I am not sure my superiors will allow this.

I was thinking, maybe I could change my restart command to an output command into a file indicating that the httpd.conf file has been modified and that apache needs to be restarted. Then perhaps I can write another program that will always run in the background. This program could check that file every, say 30 minutes or so, and if the file has changed then apache need s to be restarted.

What are your thoughts about this? Do you think, if a user happens to be submitting the webpage at the exact same time as my other program restarts apache, the same effect as before will occur?

Once again thanks for any time put into helping out a very inexperienced programmer.
 
Ok I put the reload apache command into another file. Then I put this command into my cgi script:

system("echo \"/usr/bin/reloadscript\" | at now +2 minutes");

Now the web page loads successfully. But the reloadscript is supposed to be started in two minutes time (I think by the cron daemon), but it isn't getting loaded.

What am I doing wrong???
 
Sorry, Ignore the last statement. I got it working. For anyone that has a similiar problem to mine here is a brief description of the problem and how I solved it.

I create a webpage which collects information from the user. Using this information I modify the httpd.conf file. Obviously apache has to be reloaded in order to read the configuration file. However you cannot do this while apache is load/working with a page.

In order to solve this I moved my reload apache statement into another file namely: "/usr/bin/restartapache"
Then from my web page, once the page is processed I call the following command:
system("echo \"/usr/bin/restartapache\" | at now +2 minutes");
Basically this makes linux run the script in 2 minutes time. The script then gets run completely seperatly from the web page and can therefore execute successfully.
 
np PaulTEG,

Your comment interested me enough to go do some research into it.

'Maith thu' - Congratulations = The Irish people really wouldn't just say "congratulations" or "comhghairdeas" they would say something like "Maith thu!" or "Maith go leor!" (All right!) or "Go maire tu!" Congratulations on your birthday would be = "Go maire tu an la!" and Congratulations on your wedding would be = "Go maire tu do shaol ur!"

You learn something new every day.
 
Sorry, just another follow-up for those who care. Here is a much better method of you running your reload apache script:

system("echo 'sleep 5; /path/to/script' | batch");

This will cause a 5 second delay only on the apache reload, instead of a minute, which may be useful because some people will try and access their web pages immediately afterwards.
 
Hi Sean,

I saw your solution. But I still have one more question. Like how did you run the "system" command from the CGI page. I couldnot do that. Let me give you my details.

I have loaded the Apache Web Server and started the http server. I could see my localhost running perfecly. I could see my results of my CGI pages except for in one page I used the system command which calls one of my perl scripts. But the System command doesnot produce any results and I think it didnot run at all.

Do you have any solutions in mind like why it didnot run.

Thanks,
Vijay
 
Vijay,

there could be a syntax error in your sytem("*") call, or you're not specifying the path to the perl executable properly, or Apache is incorrectly configured to run the CGI script from the direcory specified are three possible causes of your problem.

If you post the code for the system call, and spec the functions of the arguments, we may be able to help you further

HTH
--Paul
 
Hi Paul,

Thanks for the concern. I could easily compile my perl program using -c option hence it would remove the possibilities of syntax error and path of perl possibilities.

Coming to the Apache configuration, I can run all the other programs which I have written for the last one year and hence that cannot be a possibility.

Thanks,
Vijay
 
vrajasek,

You must remember that you have to give your script the correct permissions so that it is able to see the other folders on your drive, otherwise it will only be able to see files inside its own folder (e.g. /home/httpd/cgi-bin/).

If you haven't set permissions it means you would have to put your perl script in this folder. If this is the case already perhaps there is a syntax error. My code looks something like this:

system("/perlscript.pl");

Try writing a simple perl script that simply outputs a statement like "Hello world!". Then test this script through your cgi-script.

Get back to me with the results, there are a few other possibilitys that could be responsible for your problem.

P.S. Are your trying to restart apache from your script, if so I found the best command for that so far:
kill -USR1 $(cat /var/run/httpd.pid)
This will perform a graceful restart of apache, allowing its child commands to finish what they are doing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top