|
|
befec2e |
diff -up xen-3.4.0/tools/misc/xend.fix xen-3.4.0/tools/misc/xend
|
|
|
befec2e |
--- xen-3.4.0/tools/misc/xend.fix 2009-05-20 15:39:12.000000000 +0200
|
|
|
befec2e |
+++ xen-3.4.0/tools/misc/xend 2009-05-20 15:40:32.000000000 +0200
|
|
|
befec2e |
@@ -8,140 +8,16 @@
|
|
|
6645a82 |
"""Xen management daemon.
|
|
|
6645a82 |
Provides console server and HTTP management api.
|
|
|
6645a82 |
|
|
|
6645a82 |
- Run:
|
|
|
6645a82 |
- xend start
|
|
|
6645a82 |
-
|
|
|
6645a82 |
- Restart:
|
|
|
6645a82 |
- xend restart
|
|
|
6645a82 |
-
|
|
|
6645a82 |
- The daemon is stopped with:
|
|
|
6645a82 |
- xend stop
|
|
|
6645a82 |
-
|
|
|
6645a82 |
The daemon should reconnect to device control interfaces
|
|
|
6645a82 |
and recover its state when restarted.
|
|
|
befec2e |
|
|
|
6645a82 |
- On Solaris, the daemons are SMF managed, and you should not attempt
|
|
|
6645a82 |
- to start xend by hand.
|
|
|
6645a82 |
"""
|
|
|
5d197d9 |
-import fcntl
|
|
|
5d197d9 |
-import glob
|
|
|
6645a82 |
-import os
|
|
|
6645a82 |
-import os.path
|
|
|
6645a82 |
import sys
|
|
|
6645a82 |
-import socket
|
|
|
6645a82 |
-import signal
|
|
|
6645a82 |
-import time
|
|
|
6645a82 |
-import commands
|
|
|
6645a82 |
-
|
|
|
6645a82 |
from xen.xend.server import SrvDaemon
|
|
|
6645a82 |
|
|
|
6645a82 |
-class CheckError(ValueError):
|
|
|
6645a82 |
- pass
|
|
|
6645a82 |
-
|
|
|
6645a82 |
-def hline():
|
|
|
6645a82 |
- print >>sys.stderr, "*" * 70
|
|
|
6645a82 |
-
|
|
|
6645a82 |
-def msg(message):
|
|
|
6645a82 |
- print >>sys.stderr, "*" * 3, message
|
|
|
6645a82 |
-
|
|
|
6645a82 |
-def check_logging():
|
|
|
6645a82 |
- """Check python logging is installed and raise an error if not.
|
|
|
6645a82 |
- Logging is standard from Python 2.3 on.
|
|
|
6645a82 |
- """
|
|
|
6645a82 |
- try:
|
|
|
6645a82 |
- import logging
|
|
|
6645a82 |
- except ImportError:
|
|
|
6645a82 |
- hline()
|
|
|
6645a82 |
- msg("Python logging is not installed.")
|
|
|
6645a82 |
- msg("Use 'make install-logging' at the xen root to install.")
|
|
|
6645a82 |
- msg("")
|
|
|
6645a82 |
- msg("Alternatively download and install from")
|
|
|
6645a82 |
- msg("http://www.red-dove.com/python_logging.html")
|
|
|
6645a82 |
- hline()
|
|
|
6645a82 |
- raise CheckError("logging is not installed")
|
|
|
6645a82 |
-
|
|
|
6645a82 |
-def check_user():
|
|
|
6645a82 |
- """Check that the effective user id is 0 (root).
|
|
|
6645a82 |
- """
|
|
|
6645a82 |
- if os.geteuid() != 0:
|
|
|
6645a82 |
- hline()
|
|
|
6645a82 |
- msg("Xend must be run as root.")
|
|
|
6645a82 |
- hline()
|
|
|
6645a82 |
- raise CheckError("invalid user")
|
|
|
6645a82 |
-
|
|
|
77513e5 |
-def start_daemon(daemon, *args):
|
|
|
77513e5 |
- if os.fork() == 0:
|
|
|
77513e5 |
- os.execvp(daemon, (daemon,) + args)
|
|
|
77513e5 |
-
|
|
|
6645a82 |
-def start_xenstored():
|
|
|
5d197d9 |
- pidfname = "/var/run/xenstore.pid"
|
|
|
5d197d9 |
- try:
|
|
|
5d197d9 |
- f = open(pidfname, "a")
|
|
|
5d197d9 |
- try:
|
|
|
5d197d9 |
- fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
|
5d197d9 |
- rootdir = os.getenv("XENSTORED_ROOTDIR") or "/var/lib/xenstored"
|
|
|
5d197d9 |
- for i in glob.glob(rootdir + "/tdb*"):
|
|
|
5d197d9 |
- try:
|
|
|
5d197d9 |
- os.unlink(i)
|
|
|
5d197d9 |
- except:
|
|
|
5d197d9 |
- pass
|
|
|
5d197d9 |
- os.unlink(pidfname)
|
|
|
5d197d9 |
- except:
|
|
|
5d197d9 |
- pass
|
|
|
5d197d9 |
- f.close()
|
|
|
5d197d9 |
- except:
|
|
|
5d197d9 |
- pass
|
|
|
6645a82 |
- XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
|
|
|
6645a82 |
- cmd = "xenstored --pid-file /var/run/xenstore.pid"
|
|
|
6645a82 |
- if XENSTORED_TRACE:
|
|
|
6645a82 |
- cmd += " -T /var/log/xen/xenstored-trace.log"
|
|
|
6645a82 |
- s,o = commands.getstatusoutput(cmd)
|
|
|
6645a82 |
-
|
|
|
6645a82 |
-def start_consoled():
|
|
|
77513e5 |
- XENCONSOLED_TRACE = os.getenv("XENCONSOLED_TRACE")
|
|
|
77513e5 |
- args = ""
|
|
|
77513e5 |
- if XENCONSOLED_TRACE:
|
|
|
77513e5 |
- args += "--log=" + XENCONSOLED_TRACE
|
|
|
77513e5 |
- start_daemon("xenconsoled", args)
|
|
|
6645a82 |
-
|
|
|
6645a82 |
-def start_blktapctrl():
|
|
|
77513e5 |
- start_daemon("blktapctrl", "")
|
|
|
77513e5 |
-
|
|
|
6645a82 |
def main():
|
|
|
6645a82 |
- try:
|
|
|
6645a82 |
- check_logging()
|
|
|
6645a82 |
- check_user()
|
|
|
6645a82 |
- except CheckError:
|
|
|
6645a82 |
- sys.exit(1)
|
|
|
6645a82 |
-
|
|
|
6645a82 |
daemon = SrvDaemon.instance()
|
|
|
6645a82 |
- if not sys.argv[1:]:
|
|
|
6645a82 |
- print 'usage: %s {start|stop|reload|restart}' % sys.argv[0]
|
|
|
6645a82 |
- elif sys.argv[1] == 'start':
|
|
|
6645a82 |
- if os.uname()[0] != "SunOS":
|
|
|
6645a82 |
- start_xenstored()
|
|
|
6645a82 |
- start_consoled()
|
|
|
6645a82 |
- start_blktapctrl()
|
|
|
6645a82 |
- return daemon.start()
|
|
|
6645a82 |
- elif sys.argv[1] == 'trace_start':
|
|
|
6645a82 |
- start_xenstored()
|
|
|
6645a82 |
- start_consoled()
|
|
|
6645a82 |
- start_blktapctrl()
|
|
|
6645a82 |
- return daemon.start(trace=1)
|
|
|
6645a82 |
- elif sys.argv[1] == 'stop':
|
|
|
6645a82 |
- return daemon.stop()
|
|
|
6645a82 |
- elif sys.argv[1] == 'reload':
|
|
|
6645a82 |
- return daemon.reloadConfig()
|
|
|
6645a82 |
- elif sys.argv[1] == 'restart':
|
|
|
6645a82 |
- start_xenstored()
|
|
|
6645a82 |
- start_consoled()
|
|
|
6645a82 |
- start_blktapctrl()
|
|
|
6645a82 |
- return daemon.stop() or daemon.start()
|
|
|
6645a82 |
- elif sys.argv[1] == 'status':
|
|
|
6645a82 |
- return daemon.status()
|
|
|
6645a82 |
- else:
|
|
|
6645a82 |
- print 'not an option:', sys.argv[1]
|
|
|
6645a82 |
- return 1
|
|
|
6645a82 |
+ return daemon.start()
|
|
|
6645a82 |
|
|
|
6645a82 |
if __name__ == '__main__':
|
|
|
6645a82 |
sys.exit(main())
|
|
|
befec2e |
diff -up xen-3.4.0/tools/python/xen/xend/osdep.py.fix xen-3.4.0/tools/python/xen/xend/osdep.py
|
|
|
befec2e |
--- xen-3.4.0/tools/python/xen/xend/osdep.py.fix 2009-05-18 13:05:38.000000000 +0200
|
|
|
befec2e |
+++ xen-3.4.0/tools/python/xen/xend/osdep.py 2009-05-20 15:39:18.000000000 +0200
|
|
|
befec2e |
@@ -27,7 +27,7 @@ _scripts_dir = {
|
|
|
6645a82 |
|
|
|
6645a82 |
_xend_autorestart = {
|
|
|
5d197d9 |
"NetBSD": True,
|
|
|
6645a82 |
- "Linux": True,
|
|
|
6645a82 |
+ "Linux": False,
|
|
|
6645a82 |
"SunOS": False,
|
|
|
6645a82 |
}
|
|
|
6645a82 |
|
|
|
befec2e |
diff -up xen-3.4.0/tools/python/xen/xend/server/SrvDaemon.py.fix xen-3.4.0/tools/python/xen/xend/server/SrvDaemon.py
|
|
|
befec2e |
--- xen-3.4.0/tools/python/xen/xend/server/SrvDaemon.py.fix 2009-05-18 13:05:38.000000000 +0200
|
|
|
befec2e |
+++ xen-3.4.0/tools/python/xen/xend/server/SrvDaemon.py 2009-05-20 15:39:18.000000000 +0200
|
|
|
befec2e |
@@ -110,7 +110,14 @@ class Daemon:
|
|
|
6645a82 |
# Fork, this allows the group leader to exit,
|
|
|
6645a82 |
# which means the child can never again regain control of the
|
|
|
6645a82 |
# terminal
|
|
|
6645a82 |
- if os.fork():
|
|
|
6645a82 |
+ child = os.fork()
|
|
|
6645a82 |
+ if child:
|
|
|
6645a82 |
+ if not osdep.xend_autorestart:
|
|
|
6645a82 |
+ pidfile = open(XEND_PID_FILE, 'w')
|
|
|
6645a82 |
+ try:
|
|
|
6645a82 |
+ pidfile.write(str(child))
|
|
|
6645a82 |
+ finally:
|
|
|
6645a82 |
+ pidfile.close()
|
|
|
6645a82 |
os._exit(0)
|
|
|
6645a82 |
|
|
|
6645a82 |
# Detach from standard file descriptors, and redirect them to
|