ia64/xen-unstable

view tools/misc/xend @ 10945:164ad1411255

remove '=' between command line name/argument.
ease parsing without getopt.

Signed-off-by: Vincent Hanquez <vincent@xensource.com>
author vhanquez@gwig.uk.xensource.com
date Thu Aug 03 13:44:05 2006 +0000 (2006-08-03)
parents 2937703f0ed0
children 3798ec84431d
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.
22 """
23 import os
24 import os.path
25 import sys
26 import socket
27 import signal
28 import time
29 import commands
32 # Use the auxbin module in Xend to determine the correct Python path. We
33 # take the first installed instance of auxbin that we find, and then run it
34 # to determine the correct path, appending that to sys.path.
36 AUXBIN = 'xen/util/auxbin.py'
38 for p in ['python%s' % sys.version[:3], 'python']:
39 for l in ['/usr/lib64', '/usr/lib']:
40 d = os.path.join(l, p)
41 if os.path.exists(os.path.join(d, AUXBIN)):
42 sys.path.append(d)
43 import xen.util.auxbin
44 libpath = xen.util.auxbin.libpath()
45 sys.path = sys.path[:-1]
46 sys.path.append(libpath)
47 break
49 from xen.xend.server import SrvDaemon
51 class CheckError(ValueError):
52 pass
54 def hline():
55 print >>sys.stderr, "*" * 70
57 def msg(message):
58 print >>sys.stderr, "*" * 3, message
60 def check_logging():
61 """Check python logging is installed and raise an error if not.
62 Logging is standard from Python 2.3 on.
63 """
64 try:
65 import logging
66 except ImportError:
67 hline()
68 msg("Python logging is not installed.")
69 msg("Use 'make install-logging' at the xen root to install.")
70 msg("")
71 msg("Alternatively download and install from")
72 msg("http://www.red-dove.com/python_logging.html")
73 hline()
74 raise CheckError("logging is not installed")
76 def check_user():
77 """Check that the effective user id is 0 (root).
78 """
79 if os.geteuid() != 0:
80 hline()
81 msg("Xend must be run as root.")
82 hline()
83 raise CheckError("invalid user")
85 def start_xenstored():
86 XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
87 cmd = "xenstored --pid-file /var/run/xenstore.pid"
88 if XENSTORED_TRACE:
89 cmd += " -T /var/log/xenstored-trace.log"
90 s,o = commands.getstatusoutput(cmd)
92 def start_consoled():
93 if os.fork() == 0:
94 os.execvp('xenconsoled', ['xenconsoled'])
96 def start_blktapctrl():
97 if os.fork() == 0:
98 os.execvp('blktapctrl', ['blktapctrl'])
100 def main():
101 try:
102 check_logging()
103 check_user()
104 except CheckError:
105 sys.exit(1)
107 daemon = SrvDaemon.instance()
108 if not sys.argv[1:]:
109 print 'usage: %s {start|stop|restart}' % sys.argv[0]
110 elif sys.argv[1] == 'start':
111 start_xenstored()
112 start_consoled()
113 start_blktapctrl()
114 return daemon.start()
115 elif sys.argv[1] == 'trace_start':
116 start_xenstored()
117 start_consoled()
118 start_blktapctrl()
119 return daemon.start(trace=1)
120 elif sys.argv[1] == 'stop':
121 return daemon.stop()
122 elif sys.argv[1] == 'restart':
123 start_xenstored()
124 start_consoled()
125 start_blktapctrl()
126 return daemon.stop() or daemon.start()
127 elif sys.argv[1] == 'status':
128 return daemon.status()
129 else:
130 print 'not an option:', sys.argv[1]
131 return 1
133 if __name__ == '__main__':
134 sys.exit(main())