extras-buildsys/server main.py,1.18,1.19
Daniel Williams (dcbw)
fedora-extras-commits at redhat.com
Sun Mar 12 05:44:43 UTC 2006
Author: dcbw
Update of /cvs/fedora/extras-buildsys/server
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv16976/server
Modified Files:
main.py
Log Message:
2006-03-12 Dan Williams <dcbw at redhat.com>
* builder/builder.py
- Add a SIGTERM handler for clean shutdown
- Clean up lifecycle management
* common/HTTPServer.py
- Clean up lifecycle management of PlgHTTPServerManager objects
* common/SSLCommon.py
- Clean up lifecycle management of PlgBaseServer objects
- Initialize correct parent object in PlgBaseSSLServer.__init__
* etc/plague-builder.init
etc/plague-server.init
- Cleanups
* server/main.py
- Add a SIGTERM handler for clean shutdown
- Clean up lifecycle management
Index: main.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/server/main.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- main.py 15 Feb 2006 17:03:30 -0000 1.18
+++ main.py 12 Mar 2006 05:44:35 -0000 1.19
@@ -19,6 +19,8 @@
import sys
import os
import socket
+import signal
+import time
from plague import AuthedXMLRPCServer
from plague import HTTPServer
from plague import daemonize
@@ -59,7 +61,16 @@
#################################################################
-if __name__ == '__main__':
+bm_server = None
+
+def exit_handler(signum, frame):
+ global bm_server
+ print "Received SIGTERM, quitting..."
+ bm_server.stop()
+
+def main():
+ global bm_server
+
usage = "Usage: %s [-p <pidfile>] [-l <logfile>] [-d] [-c <configfile>]" % sys.argv[0]
parser = OptionParser(usage=usage)
parser.add_option("-p", "--pidfile", default=None,
@@ -135,7 +146,7 @@
bm_server = AuthedXMLRPCServer.AuthedXMLRPCServer((hostname, port))
except socket.error, e:
if e[0] == 98: # Address already in use
- print "Error: couldn't bind to address '%s:%s'. Is the server already running?" % (hostname, UI_PORT)
+ print "Error: couldn't bind to address '%s:%s'. Is the server already running?" % (hostname, port)
os._exit(1)
bm_server.register_instance(ui)
@@ -157,20 +168,30 @@
DebugUtils.registerThreadName(dummy)
del dummy
+ # Set up our termination handler
+ signal.signal(signal.SIGTERM, exit_handler)
+
print "Build Server accepting requests on %s:%d.\n" % (hostname, port)
+
+ # Serve requests until we're told to stop
try:
bm_server.serve_forever()
except KeyboardInterrupt:
- # Make sure the BuildMaster thread shuts down
- print "Shutting down..."
- bm.stop()
- srpm_server.stop()
- tbs.stop()
+ bm_server.server_close()
+
+ # Make sure the BuildMaster thread shuts down
+ print "Shutting down..."
+ bm.stop()
+ srpm_server.stop()
+ tbs.stop()
if opts.pidfile:
os.unlink(opts.pidfile)
+ time.sleep(2)
print "Done."
os._exit(0)
+if __name__ == '__main__':
+ main()
More information about the fedora-extras-commits
mailing list