direct-io.hg

view tools/misc/xensv @ 4651:3b385d58d823

bitkeeper revision 1.1378 (426ca26eUpP7OInuOBvTyETb6y9VRQ)

Add /usr/lib64/python to the path for python tools so that they can be
found on 64-bit platforms.
Signed-off-by: Jerone Young <jyoung@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Apr 25 07:55:26 2005 +0000 (2005-04-25)
parents 189085197f6d
children
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 # add fallback path for non-native python path installs if needed
26 sys.path.append('/usr/lib/python')
27 sys.path.append('/usr/lib64/python')
28 from xen.xend.server.params import XEND_PID_FILE
30 class CheckError(ValueError):
31 pass
33 def hline():
34 print >>sys.stderr, "*" * 70
36 def msg(message):
37 print >>sys.stderr, "*" * 3, message
39 def check_logging():
40 """Check python logging is installed and raise an error if not.
41 Logging is standard from Python 2.3 on.
42 """
43 try:
44 import logging
45 except ImportError:
46 hline()
47 msg("Python logging is not installed.")
48 msg("Use 'make install-logging' at the xen root to install.")
49 msg("")
50 msg("Alternatively download and install from")
51 msg("http://www.red-dove.com/python_logging.html")
52 hline()
53 raise CheckError("logging is not installed")
55 def check_twisted_version():
56 """Check twisted is installed with a supported version and print a warning if not.
57 Raises an error if twisted is not installed.
58 """
59 # Supported twisted release and major version.
60 RELEASE = 1
61 MAJOR = 3
62 try:
63 from twisted.copyright import version
64 except ImportError:
65 hline()
66 msg("The Twisted framework is not installed.")
67 msg("Use 'make install-twisted' at the xen root to install.")
68 msg("")
69 msg("Alternatively download and install version %d.%d or higher" % (RELEASE, MAJOR))
70 msg("from http://www.twistedmatrix.com/products")
71 hline()
72 raise CheckError("twisted is not installed")
75 (release, major, minor) = version.split('.')
76 release = int(release)
77 major = int(major)
78 if release > RELEASE: return
79 if release == RELEASE and major >= MAJOR: return
80 hline()
81 msg("Warning: Twisted version not supported: %s" % version)
82 msg("Use Twisted version %d.%d.0 or higher" % (RELEASE, MAJOR))
83 hline()
85 def check_xend():
86 """Check xend is running
87 """
89 if not os.path.isfile(XEND_PID_FILE) or not os.path.getsize(XEND_PID_FILE):
90 hline()
91 msg( "Warning: Xend has not been detected as running." )
92 msg( "Please start it immediately with: xend start " )
93 hline()
94 return 0
96 # Read the pid of the previous invocation and search active process list.
97 pid = open(XEND_PID_FILE, 'r').read()
98 lines = os.popen('ps ' + pid + ' 2>/dev/null').readlines()
99 for line in lines:
100 if re.search('^ *' + pid + '.+xend', line):
101 return 1
103 hline()
104 msg( "Warning: Xend has not been detected as running." )
105 msg( "Please start it immediately with: xend start " )
106 hline()
107 return 0
109 def main():
110 try:
111 check_logging()
112 check_twisted_version()
113 check_xend()
114 except CheckError:
115 sys.exit(1)
117 from xen.sv import Daemon
119 daemon = Daemon.instance()
121 if not sys.argv[1:]:
122 print 'usage: %s {start|stop|restart}' % sys.argv[0]
123 elif os.fork():
124 pid, status = os.wait()
125 return status >> 8
126 elif sys.argv[1] == 'start':
127 return daemon.start()
128 elif sys.argv[1] == 'stop':
129 return daemon.stop()
130 elif sys.argv[1] == 'restart':
131 return daemon.stop() or daemon.start()
132 else:
133 print 'not an option:', sys.argv[1]
134 return 1
136 if __name__ == '__main__':
137 sys.exit(main())