httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexei Kosut <ako...@organic.com>
Subject sig_term
Date Tue, 12 Aug 1997 02:00:10 GMT
Let me quote from http_main.c:

void sig_term(int sig) {
    log_error("httpd: caught SIGTERM, shutting down", server_conf);
    cleanup_scoreboard();
#ifdef SIGKILL
    ap_killpg (pgrp, SIGKILL);
#endif /* SIGKILL */
    close(sd);
    exit(1);
}

I realize this code has been there since Apache 0.8, but it just decided
to annoy me. AFAIK, a TERM signal is the perferred method of shutting
Apache down. I know of no other way to do it, at least. So when one turns
Apache off, in a presumably graceful way, it sends a KILL to all its
children.

I can't possibly be the first person to run up against this problem:
There seems to be no way to have anything occur when Apache shuts
down. When Apache is restarted, it sends a SIGHUP to its children, which
allows them to do things. For example, they call the child_exit API
phase (in Apache 1.3), then they exit normally and send a SIGTERM to the
children's children (if you have running CGI scripts or whatnot).

No such luck with a shutdown. In fact, I believe I should veto
(retroactively) adding the child_exit phase, since it doesn't, in fact,
get called when a child exits when the server is shut down. It's
misleading and not all that useful.

The reason that I'm trying to do this is that I have module with a
process that I fork off in my initialization phase that I want to shut
down gracefully when Apache shuts down. Since I can't very well use
signal(SIGKILL), I haven't been able to do this. The only thing I can
think of is to call setpgid() to change my process group so I don't get
killed by the killpg when Apache dies, then poll getppid() to see if it
changes to 1.

But I'd really perfer not to do that. Have I missed something?

-- Alexei Kosut <akosut@organic.com>


Mime
View raw message