ia64/xen-unstable

view tools/misc/xend @ 12786:59f438d2739b

Added rudimentary "xend reload" functionality. This allows you to reconfigure
the services offered by Xend, without restarting the daemon itself.

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