Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > CGI to reload apache

CGI to reload apache
Thread Tools
ctlq
Junior Member
Join Date: Nov 2004
Location: Michigan
Status: Offline
Reply With Quote
Apr 12, 2006, 01:41 PM
 
Ok I found out this is harder than it sounds. First I tried a php script to run a setuid file that did the httpd restart. But, since apache is running php it won't run code to restart itself. So, I came up with some C to do it for me and stuck it in a CGI. Unfortunately, it doesn't work. I know it's possible because Plesk does it.

Here's my code:

#include <stdio.h>
#include <stdlib.h>

int main() {
pid_t pid = 0;
printf("Content Type: text/html\n\n");;
printf("Connection: close\n");
printf("Content-Length: 5\n");
pid = fork();
if (pid < 0) printf("Fork error\n");
if (pid == 0) {
system("/sbin/service httpd reload");
} else {
exit(0);
}
return 0;
}
Pretty much I tried to fork the thread and have the new one that I didn't think apache would still control do the work.
     
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Apr 12, 2006, 09:39 PM
 
(deleted) oops... never mind, re-read your post, and realised mine was irrelevant.
     
Mithras
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Apr 12, 2006, 10:59 PM
 
Hmm, maybe have a separately-launched process reading on a FIFO or a TCP socket, and have the CGI script pass some kind of authenticating token to it, which triggers the httpd reload?
     
proton
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 23, 2006, 02:49 AM
 
Apache forked processes (such as CGI) runs as the user "www" which doesn't have permission to restart Apache.

You'll need to have a way to elevate privileges to root to restart apache and be extremely careful not to introduce any security issues (it's much harder than it looks to do this).

You'll want to use the command /usr/sbin/apachectl graceful to do the restart as this will mean it won't terminate currently active connections.

- proton
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 08:14 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,