ia64/xen-unstable

view tools/misc/xensv @ 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 75c62d5f88c3
children 4bf285a87365 eb0280fe0abf
line source
1 #!/usr/bin/env python
2 # -*- mode: python; -*-
3 #============================================================================
4 # Copyright (C) 2004 Tom Wilkie <tw275@cl.cam.ac.uk>
5 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
6 #============================================================================
8 """SV web interface Lives in /usr/sbin.
9 Provides pretty HTML management interface.
11 Run:
13 sv start
15 The daemon is stopped with:
17 sv stop
19 The daemon will be accessible from http://localhost:8080/
20 """
21 import os
22 import sys
23 import re
25 from xen.xend.server.params import XEND_PID_FILE
27 class CheckError(ValueError):
28 pass
30 def hline():
31 print >>sys.stderr, "*" * 70
33 def msg(message):
34 print >>sys.stderr, "*" * 3, message
36 def check_logging():
37 """Check python logging is installed and raise an error if not.
38 Logging is standard from Python 2.3 on.
39 """
40 try:
41 import logging
42 except ImportError:
43 hline()
44 msg("Python logging is not installed.")
45 msg("Use 'make install-logging' at the xen root to install.")
46 msg("")
47 msg("Alternatively download and install from")
48 msg("http://www.red-dove.com/python_logging.html")
49 hline()
50 raise CheckError("logging is not installed")
52 def check_twisted_version():
53 """Check twisted is installed with a supported version and print a warning if not.
54 Raises an error if twisted is not installed.
55 """
56 # Supported twisted release and major version.
57 RELEASE = 1
58 MAJOR = 3
59 try:
60 from twisted.copyright import version
61 except ImportError:
62 hline()
63 msg("The Twisted framework is not installed.")
64 msg("Use 'make install-twisted' at the xen root to install.")
65 msg("")
66 msg("Alternatively download and install version %d.%d or higher" % (RELEASE, MAJOR))
67 msg("from http://www.twistedmatrix.com/products")
68 hline()
69 raise CheckError("twisted is not installed")
72 (release, major, minor) = version.split('.')
73 release = int(release)
74 major = int(major)
75 if release > RELEASE: return
76 if release == RELEASE and major >= MAJOR: return
77 hline()
78 msg("Warning: Twisted version not supported: %s" % version)
79 msg("Use Twisted version %d.%d.0 or higher" % (RELEASE, MAJOR))
80 hline()
82 def check_xend():
83 """Check xend is running
84 """
86 if not os.path.isfile(XEND_PID_FILE) or not os.path.getsize(XEND_PID_FILE):
87 hline()
88 msg( "Warning: Xend has not been detected as running." )
89 msg( "Please start it immediately with: xend start " )
90 hline()
91 return 0
93 # Read the pid of the previous invocation and search active process list.
94 pid = open(XEND_PID_FILE, 'r').read()
95 lines = os.popen('ps ' + pid + ' 2>/dev/null').readlines()
96 for line in lines:
97 if re.search('^ *' + pid + '.+xend', line):
98 return 1
100 hline()
101 msg( "Warning: Xend has not been detected as running." )
102 msg( "Please start it immediately with: xend start " )
103 hline()
104 return 0
106 def main():
107 try:
108 check_logging()
109 check_twisted_version()
110 check_xend()
111 except CheckError:
112 sys.exit(1)
114 from xen.sv import Daemon
116 daemon = Daemon.instance()
118 if not sys.argv[1:]:
119 print 'usage: %s {start|stop|restart}' % sys.argv[0]
120 elif os.fork():
121 pid, status = os.wait()
122 return status >> 8
123 elif sys.argv[1] == 'start':
124 return daemon.start()
125 elif sys.argv[1] == 'stop':
126 return daemon.stop()
127 elif sys.argv[1] == 'restart':
128 return daemon.stop() or daemon.start()
129 else:
130 print 'not an option:', sys.argv[1]
131 return 1
133 if __name__ == '__main__':
134 sys.exit(main())