ia64/xen-unstable

view tools/misc/xend @ 6946:e703abaf6e3d

Add behaviour to the remove methods to remove the transaction's path itself. This allows us to write Remove(path) to remove the specified path rather than having to slice the path ourselves.
author emellor@ewan
date Sun Sep 18 14:42:13 2005 +0100 (2005-09-18)
parents 3233e7ecfa9f
children 06d84bf87159
line source
1 #!/usr/bin/env python
2 # -*- mode: python; -*-
3 #============================================================================
4 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
5 #============================================================================
7 """Xen management daemon. Lives in /usr/sbin.
8 Provides console server and HTTP management api.
10 Run:
11 xend start
13 Restart:
14 xend restart
16 The daemon is stopped with:
17 xend stop
19 The daemon should reconnect to device control interfaces
20 and recover its state when restarted.
21 """
22 import os
23 import sys
24 import socket
25 import signal
26 import time
27 import commands
29 # add fallback path for non-native python path installs if needed
30 sys.path.append('/usr/lib/python')
31 sys.path.append('/usr/lib64/python')
32 from xen.xend.server import SrvDaemon
34 class CheckError(ValueError):
35 pass
37 def hline():
38 print >>sys.stderr, "*" * 70
40 def msg(message):
41 print >>sys.stderr, "*" * 3, message
43 def check_logging():
44 """Check python logging is installed and raise an error if not.
45 Logging is standard from Python 2.3 on.
46 """
47 try:
48 import logging
49 except ImportError:
50 hline()
51 msg("Python logging is not installed.")
52 msg("Use 'make install-logging' at the xen root to install.")
53 msg("")
54 msg("Alternatively download and install from")
55 msg("http://www.red-dove.com/python_logging.html")
56 hline()
57 raise CheckError("logging is not installed")
59 def check_user():
60 """Check that the effective user id is 0 (root).
61 """
62 if os.geteuid() != 0:
63 hline()
64 msg("Xend must be run as root.")
65 hline()
66 raise CheckError("invalid user")
68 def start_xenstored():
69 XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
70 cmd = "/usr/sbin/xenstored --pid-file=/var/run/xenstore.pid"
71 if XENSTORED_TRACE:
72 cmd += " -T /var/log/xenstored-trace.log"
73 s,o = commands.getstatusoutput(cmd)
75 def start_consoled():
76 if os.fork() == 0:
77 os.execvp('/usr/sbin/xenconsoled', ['/usr/sbin/xenconsoled'])
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|restart}' % sys.argv[0]
89 elif sys.argv[1] == 'start':
90 start_xenstored()
91 start_consoled()
92 return daemon.start()
93 elif sys.argv[1] == 'trace_start':
94 start_xenstored()
95 start_consoled()
96 return daemon.start(trace=1)
97 elif sys.argv[1] == 'stop':
98 return daemon.stop()
99 elif sys.argv[1] == 'restart':
100 start_xenstored()
101 start_consoled()
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())