We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

restart apache from web page

mxjijo
mxjijo asked
on
Medium Priority
391 Views
Last Modified: 2008-02-01

Hello,
       I have an appliance which runs apache in it. Admin configures the appliance using web UI.
There are some configurations which needs apache restart. As you can imagine restarting apache
from a web page back-end would end up in a page-not-found error on the browser. How do you solve this ?

       Currently we have a delayed re-start script. When the restart is initiated using this script, it spawns
another instance and returns immediately to complete the HTTP request. The second instance restarts
apache after a delay (couple of seconds). This works fine - but not always. So is there a better way to
do this ?

thanks
Comment
Watch Question

Sam PanwarSr. Server Administrator

Commented:

Hi,

1.The requirement is more like that of a remote administration system and Webmin (http://www.webmin.com/) cleanly and safely fits the bill. Webmin can actually do more than just restarting Apache. But it can be configured to do only that.
assuming that your restart script is a simple shell, then use the restart command like follows:

  (sleep 10 && /path/to/apache restart )&

Author

Commented:
Abs_jaipur,
    webmin sounds like a 3rd party tool ? unfortunately we cannot use any non-trivial methods at this point.

 ahoffmann ,
   Yes, thats is sort of  what I do.
But the problem is  - the script restarts apache after 10 seconds of invokation.
In the mean time the request will be compleated and the user and navigate away to anothr page.
By the time the the script actually restarts the script the user may be trying to access a different
page and he will get a page_not_found error.
   
    One way to solve this is to display a message saying "Please Wait... " for 10+ seconds.
But I was wondering this should be a common problem for appliance web development and how
you guys solve it ?

~j
Sam PanwarSr. Server Administrator

Commented:
Hi,

In php 62 function but i found you can not control system through the php script language. you can use the cgi script for it becaouse apache support it and also use this script i will try to make script and give you shortly.
> In the mean time the request will be compleated and the user and navigate away
the server cannot inhibit this, for obvious reason
You just can inform the user as you identified yourself.
Sam PanwarSr. Server Administrator

Commented:
You could run apache with inetd instead of as a daemon.  But I have not
been able to find info about mod_perl at the apache web site, so I am not
sure how that works.  At any rate, your CGI would need root access to
change any server conf and attempting to restart apache would kill the CGI
that you were attempting to do it from.  Sounds like ssh (or telnet) would
be better.
http://perl.apache.org/

Try using 'suexec' with a password-protected CGI script which does
'apachectl graceful' as root.
http://httpd.apache.org/docs/1.3/suexec.html
http://httpd.apache.org/docs/2.0/stopping.html

http://groups.google.co.in/group/comp.infosystems.www.servers.ms-windows/browse_thread/thread/7143152d6aee3680/3467221e840f8042?lnk=st&q=restart+Apache+server+through+the+script&rnum=7&hl=en#3467221e840f8042

Author

Commented:

ahoffmann,
    So far it looks like that is the only way around. I'll wait some more time and see if anyone got a better idea.

Abs_jaipur,
    I am not 100% sure if I understood your approach. As you can see "how to restart apache" is NOT the question. The question is "How to restart apache with out loosing the current (or  subsequent) page". It is definitly a timing issue. Btw, we are not using (cannot use) cgi or any other non-trivial tools. PHP, JAVA/JSP/javascript are fine.

thanks
~j
Jeffrey Kane - TechSoEasyPrincipal Consultant
CERTIFIED EXPERT
Most Valuable Expert 2016
Top Expert 2014

Commented:
Actually, your premise that a 404 Page-Not-Found error will occur when you restart Apache is wrong.

Page-Not-Found errors are generated by Apache itself so it must be running in order to have that error.  If anything, the front-end user would have a Server-Not-Found error generated by their browser... but restarting Apache takes less than 5 seconds and the timeout on browsers for resolving servers is generally 5 seconds.  

Jeff
TechSoEasy

Author

Commented:
TechSoEasy,
    it is not a 404 HTTP error. it is a browser error "The page cannot be displayed"..

~j
Jeffrey Kane - TechSoEasyPrincipal Consultant
CERTIFIED EXPERT
Most Valuable Expert 2016
Top Expert 2014

Commented:
mxjijo,

Even if it's a Page cannot be displayed error (meaning that the server is not able to be resolved) I still don't quite understand what the problem is... restarting Apache IS the http request... what would you want to be returned after you've issued the restart command?  Usually just refreshing the browser will reconnect it within the couple of seconds it takes to reboot Apache.

This is rather similar to most every Router Control Panel that's out there... most of them, when you restart the router will answer back first with a delayed refresh script and then restart... your browser would then refresh automatically in 10 or 15 seconds, however long you set the delay for.

Jeff
TechSoEasy
I also bvelieve that the answer to the question is: cannot be done that way.
"impossible" or "cannot be done" is an answer, even if it is not what the autor wants to hear.

Author

Commented:

Jeff, ahoffmann,
  As I mentioned in my first posting itself, I do have a delayed script to restart apache - which works (with some tweaks).
Being not an expert in web programming, I wanted to know if there is a "better" method to do this. I really thank you
guys for spending time on this. I just want to clarify one thing.

>> I still don't quite understand what the problem is... restarting Apache IS the http request...
>> what would you want to be returned after you've issued the restart command?
  I don't know much about the HTTP request lifecycle. However as far as I can see,
when I restart apache from a request handler script (say a php script), I think the "current" request terminates
abnormally. With IE, sometimes I can see a blank page in this case.
  I totally agree with you guys that the browser can reconnect in a few seconds and everything will get back
where it should be. But I wanted to avoid the possibility of getting blank pages. The important point being
I was working on a configuration wizard kind of page where one page automatically forwards to the next page after submit.
So in this case the suceeding page can easily get into the situation we were discussing.
> I think the "current" request terminates ..
normally, not abnormally
You cannot "hold" a connection if one end of the connection dies

> But I wanted to avoid the possibility of getting blank pages.
If the connection dies where the request is going to, there is no possibility. Dot. Period.
If the request arrives to your intermediate server, then that one should send a redirect page with a timout of your choice.
Principal Consultant
CERTIFIED EXPERT
Most Valuable Expert 2016
Top Expert 2014
Commented:
There are a number of ways to code this... but most people do restart apache through a web browser (instead of using an ssh session, for instance).  So to enable a client-side refresh, you just need to add a small javascript that would refresh the browser in whatever timeframe you think appropriate... you can also write the script to show a "restarting" page in case the server hasn't responded the first time.

I've not written anything of the sort myself, but I see it in operation on a daily basis... just as an example, here's the javascript that is on my NetGear FVS318's interface:

}  
    var time = 0
    var interval = 3
    intervalId = setInterval("getPage()", interval * 1000)
    function begin()
    {
        if(time==0)
        stopInterval();
    }
    function stopInterval()
    {  
        clearInterval(intervalId)
    }

    function getPage()
    {
        top.formframe.location.href="diagnostics.html"
    }
