|
|
CGI to reload apache
|
|
|
|
Junior Member
Join Date: Nov 2004
Location: Michigan
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
(deleted) oops... never mind, re-read your post, and realised mine was irrelevant.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
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 Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|