ia64/xen-unstable

view tools/misc/xend @ 19527:0e24e9674ded

tools: Always use sane upstream (`native') python paths

Previously, by default we would install our python modules into
/usr/lib/python/xen, for example /usr/lib/python/xen/__init__.py.
Upstream python's standard install location (a) includes the Python
version number and (b) puts things in site-packages by default.

Our best conjecture for the reason for this was an attempt to make the
installs portable between different python versions. However, that
doesn't work because compiled python modules (.pyc), and C python
extensions corresponding to one version of python, are not compatible
across different versions of python.

This is why upstream include the version number.

site-packages is the standard location for locally-installed packages
and is automatically included on the python search path.

In this change, we abandon our own unusual python path setup:

* Invoke setup.py in an entirely standard manner. We pass
PREFIX and DESTDIR using the appropriate options provided by
setup.py for those purposes (adding them to setup.py calls
which were previously lacking them).

* Since the installation locations are now on the standard
python path, we no longer need to add anything to the path
in any of our python utilities. Therefore remove all that
code from every python script. (Many of these scripts
unconditionally added /usr/lib/python and /usr/lib64/python which
is wrong even in the old world.)

* There is no longer any special `Xen python path'. xen-python-path
is no longer needed. It is no longer called by anything in our
tree. However since out-of-tree callers may still invoke it, we
retain it. It now prints a fixed string referring to a directory
which does not to exist; callers (who use it to augment their
python path) will thus add a nonexistent directory to their python
path which is harmless.

* Remove various workarounds including use of setup.py --home
(which is intended for something completely different).

* Remove tests for the XEN_PYTHON_NATIVE_INSTALL build-time
environment variable. The new behaviour is the behaviour which we
should have had if this variable had been set. That is, it is now
as if this variable was always set but also bugs in the resulting
install have been fixed.

This should be a proper fix for the bug addressed by c/s 19515.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Apr 08 19:13:04 2009 +0100 (2009-04-08)
parents 644a9d219973
children
line source
1 #!/usr/bin/env python
2 # -*- mode: python; -*-
3 #============================================================================
4 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
5 # Copyright (C) 2005-2006 XenSource Inc
6 #============================================================================
8 """Xen management daemon.
9 Provides console server and HTTP management api.
11 Run:
12 xend start
14 Restart:
15 xend restart
17 The daemon is stopped with:
18 xend stop
20 The daemon should reconnect to device control interfaces
21 and recover its state when restarted.
23 On Solaris, the daemons are SMF managed, and you should not attempt
24 to start xend by hand.
25 """
26 import fcntl
27 import glob
28 import os
29 import os.path
30 import sys
31 import socket
32 import signal
33 import time
34 import commands
36 from xen.xend.server import SrvDaemon
38 class CheckError(ValueError):
39 pass
41 def hline():
42 print >>sys.stderr, "*" * 70
44 def msg(message):
45 print >>sys.stderr, "*" * 3, message
47 def check_logging():
48 """Check python logging is installed and raise an error if not.
49 Logging is standard from Python 2.3 on.
50 """
51 try:
52 import logging
53 except ImportError:
54 hline()
55 msg("Python logging is not installed.")
56 msg("Use 'make install-logging' at the xen root to install.")
57 msg("")
58 msg("Alternatively download and install from")
59 msg("http://www.red-dove.com/python_logging.html")
60 hline()
61 raise CheckError("logging is not installed")
63 def check_user():
64 """Check that the effective user id is 0 (root).
65 """
66 if os.geteuid() != 0:
67 hline()
68 msg("Xend must be run as root.")
69 hline()
70 raise CheckError("invalid user")
72 def start_daemon(daemon, *args):
73 if os.fork() == 0:
74 os.execvp(daemon, (daemon,) + args)
76 def start_xenstored():
77 pidfname = "/var/run/xenstore.pid"
78 try:
79 f = open(pidfname, "a")
80 try:
81 fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
82 rootdir = os.getenv("XENSTORED_ROOTDIR") or "/var/lib/xenstored"
83 for i in glob.glob(rootdir + "/tdb*"):
84 try:
85 os.unlink(i)
86 except:
87 pass
88 os.unlink(pidfname)
89 except:
90 pass
91 f.close()
92 except:
93 pass
94 XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
95 cmd = "xenstored --pid-file /var/run/xenstore.pid"
96 if XENSTORED_TRACE:
97 cmd += " -T /var/log/xen/xenstored-trace.log"
98 s,o = commands.getstatusoutput(cmd)
100 def start_consoled():
101 XENCONSOLED_TRACE = os.getenv("XENCONSOLED_TRACE")
102 args = ""
103 if XENCONSOLED_TRACE:
104 args += "--log=" + XENCONSOLED_TRACE
105 start_daemon("xenconsoled", args)
107 def start_blktapctrl():
108 start_daemon("blktapctrl", "")
110 def main():
111 try:
112 check_logging()
113 check_user()
114 except CheckError:
115 sys.exit(1)
117 daemon = SrvDaemon.instance()
118 if not sys.argv[1:]:
119 print 'usage: %s {start|stop|reload|restart}' % sys.argv[0]
120 elif sys.argv[1] == 'start':
121 if os.uname()[0] != "SunOS":
122 start_xenstored()
123 start_consoled()
124 start_blktapctrl()
125 return daemon.start()
126 elif sys.argv[1] == 'trace_start':
127 start_xenstored()
128 start_consoled()
129 start_blktapctrl()
130 return daemon.start(trace=1)
131 elif sys.argv[1] == 'stop':
132 return daemon.stop()
133 elif sys.argv[1] == 'reload':
134 return daemon.reloadConfig()
135 elif sys.argv[1] == 'restart':
136 start_xenstored()
137 start_consoled()
138 start_blktapctrl()
139 return daemon.stop() or daemon.start()
140 elif sys.argv[1] == 'status':
141 return daemon.status()
142 else:
143 print 'not an option:', sys.argv[1]
144 return 1
146 if __name__ == '__main__':
147 sys.exit(main())