ia64/xen-unstable

view tools/misc/xend @ 2570:30a9b33481dc

bitkeeper revision 1.1159.90.2 (415be9d5hTw1zLV9fA-AYcekmwhMwg)

Discard devices early for local migrate.
author mjw@wray-m-3.hpl.hp.com
date Thu Sep 30 11:11:17 2004 +0000 (2004-09-30)
parents c7b0154dff73
children 4bf285a87365 eb0280fe0abf
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:
11 xend start
13 Restart:
14 xend restart
16 The daemon is stopped with:
17 xend stop
19 The daemon should reconnect to device control interfaces
20 and recover its state when restarted.
21 """
22 import os
23 import sys
25 class CheckError(ValueError):
26 pass
28 def hline():
29 print >>sys.stderr, "*" * 70
31 def msg(message):
32 print >>sys.stderr, "*" * 3, message
34 def check_logging():
35 """Check python logging is installed and raise an error if not.
36 Logging is standard from Python 2.3 on.
37 """
38 try:
39 import logging
40 except ImportError:
41 hline()
42 msg("Python logging is not installed.")
43 msg("Use 'make install-logging' at the xen root to install.")
44 msg("")
45 msg("Alternatively download and install from")
46 msg("http://www.red-dove.com/python_logging.html")
47 hline()
48 raise CheckError("logging is not installed")
50 def check_twisted_version():
51 """Check twisted is installed with a supported version and print a warning if not.
52 Raises an error if twisted is not installed.
53 """
54 # Supported twisted release and major version.
55 RELEASE = 1
56 MAJOR = 3
57 try:
58 from twisted.copyright import version
59 except ImportError:
60 hline()
61 msg("The Twisted framework is not installed.")
62 msg("Use 'make install-twisted' at the xen root to install.")
63 msg("")
64 msg("Alternatively download and install version %d.%d or higher" % (RELEASE, MAJOR))
65 msg("from http://www.twistedmatrix.com/products")
66 hline()
67 raise CheckError("twisted is not installed")
70 (release, major, minor) = version.split('.')
71 release = int(release)
72 major = int(major)
73 if release > RELEASE: return
74 if release == RELEASE and major >= MAJOR: return
75 hline()
76 msg("Warning: Twisted version not supported: %s" % version)
77 msg("Use Twisted version %d.%d.0 or higher" % (RELEASE, MAJOR))
78 hline()
80 def check_user():
81 """Check that the effective user id is 0 (root).
82 """
83 if os.geteuid() != 0:
84 hline()
85 msg("Xend must be run as root.")
86 hline()
87 raise CheckError("invalid user")
89 def main():
90 try:
91 check_logging()
92 check_twisted_version()
93 check_user()
94 except CheckError:
95 sys.exit(1)
96 from xen.xend.server import SrvDaemon
97 daemon = SrvDaemon.instance()
98 if not sys.argv[1:]:
99 print 'usage: %s {start|stop|restart}' % sys.argv[0]
100 elif os.fork():
101 pid, status = os.wait()
102 return status >> 8
103 elif sys.argv[1] == 'start':
104 return daemon.start()
105 elif sys.argv[1] == 'trace_start':
106 return daemon.start(trace=1)
107 elif sys.argv[1] == 'stop':
108 return daemon.stop()
109 elif sys.argv[1] == 'restart':
110 return daemon.stop() or daemon.start()
111 elif sys.argv[1] == 'status':
112 return daemon.status()
113 else:
114 print 'not an option:', sys.argv[1]
115 return 1
117 if __name__ == '__main__':
118 sys.exit(main())