debuggers.hg

view tools/misc/xend @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents 8bcaec29574e
children
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.
23 On Solaris, the daemons are SMF managed, and you should not attempt
24 to start xend by hand.
25 """
26 import fcntl
27 import glob
28 import os
29 import os.path
30 import sys
31 import socket
32 import signal
33 import time
34 import commands
36 from xen.xend.server import SrvDaemon
38 class CheckError(ValueError):
39 pass
41 def hline():
42 print >>sys.stderr, "*" * 70
44 def msg(message):
45 print >>sys.stderr, "*" * 3, message
47 def check_logging():
48 """Check python logging is installed and raise an error if not.
49 Logging is standard from Python 2.3 on.
50 """
51 try:
52 import logging
53 except ImportError:
54 hline()
55 msg("Python logging is not installed.")
56 msg("Use 'make install-logging' at the xen root to install.")
57 msg("")
58 msg("Alternatively download and install from")
59 msg("http://www.red-dove.com/python_logging.html")
60 hline()
61 raise CheckError("logging is not installed")
63 def check_user():
64 """Check that the effective user id is 0 (root).
65 """
66 if os.geteuid() != 0:
67 hline()
68 msg("Xend must be run as root.")
69 hline()
70 raise CheckError("invalid user")
72 def start_daemon(daemon, *args):
73 if os.fork() == 0:
74 os.execvp(daemon, (daemon,) + args)
76 def start_blktapctrl():
77 start_daemon("blktapctrl", "")
79 def main():
80 try:
81 check_logging()
82 check_user()
83 except CheckError:
84 sys.exit(1)
86 daemon = SrvDaemon.instance()
87 if not sys.argv[1:]:
88 print 'usage: %s {start|stop|reload|restart}' % sys.argv[0]
89 elif sys.argv[1] == 'start':
90 if os.uname()[0] != "SunOS":
91 start_blktapctrl()
92 return daemon.start()
93 elif sys.argv[1] == 'trace_start':
94 start_blktapctrl()
95 return daemon.start(trace=1)
96 elif sys.argv[1] == 'stop':
97 return daemon.stop()
98 elif sys.argv[1] == 'reload':
99 return daemon.reloadConfig()
100 elif sys.argv[1] == 'restart':
101 start_blktapctrl()
102 return daemon.stop() or daemon.start()
103 elif sys.argv[1] == 'status':
104 return daemon.status()
105 else:
106 print 'not an option:', sys.argv[1]
107 return 1
109 if __name__ == '__main__':
110 sys.exit(main())