[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: WSAPI vs. events
- From: Brian Maher <brian@...>
- Date: Wed, 13 Apr 2011 20:17:10 -0700
Here are some other random ideas:
For the log rotation problem I normally write to a named pipe and have
cronolog or multilog read from that named pipe:
http://cronolog.org/
http://cr.yp.to/daemontools/multilog.html
I also have cronolog or multilog monitored with daemontools's
supervise program or runit's runsv since cronolog will exit if you run
out of disk space (and cause all writers to block which effectively
creates a denial of service). In general, I use supervise or runsv to
monitor all my daemon's, it is also a much easier interface for
dealing with daemon's in my opinion.
For graceful server shutdown I would agree with other people that
doing it via signals would be easiest. I don't know enough about
existing Lua signal library implementations, but in general you need
to be careful in C about what functions get executed in your signal
handlers. So for example, libev's signal handling facilities uses the
"self pipe trick" so that your signal handles are ran in the "normal"
flow of the event loop.
Anyways, the easiest thing I can think of to do is to write a simple
Lua C extension that handles SIGHUP and updates a userdata. Then at
the end of your request processing, check the userdata to see if a
signal was received and if so, then exit/respawn.
Of course, the only problem with this solution is that you don't get a
"timely" shutdown since your only checking the state variable at the
end of processing a request. To overcome this, ideally you would
check the accept() system call to see if it errors with EINTR and if
so, then check the userdata to see if we got interrupted because of
our SIGHUP handler and if so, then shutdown immediately.
http://linux.die.net/man/2/accept
Unfortunately, it looks like you would need to hack lua sockets for that though:
https://github.com/LuaDist/luasocket/blob/master/src/usocket.c#L190
Cheers,
-Brian
On Sat, Apr 9, 2011 at 11:59 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
> Hi, list!
>
> Here is a simple question that I do not know a good answer for:
>
> I have a simple WSAPI-based HTTP service (running under
> nginx/spawn+fcgi/multiwatch/luajit2b5).
>
> Aside of serving some data over HTTP, this service writes some data to
> a log file for each request.
>
> I forked this service N times. Each fork does not and should not know
> about other's existence.
>
> Now I rotated the log file. How do I tell the WSAPI service to let go
> old log file and open a new one?
>
> * * *
>
> Note that my problem is more broad than that — for example I want to
> tell all forks to shut down etc., but we may concentrate on the issue
> at hand first.
>
> I have some possible solutions in mind (and actually do employ one of
> them), but, since the question is so simple, I will wait until others
> will suggest something. I like none of the options that I see.
>
> Alexander.
>
>
--
Brian Maher >> Glory to God <<