ia64/xen-unstable

view tools/misc/xend @ 2422:2274a0386cc9

bitkeeper revision 1.1159.69.5 (4138e882jA1YaR_OfTfNHe_uT4PDIg)

trivial
author iap10@labyrinth.cl.cam.ac.uk
date Fri Sep 03 21:56:18 2004 +0000 (2004-09-03)
parents dae98734f12e
children b239a7e0631e c7b0154dff73 0a4b76b6b5a0
line source
1 #!/usr/bin/env python
2 # -*- mode: python; -*-
3 #============================================================================
4 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
5 #============================================================================
7 """Xen management daemon. Lives in /usr/sbin.
8 Provides console server and HTTP management api.
10 Run:
12 xend start
14 The daemon is stopped with:
16 xend stop
18 The daemon should reconnect to device control interfaces
19 and recover its state when restarted.
20 """
21 import os
22 import sys
24 class CheckError(ValueError):
25 pass
27 def hline():
28 print >>sys.stderr, "*" * 70
30 def msg(message):
31 print >>sys.stderr, "*" * 3, message
33 def check_logging():
34 """Check python logging is installed and raise an error if not.
35 Logging is standard from Python 2.3 on.
36 """
37 try:
38 import logging
39 except ImportError:
40 hline()
41 msg("Python logging is not installed.")
42 msg("Use 'make install-logging' at the xen root to install.")
43 msg("")
44 msg("Alternatively download and install from")
45 msg("http://www.red-dove.com/python_logging.html")
46 hline()
47 raise CheckError("logging is not installed")
49 def check_twisted_version():
50 """Check twisted is installed with a supported version and print a warning if not.
51 Raises an error if twisted is not installed.
52 """
53 # Supported twisted release and major version.
54 RELEASE = 1
55 MAJOR = 3
56 try:
57 from twisted.copyright import version
58 except ImportError:
59 hline()
60 msg("The Twisted framework is not installed.")
61 msg("Use 'make install-twisted' at the xen root to install.")
62 msg("")
63 msg("Alternatively download and install version %d.%d or higher" % (RELEASE, MAJOR))
64 msg("from http://www.twistedmatrix.com/products")
65 hline()
66 raise CheckError("twisted is not installed")
69 (release, major, minor) = version.split('.')
70 release = int(release)
71 major = int(major)
72 if release > RELEASE: return
73 if release == RELEASE and major >= MAJOR: return
74 hline()
75 msg("Warning: Twisted version not supported: %s" % version)
76 msg("Use Twisted version %d.%d.0 or higher" % (RELEASE, MAJOR))
77 hline()
79 def check_user():
80 """Check that the effective user id is 0 (root).
81 """
82 if os.geteuid() != 0:
83 hline()
84 msg("Xend must be run as root.")
85 hline()
86 raise CheckError("invalid user")
88 def main():
89 try:
90 check_logging()
91 check_twisted_version()
92 check_user()
93 except CheckError:
94 sys.exit(1)
95 from xen.xend.server import SrvDaemon
96 daemon = SrvDaemon.instance()
97 if not sys.argv[1:]:
98 print 'usage: %s {start|stop|restart}' % sys.argv[0]
99 elif os.fork():
100 pid, status = os.wait()
101 return status >> 8
102 elif sys.argv[1] == 'start':
103 return daemon.start()
104 elif sys.argv[1] == 'trace_start':
105 return daemon.start(trace=1)
106 elif sys.argv[1] == 'stop':
107 return daemon.stop()
108 elif sys.argv[1] == 'restart':
109 return daemon.stop() or daemon.start()
110 else:
111 print 'not an option:', sys.argv[1]
112 return 1
114 if __name__ == '__main__':
115 sys.exit(main())