direct-io.hg

view tools/misc/xend @ 7477:5a7baecb1c70

Fix an issue for passing arguement from control panel to deivce model
for some arguemnt like 'localtime', 'isa', device model need an argument
"-localtime", instead of "-localtime 1"
Signed-off-by: Xiaofeng Ling <xiaofeng.ling@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Sun Oct 23 16:51:47 2005 +0100 (2005-10-23)
parents 903d88857972
children d61fc1f33954
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 XenSource Ltd
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 sys
25 import socket
26 import signal
27 import time
28 import commands
30 # add fallback path for non-native python path installs if needed
31 sys.path.append('/usr/lib/python')
32 sys.path.append('/usr/lib64/python')
33 from xen.xend.server import SrvDaemon
35 class CheckError(ValueError):
36 pass
38 def hline():
39 print >>sys.stderr, "*" * 70
41 def msg(message):
42 print >>sys.stderr, "*" * 3, message
44 def check_logging():
45 """Check python logging is installed and raise an error if not.
46 Logging is standard from Python 2.3 on.
47 """
48 try:
49 import logging
50 except ImportError:
51 hline()
52 msg("Python logging is not installed.")
53 msg("Use 'make install-logging' at the xen root to install.")
54 msg("")
55 msg("Alternatively download and install from")
56 msg("http://www.red-dove.com/python_logging.html")
57 hline()
58 raise CheckError("logging is not installed")
60 def check_user():
61 """Check that the effective user id is 0 (root).
62 """
63 if os.geteuid() != 0:
64 hline()
65 msg("Xend must be run as root.")
66 hline()
67 raise CheckError("invalid user")
69 def start_xenstored():
70 XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
71 cmd = "xenstored --pid-file=/var/run/xenstore.pid"
72 if XENSTORED_TRACE:
73 cmd += " -T /var/log/xenstored-trace.log"
74 s,o = commands.getstatusoutput(cmd)
76 def start_consoled():
77 if os.fork() == 0:
78 os.execvp('xenconsoled', ['xenconsoled'])
80 def main():
81 try:
82 check_logging()
83 check_user()
84 except CheckError:
85 sys.exit(1)
87 daemon = SrvDaemon.instance()
88 if not sys.argv[1:]:
89 print 'usage: %s {start|stop|restart}' % sys.argv[0]
90 elif sys.argv[1] == 'start':
91 start_xenstored()
92 start_consoled()
93 return daemon.start()
94 elif sys.argv[1] == 'trace_start':
95 start_xenstored()
96 start_consoled()
97 return daemon.start(trace=1)
98 elif sys.argv[1] == 'stop':
99 return daemon.stop()
100 elif sys.argv[1] == 'restart':
101 start_xenstored()
102 start_consoled()
103 return daemon.stop() or daemon.start()
104 elif sys.argv[1] == 'status':
105 return daemon.status()
106 else:
107 print 'not an option:', sys.argv[1]
108 return 1
110 if __name__ == '__main__':
111 sys.exit(main())