function Restart(){
      if (confirm('WARNING:\n\nA reboot will interrupt all current connections while the router restarts.\n\nAre you sure you want to do this?\n'))
      {
          //raymond 20040309
          //tF.submit();
              return true;
      }
      else
      {
      //raymond 20040309
      //top.formframe.location.href="diagnostics.html"
      return false;
      }
}
   

This both pops up a warning box to confirm the reboot, and then it delays a refresh for a few seconds before returning the "competed" page.  (That part of the code is by the reboot button):

<td colspan="2">
      <b>Reboot the router</b>
</td>
</tr>
<tr>
<td colspan="2" align="right">
      <!-- raymond 20040309 -->
      <!-- <input type="button" name="reboot" value=" Reboot " onClick="Restart(document.tF)"> -->
      <input type="submit" name="reboot" value=" Reboot " onClick="return Restart(document.tF)">
      <input type="hidden" name="UN" size="30" maxlength="31">
</td>
</tr>

Hope that's enough to inspire you!  :-)

Jeff
TechSoEasy

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
> .. you just need to add a small javascript ..
unreliable, better use meta tag refresh
KISS - keep it simple stupid
Jeffrey Kane - TechSoEasyPrincipal Consultant
CERTIFIED EXPERT
Most Valuable Expert 2016
Top Expert 2014

Commented:
Fine, do it with META refresh... like I said, I don't do much in this area, but since nobody was answering and I knew it was technically possible, I tossed that out... after copying it from my router's interface!

Jeff
TechSoEasy
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.