[Twisted-Python] stopping daemon started via twistd
I'm looking for a portable way to stop and start a twisted application, specifically a twisted.web.xmlrpc server being started with a .tac file via twistd. on ubuntu i can easily use the start-stop-daemon but some other developers are using mac/windows and i was looking for a nice way for all to be able to start and stop this server as they make changes to it, aside from kill/killproc that is. I noticed that the object returned after calling internet.SSLServer server has a method called stopService, but am confused about how to use that, after starting it with twistd. Perhaps twistd is not the right approach for starting? googling around seems to bring up arguments from years past about if this behavior belongs in twisted on in the users app, but found no real solution...but may have missed the obvious. Thanks Jeff
On Tue, 1 Jul 2008 17:53:26 -0400, Jeff Dyke
I'm looking for a portable way to stop and start a twisted application, specifically a twisted.web.xmlrpc server being started with a .tac file via twistd. on ubuntu i can easily use the start-stop-daemon but some other developers are using mac/windows and i was looking for a nice way for all to be able to start and stop this server as they make changes to it, aside from kill/killproc that is.
I noticed that the object returned after calling internet.SSLServer server has a method called stopService, but am confused about how to use that, after starting it with twistd. Perhaps twistd is not the right approach for starting? googling around seems to bring up arguments from years past about if this behavior belongs in twisted on in the users app, but found no real solution...but may have missed the obvious.
Perhaps the feature described at http://twistedmatrix.com/trac/ticket/2577 is what you're looking for? Someone still needs to implement it. :) Jean-Paul
I don't know of a portable way to do this, but...
The "stopService" method that you referenced is probably not what you want.
It stops a twisted service object, which you should have created in your
.tac file, but does not stop twistd.
I know diddly about how to stop and start service/daemon processes on MacOS,
but on Win32, you have a lot of options:
- rewrite things to use pywin32's services support...this typically involves
starting the reactor manually, though
- there's some code in the twisted svn sandbox (look under moonfallen) that
does something like this using py2exe (haven't used this though)
- take your twistd command line and use "instsrv" and "srvany" to make it
run as a service (maybe)
Good luck!
Kevin Horn
On Tue, Jul 1, 2008 at 4:53 PM, Jeff Dyke
I'm looking for a portable way to stop and start a twisted application, specifically a twisted.web.xmlrpc server being started with a .tac file via twistd. on ubuntu i can easily use the start-stop-daemon but some other developers are using mac/windows and i was looking for a nice way for all to be able to start and stop this server as they make changes to it, aside from kill/killproc that is.
I noticed that the object returned after calling internet.SSLServer server has a method called stopService, but am confused about how to use that, after starting it with twistd. Perhaps twistd is not the right approach for starting? googling around seems to bring up arguments from years past about if this behavior belongs in twisted on in the users app, but found no real solution...but may have missed the obvious.
Thanks Jeff
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
On Tue, Jul 1, 2008 at 7:09 PM, Curt
Kevin Horn wrote:
I don't know of a portable way to do this, but...
The "stopService" method that you referenced is probably not what you want. It stops a twisted service object, which you should have created in your .tac file, but does not stop twistd.
I know diddly about how to stop and start service/daemon processes on MacOS, but on Win32, you have a lot of options: - rewrite things to use pywin32's services support...this typically involves starting the reactor manually, though - there's some code in the twisted svn sandbox (look under moonfallen) that does something like this using py2exe (haven't used this though) - take your twistd command line and use "instsrv" and "srvany" to make it run as a service (maybe)
Good luck!
Kevin Horn
On Tue, Jul 1, 2008 at 4:53 PM, Jeff Dyke
wrote: I'm looking for a portable way to stop and start a twisted application, specifically a twisted.web.xmlrpc server being started with a .tac file via twistd. on ubuntu i can easily use the start-stop-daemon but some other developers are using mac/windows and i was looking for a nice way for all to be able to start and stop this server as they make changes to it, aside from kill/killproc that is.
I noticed that the object returned after calling internet.SSLServer server has a method called stopService, but am confused about how to use that, after starting it with twistd. Perhaps twistd is not the right approach for starting? googling around seems to bring up arguments from years past about if this behavior belongs in twisted on in the users app, but found no real solution...but may have missed the obvious.
Thanks Jeff
I just parse the twistd.pid file and os.kill(pid, signal.SIGTERM). This does a 'nice' shutdown, each service that the twistd daemon is running will call it's stopService method for cleanup and shut down in an orderly manner. makes sense.
PS. the signal above is in a shutdown command in the app that does any necessary app level clean-up first, although I guess you could put that clean-up in your service's stopService method too.
what do you mean is in a shutdown command in the app, how do you tell the app to execute the shutdown command containing os.kill? If i can figure all this out and more, i'd love to fulfill that feature request. thanks
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
thought you might say that, i had started down that path...perhaps i'm
headed back, thanks.
On Wed, Jul 2, 2008 at 9:36 AM, Curt
Jeff Dyke wrote:
I just parse the twistd.pid file and os.kill(pid, signal.SIGTERM). This does a 'nice' shutdown, each service that the twistd daemon is running will call it's stopService method for cleanup and shut down in an orderly manner.
makes sense.
PS. the signal above is in a shutdown command in the app that does any necessary app level clean-up first, although I guess you could put that clean-up in your service's stopService method too.
what do you mean is in a shutdown command in the app, how do you tell the app to execute the shutdown command containing os.kill? If i can figure all this out and more, i'd love to fulfill that feature request.
thanks
def handle_shutdown(self, user, *args): if user.account.access is not AllAccess.Owner: self.hideCommand(user) else: pid = int(file('twistd.pid', mode = 'r').readline()) os.kill(pid, signal.SIGUSR1) user.socket.sendToClient('Normal shutdown, rotating logfiles.\r\n') os.kill(pid, signal.SIGTERM)
Here's my handle_shutdown method, slightly abbreviated. Just call this the same way you give the app any other input....IE: if it is a web app, put an admin control clickie somewhere that activates it. If it is a custom client, put a control in that, if it is a direct TCP app (telnet) make the command parser call it when the user enters the proper command.
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (4)
-
Curt
-
Jean-Paul Calderone
-
Jeff Dyke
-
Kevin Horn