ia64/xen-unstable

view tools/python/xen/xend/server/SrvServer.py @ 6588:f25a9797419e

Fix closing of /var/log/xend.log fd
Fix the problem where /var/log/xend.log was getting closed and then
/var/log/xend-debug was getting all the spam about the fd being closed
in the logging stuff.

Basically what was happening is that the main thread wasn't sticking
around and during its exit, the atexit handlers of the python logging
stuff got called closing the log fd.

Patch makes it so that we instead wait on the real server threads to
exit before shutting things down.

Signed-off-by: Jeremy Katz <katzj@redhat.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Sep 01 10:26:17 2005 +0000 (2005-09-01)
parents dd668f7527cb
children b2f4823b6ff0 b35215021b32 9af349b055e5 7985a4d8bae9
line source
1 #!/usr/bin/python
2 #============================================================================
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of version 2.1 of the GNU Lesser General Public
5 # License as published by the Free Software Foundation.
6 #
7 # This library is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 # Lesser General Public License for more details.
11 #
12 # You should have received a copy of the GNU Lesser General Public
13 # License along with this library; if not, write to the Free Software
14 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 #============================================================================
16 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
17 #============================================================================
19 """Example xend HTTP
21 Can be accessed from a browser or from a program.
22 Do 'python SrvServer.py' to run the server.
23 Then point a web browser at http://localhost:8000/xend and follow the links.
24 Most are stubs, except /domain which has a list of domains and a 'create domain'
25 button.
27 You can also access the server from a program.
28 Do 'python XendClient.py' to run a few test operations.
30 The data served differs depending on the client (as defined by User-Agent
31 and Accept in the HTTP headers). If the client is a browser, data
32 is returned in HTML, with interactive forms. If the client is a program,
33 data is returned in SXP format, with no forms.
35 The server serves to the world by default. To restrict it to the local host
36 change 'interface' in main().
38 Mike Wray <mike.wray@hp.com>
39 """
40 # todo Support security settings etc. in the config file.
41 # todo Support command-line args.
43 from threading import Thread
45 from xen.web.httpserver import HttpServer, UnixHttpServer
47 from xen.xend import XendRoot; xroot = XendRoot.instance()
48 from xen.xend import Vifctl
49 from xen.xend.XendLogging import log
50 from xen.web.SrvDir import SrvDir
52 from SrvRoot import SrvRoot
54 class XendServers:
56 def __init__(self):
57 self.servers = []
59 def add(self, server):
60 self.servers.append(server)
62 def start(self):
63 Vifctl.network('start')
64 threads = []
65 for server in self.servers:
66 thread = Thread(target=server.run)
67 thread.start()
68 threads.append(thread)
70 for t in threads:
71 t.join()
73 def create():
74 root = SrvDir()
75 root.putChild('xend', SrvRoot())
76 servers = XendServers()
77 if xroot.get_xend_http_server():
78 port = xroot.get_xend_port()
79 interface = xroot.get_xend_address()
80 servers.add(HttpServer(root=root, interface=interface, port=port))
81 if xroot.get_xend_unix_server():
82 path = xroot.get_xend_unix_path()
83 log.info('unix path=' + path)
84 servers.add(UnixHttpServer(path=path, root=root))
85 return servers