debuggers.hg

annotate 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
rev   line source
mjw@1661 1 #!/usr/bin/env python
mjw@1661 2 # -*- mode: python; -*-
mjw@1661 3 #============================================================================
mjw@1661 4 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
emellor@9987 5 # Copyright (C) 2005-2006 XenSource Inc
mjw@1661 6 #============================================================================
mjw@1661 7
emellor@7347 8 """Xen management daemon.
mjw@1661 9 Provides console server and HTTP management api.
mjw@1661 10
mjw@1661 11 Run:
mjw@1661 12 xend start
mjw@1661 13
kaf24@2534 14 Restart:
kaf24@2534 15 xend restart
kaf24@2534 16
mjw@1661 17 The daemon is stopped with:
mjw@1661 18 xend stop
mjw@1661 19
mjw@1661 20 The daemon should reconnect to device control interfaces
mjw@1661 21 and recover its state when restarted.
kfraser@11825 22
kfraser@11825 23 On Solaris, the daemons are SMF managed, and you should not attempt
kfraser@11825 24 to start xend by hand.
mjw@1661 25 """
keir@16361 26 import fcntl
keir@16361 27 import glob
mjw@1661 28 import os
emellor@9987 29 import os.path
mjw@1661 30 import sys
kaf24@3404 31 import socket
akw27@4174 32 import signal
kaf24@3404 33 import time
cl349@6109 34 import commands
kaf24@3404 35
kaf24@2864 36 from xen.xend.server import SrvDaemon
kaf24@2864 37
mjw@1881 38 class CheckError(ValueError):
mjw@1881 39 pass
mjw@1881 40
mjw@1881 41 def hline():
mjw@1881 42 print >>sys.stderr, "*" * 70
mjw@1881 43
mjw@1881 44 def msg(message):
mjw@1881 45 print >>sys.stderr, "*" * 3, message
mjw@1881 46
mjw@1881 47 def check_logging():
mjw@1881 48 """Check python logging is installed and raise an error if not.
mjw@1881 49 Logging is standard from Python 2.3 on.
mjw@1881 50 """
mjw@1881 51 try:
mjw@1881 52 import logging
mjw@1881 53 except ImportError:
mjw@1881 54 hline()
mjw@1881 55 msg("Python logging is not installed.")
mjw@1881 56 msg("Use 'make install-logging' at the xen root to install.")
mjw@1881 57 msg("")
mjw@1881 58 msg("Alternatively download and install from")
mjw@1881 59 msg("http://www.red-dove.com/python_logging.html")
mjw@1881 60 hline()
mjw@1881 61 raise CheckError("logging is not installed")
mjw@1661 62
mjw@1881 63 def check_user():
mjw@1881 64 """Check that the effective user id is 0 (root).
mjw@1881 65 """
mjw@1881 66 if os.geteuid() != 0:
mjw@1881 67 hline()
mjw@1881 68 msg("Xend must be run as root.")
mjw@1881 69 hline()
mjw@1881 70 raise CheckError("invalid user")
kaf24@3404 71
keir@18360 72 def start_daemon(daemon, *args):
keir@18360 73 if os.fork() == 0:
keir@18360 74 os.execvp(daemon, (daemon,) + args)
keir@18360 75
jchesterfield@10715 76 def start_blktapctrl():
keir@18360 77 start_daemon("blktapctrl", "")
keir@18360 78
mjw@1661 79 def main():
mjw@1881 80 try:
mjw@1881 81 check_logging()
mjw@1881 82 check_user()
mjw@1881 83 except CheckError:
mjw@1881 84 sys.exit(1)
akw27@4174 85
mjw@1661 86 daemon = SrvDaemon.instance()
mjw@1661 87 if not sys.argv[1:]:
ewan@12764 88 print 'usage: %s {start|stop|reload|restart}' % sys.argv[0]
mjw@1661 89 elif sys.argv[1] == 'start':
kfraser@11825 90 if os.uname()[0] != "SunOS":
kfraser@11825 91 start_blktapctrl()
mjw@1661 92 return daemon.start()
mjw@1661 93 elif sys.argv[1] == 'trace_start':
jchesterfield@10715 94 start_blktapctrl()
mjw@1661 95 return daemon.start(trace=1)
mjw@1661 96 elif sys.argv[1] == 'stop':
mjw@1661 97 return daemon.stop()
ewan@12764 98 elif sys.argv[1] == 'reload':
ewan@12764 99 return daemon.reloadConfig()
mjw@1661 100 elif sys.argv[1] == 'restart':
jchesterfield@10715 101 start_blktapctrl()
mjw@1661 102 return daemon.stop() or daemon.start()
kaf24@2534 103 elif sys.argv[1] == 'status':
kaf24@2534 104 return daemon.status()
mjw@1661 105 else:
mjw@1661 106 print 'not an option:', sys.argv[1]
mjw@1661 107 return 1
mjw@1661 108
mjw@1661 109 if __name__ == '__main__':
mjw@1661 110 sys.exit(main())