WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] init script v2

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] init script v2
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Date: Mon, 7 Jun 2010 13:03:05 +0100
Delivery-date: Mon, 07 Jun 2010 05:08:31 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)
Hi all,
second version of the init scripts for xl: now the init script is called
xencommons and, as the name suggests, it is a common script between xl
and xend because it is used to start xenconsoled, xenstored and
xenbackendd and the initialization of these three daemons has been removed
from xend.
The global xen_toolstack=xl/xend variable has been removed.
Regarding the network setup, I made the vif scripts follow the same
pattern as the other scripts in xen-backend: a new script called
vif-setup is executed unconditionally. vif-setup is going to do the
right thing depending on the value of the environmental variable
"script" (same technique used before), defaulting to vif-bridge.
In the common scenario the toolstack doesn't need to set the variable "script"
because vif-bridge is going to be called anyway.
There is no global network script to setup the network bridges with xl, so if
you are using xl without xend, you need to manually configure the bridges using
your distro network setup, or, if you are lazy, you can just add something like:

/etc/xen/scripts/network-bridge start

to your rc.local.


Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>

---

diff -r c514d69c71d8 tools/hotplug/Linux/Makefile
--- a/tools/hotplug/Linux/Makefile      Fri Jun 04 11:39:06 2010 +0100
+++ b/tools/hotplug/Linux/Makefile      Mon Jun 07 12:46:52 2010 +0100
@@ -3,15 +3,18 @@
 
 # Init scripts.
 XEND_INITD = init.d/xend
-XEND_SYSCONFIG = init.d/sysconfig.xend
 XENDOMAINS_INITD = init.d/xendomains
 XENDOMAINS_SYSCONFIG = init.d/sysconfig.xendomains
 
+XENCOMMONS_INITD = init.d/xencommons
+XENCOMMONS_SYSCONFIG = init.d/sysconfig.xencommons
+
 # Xen script dir and scripts to go there.
 XEN_SCRIPTS = network-bridge vif-bridge
 XEN_SCRIPTS += network-route vif-route
 XEN_SCRIPTS += network-nat vif-nat
 XEN_SCRIPTS += vif2
+XEN_SCRIPTS += vif-setup
 XEN_SCRIPTS += block
 XEN_SCRIPTS += block-enbd block-nbd
 XEN_SCRIPTS += blktap
@@ -64,9 +67,10 @@
        [ -d $(DESTDIR)$(CONFIG_DIR)/init.d ] || $(INSTALL_DIR) 
$(DESTDIR)$(CONFIG_DIR)/init.d
        [ -d $(DESTDIR)$(CONFIG_DIR)/sysconfig ] || $(INSTALL_DIR) 
$(DESTDIR)$(CONFIG_DIR)/sysconfig
        $(INSTALL_PROG) $(XEND_INITD) $(DESTDIR)$(CONFIG_DIR)/init.d
-       $(INSTALL_PROG) $(XEND_SYSCONFIG) $(DESTDIR)$(CONFIG_DIR)/sysconfig/xend
        $(INSTALL_PROG) $(XENDOMAINS_INITD) $(DESTDIR)$(CONFIG_DIR)/init.d
        $(INSTALL_PROG) $(XENDOMAINS_SYSCONFIG) 
$(DESTDIR)$(CONFIG_DIR)/sysconfig/xendomains
+       $(INSTALL_PROG) $(XENCOMMONS_INITD) $(DESTDIR)$(CONFIG_DIR)/init.d
+       $(INSTALL_PROG) $(XENCOMMONS_SYSCONFIG) 
$(DESTDIR)$(CONFIG_DIR)/sysconfig/xencommons
 
 .PHONY: install-scripts
 install-scripts:
diff -r c514d69c71d8 tools/hotplug/Linux/init.d/sysconfig.xencommons
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/hotplug/Linux/init.d/sysconfig.xencommons   Mon Jun 07 12:46:52 
2010 +0100
@@ -0,0 +1,11 @@
+# Log xenconsoled messages (cf xl dmesg)
+#XENCONSOLED_TRACE=[none|guest|hv|all]
+
+# Log xenstored messages
+#XENSTORED_TRACE=[yes|on|1]
+
+# Running xenstored on XENSTORED_ROOTDIR
+#XENSTORED_ROOTDIR=/var/lib/xenstored
+
+# Running xenbackendd in debug mode
+#XENBACKENDD_DEBUG=[yes|on|1]
diff -r c514d69c71d8 tools/hotplug/Linux/init.d/sysconfig.xend
--- a/tools/hotplug/Linux/init.d/sysconfig.xend Fri Jun 04 11:39:06 2010 +0100
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-# Log xenconsoled messages (cf xm dmesg)
-#XENCONSOLED_TRACE=[none|guest|hv|all]
-
-# Log xenstored messages
-#XENSTORED_TRACE=[yes|on|1]
-
-# Running xenstored on XENSTORED_ROOTDIR
-#XENSTORED_ROOTDIR=/var/lib/xenstored
-
-# Running xenbackendd in debug mode
-#XENBACKENDD_DEBUG=[yes|on|1]
diff -r c514d69c71d8 tools/hotplug/Linux/init.d/xencommons
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/hotplug/Linux/init.d/xencommons     Mon Jun 07 12:46:52 2010 +0100
@@ -0,0 +1,87 @@
+#!/bin/bash
+#
+# xencommons    Script to start and stop xenstored and xenconsoled
+#
+# Author:       Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
+#
+# chkconfig: 2345
+# description: Starts and stops xenstored and xenconsoled
+### BEGIN INIT INFO
+# Provides:          xenstored xenconsoled
+# Required-Start:    $syslog $remote_fs
+# Should-Start:
+# Required-Stop:     $syslog $remote_fs
+# Should-Stop:
+# Default-Start:     3 4 5
+# Default-Stop:      1
+# Default-Enabled:   yes
+# Short-Description: Start/stop xenstored and xenconsoled
+# Description:       Starts and stops the daemons neeeded for xl/xend
+### END INIT INFO
+
+test -f /etc/sysconfig/xencommons && . /etc/sysconfig/xencommons
+
+XENCONSOLED_PIDFILE=/var/run/xenconsoled.pid
+shopt -s extglob
+
+if test "x$1" = xstart && \
+     test -d /proc/xen && \
+   ! test -d /proc/xen/capabilities && \
+     grep '    xenfs$' /proc/filesystems >/dev/null && \
+   ! grep '^xenfs ' /proc/mounts >/dev/null;
+then
+       mount -t xenfs xenfs /proc/xen
+fi
+
+if ! grep -q "control_d" /proc/xen/capabilities ; then
+       exit 0
+fi
+
+do_start () {
+       if ! `xenstore-read -s / >/dev/null 2>&1`
+       then
+               test -z "$XENSTORED_ROOTDIR" || 
XENSTORED_ROOTDIR="/var/lib/xenstored"
+               rm -f "$XENSTORED_ROOTDIR"/tdb* &>/dev/null
+               test -z "$XENSTORED_TRACE" || XENSTORED_ARGS=" -T 
/var/log/xen/xenstored-trace.log"
+               xenstored --pid-file=/var/run/xenstore.pid $XENSTORED_ARGS
+               xenstore-write "/local/domain/0/name" "Domain-0"
+       fi
+
+       test -z "$XENCONSOLED_TRACE" || XENCONSOLED_ARGS=" -T 
/var/log/xen/xenstored-trace.log"
+       xenconsoled --pid-file=$XENCONSOLED_PIDFILE $XENCONSOLED_ARGS
+       test -z "$XENBACKENDD_DEBUG" || XENBACKENDD_ARGS="-d"
+       test "`uname`" != "NetBSD" || xenbackendd $XENBACKENDD_ARGS
+}
+do_stop () {
+       if read 2>/dev/null <$XENCONSOLED_PIDFILE pid; then
+               kill $pid
+               while kill -9 $pid >/dev/null 2>&1; do sleep 0.1; done
+               rm -f $XENCONSOLED_PIDFILE
+       fi
+}
+
+case "$1" in
+  start)
+       do_start
+       ;;
+  status)
+        xenstore-read -s /
+       ;;
+  stop)
+       do_stop
+       ;;
+  reload)
+       echo >&2 'Reload not available; use force-reload'; exit 1
+       ;;
+  force-reload|restart)
+        do_stop
+       do_start
+       ;;
+  *)
+       # do not advertise unreasonable commands that there is no reason
+       # to use with this device
+       echo $"Usage: $0 {start|stop|status|restart|force-reload}"
+       exit 1
+esac
+
+exit $?
diff -r c514d69c71d8 tools/hotplug/Linux/init.d/xend
--- a/tools/hotplug/Linux/init.d/xend   Fri Jun 04 11:39:06 2010 +0100
+++ b/tools/hotplug/Linux/init.d/xend   Mon Jun 07 12:46:52 2010 +0100
@@ -20,20 +20,6 @@
 ### END INIT INFO
 
 shopt -s extglob
-test -f /etc/sysconfig/xend && . /etc/sysconfig/xend
-
-if   test "x$1" = xstart && \
-     test -d /proc/xen && \
-   ! test -d /proc/xen/capabilities && \
-     grep '    xenfs$' /proc/filesystems >/dev/null && \
-   ! grep '^xenfs ' /proc/mounts >/dev/null;
-then
-       mount -t xenfs xenfs /proc/xen
-fi
-
-if ! grep -qs "control_d" /proc/xen/capabilities ; then
-       exit 0
-fi
 
 # Wait for Xend to be up
 function await_daemons_up
@@ -53,10 +39,6 @@
   start)
        mkdir -p /var/lock/subsys
        touch /var/lock/subsys/xend
-       test -z "$XENSTORED_ROOTDIR" || export XENSTORED_ROOTDIR
-       test -z "$XENCONSOLED_TRACE" || export XENCONSOLED_TRACE
-       [[ "$XENSTORED_TRACE" == @(yes|on|1) ]] && export XENSTORED_TRACE
-       [[ "$XENBACKENDD_DEBUG" == @(yes|on|1) ]] && export XENBACKENDD_DEBUG
        xend start
        await_daemons_up
        ;;
diff -r c514d69c71d8 tools/hotplug/Linux/init.d/xendomains
--- a/tools/hotplug/Linux/init.d/xendomains     Fri Jun 04 11:39:06 2010 +0100
+++ b/tools/hotplug/Linux/init.d/xendomains     Mon Jun 07 12:46:52 2010 +0100
@@ -28,6 +28,11 @@
 #                    boots / shuts down.
 ### END INIT INFO
 
+if ! `xm list &> /dev/null`
+then
+       exit 0
+fi
+
 # Correct exit code would probably be 5, but it's enough 
 # if xend complains if we're not running as privileged domain
 if ! [ -e /proc/xen/privcmd ]; then
diff -r c514d69c71d8 tools/hotplug/Linux/vif-setup
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/hotplug/Linux/vif-setup     Mon Jun 07 12:46:52 2010 +0100
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+if test "$script"
+then
+    exec "$script" $*
+else
+    exec /etc/xen/scripts/vif-bridge $*
+fi
+
diff -r c514d69c71d8 tools/hotplug/Linux/xen-backend.rules
--- a/tools/hotplug/Linux/xen-backend.rules     Fri Jun 04 11:39:06 2010 +0100
+++ b/tools/hotplug/Linux/xen-backend.rules     Mon Jun 07 12:46:52 2010 +0100
@@ -2,8 +2,8 @@
 SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block 
$env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm 
$env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 
$env{ACTION}"
-SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", 
RUN+="$env{script} online"
-SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", 
RUN+="$env{script} offline"
+SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", 
RUN+="/etc/xen/scripts/vif-setup online"
+SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", 
RUN+="/etc/xen/scripts/vif-setup offline"
 SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi 
$env{ACTION}"
 SUBSYSTEM=="xen-backend", ACTION=="remove", 
RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
 KERNEL=="evtchn", NAME="xen/%k"
diff -r c514d69c71d8 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Fri Jun 04 11:39:06 2010 +0100
+++ b/tools/libxl/libxl.h       Mon Jun 07 12:46:52 2010 +0100
@@ -538,5 +538,17 @@
                    uint32_t set);
 int libxl_tmem_shared_auth(struct libxl_ctx *ctx, uint32_t domid, char* uuid,
                            int auth);
+
+/* common paths */
+const char *libxl_sbindir_path(void);
+const char *libxl_bindir_path(void);
+const char *libxl_libexec_path(void);
+const char *libxl_libdir_path(void);
+const char *libxl_sharedir_path(void);
+const char *libxl_private_bindir_path(void);
+const char *libxl_xenfirmwaredir_path(void);
+const char *libxl_xen_config_dir_path(void);
+const char *libxl_xen_script_dir_path(void);
+
 #endif /* LIBXL_H */
 
diff -r c514d69c71d8 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Fri Jun 04 11:39:06 2010 +0100
+++ b/tools/libxl/libxl_internal.h      Mon Jun 07 12:46:52 2010 +0100
@@ -215,17 +215,6 @@
 
 char *libxl_abs_path(struct libxl_ctx *ctx, char *s, const char *path);
 
-/* libxl_paths.c */
-const char *libxl_sbindir_path(void);
-const char *libxl_bindir_path(void);
-const char *libxl_libexec_path(void);
-const char *libxl_libdir_path(void);
-const char *libxl_sharedir_path(void);
-const char *libxl_private_bindir_path(void);
-const char *libxl_xenfirmwaredir_path(void);
-const char *libxl_xen_config_dir_path(void);
-const char *libxl_xen_script_dir_path(void);
-
 #define XL_LOG_DEBUG   XTL_DEBUG
 #define XL_LOG_INFO    XTL_INFO
 #define XL_LOG_WARNING XTL_WARN
diff -r c514d69c71d8 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Fri Jun 04 11:39:06 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Mon Jun 07 12:46:52 2010 +0100
@@ -42,6 +42,25 @@
 
 #define UUID_FMT 
"%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
 
+#define CHK_ERRNO( call ) ({                                            \
+        int chk_errno = (call);                                         \
+        if (chk_errno < 0) {                                                \
+            fprintf(stderr,"xl: fatal error: %s:%d: %s: %s\n",          \
+                    __FILE__,__LINE__, strerror(chk_errno), #call);     \
+            exit(-ERROR_FAIL);                                          \
+        }                                                               \
+    })
+
+#define MUST( call ) ({                                                 \
+        int must_rc = (call);                                           \
+        if (must_rc < 0) {                                                  \
+            fprintf(stderr,"xl: fatal error: %s:%d, rc=%d: %s\n",       \
+                    __FILE__,__LINE__, must_rc, #call);                 \
+            exit(-must_rc);                                             \
+        }                                                               \
+    })
+
+
 int logfile = 2;
 
 /* every libxl action in xl uses this same libxl context */
@@ -240,7 +259,8 @@
     nic_info->mac[5] = 1 + (int) (0xff * (rand() / (RAND_MAX + 1.0)));
     nic_info->ifname = NULL;
     nic_info->bridge = "xenbr0";
-    nic_info->script = "/etc/xen/scripts/vif-bridge";
+    CHK_ERRNO( asprintf(&nic_info->script, "%s/vif-bridge",
+               libxl_xen_script_dir_path()) );
     nic_info->nictype = NICTYPE_IOEMU;
 }
 
@@ -791,24 +811,6 @@
     xlu_cfg_destroy(config);
 }
 
-#define CHK_ERRNO( call ) ({                                            \
-        int chk_errno = (call);                                         \
-        if (chk_errno) {                                                \
-            fprintf(stderr,"xl: fatal error: %s:%d: %s: %s\n",          \
-                    __FILE__,__LINE__, strerror(chk_errno), #call);     \
-            exit(-ERROR_FAIL);                                          \
-        }                                                               \
-    })
-
-#define MUST( call ) ({                                                 \
-        int must_rc = (call);                                           \
-        if (must_rc) {                                                  \
-            fprintf(stderr,"xl: fatal error: %s:%d, rc=%d: %s\n",       \
-                    __FILE__,__LINE__, must_rc, #call);                 \
-            exit(-must_rc);                                             \
-        }                                                               \
-    })
-
 static void *xmalloc(size_t sz) {
     void *r;
     r = malloc(sz);
diff -r c514d69c71d8 tools/misc/xend
--- a/tools/misc/xend   Fri Jun 04 11:39:06 2010 +0100
+++ b/tools/misc/xend   Mon Jun 07 12:46:52 2010 +0100
@@ -73,48 +73,9 @@
     if os.fork() == 0:
         os.execvp(daemon, (daemon,) + args)
 
-def start_xenstored():
-    pidfname = "/var/run/xenstore.pid"
-    try:
-        f = open(pidfname, "a")
-        try:
-            fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
-            rootdir = os.getenv("XENSTORED_ROOTDIR") or "/var/lib/xenstored"
-            for i in glob.glob(rootdir + "/tdb*"):
-                try:
-                    os.unlink(i)
-                except:
-                    pass
-            os.unlink(pidfname)
-        except:
-            pass
-        f.close()
-    except:
-        pass
-    XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
-    cmd = "xenstored --pid-file /var/run/xenstore.pid"
-    if XENSTORED_TRACE:
-        cmd += " -T /var/log/xen/xenstored-trace.log"
-    s,o = commands.getstatusoutput(cmd)
-
-def start_consoled():
-    XENCONSOLED_TRACE = os.getenv("XENCONSOLED_TRACE")
-    args = ""
-    if XENCONSOLED_TRACE:
-        args += "--log=" + XENCONSOLED_TRACE
-    start_daemon("xenconsoled", args)
-
 def start_blktapctrl():
     start_daemon("blktapctrl", "")
 
-def start_xenbackendd():
-    XENBACKENDD_DEBUG = os.getenv("XENBACKENDD_DEBUG")
-    args = ""
-    if XENBACKENDD_DEBUG:
-        args += "-d"
-    if os.uname()[0] == 'NetBSD':
-        start_daemon("xenbackendd", args)
-
 def main():
     try:
         check_logging()
@@ -127,15 +88,9 @@
         print 'usage: %s {start|stop|reload|restart}' % sys.argv[0]
     elif sys.argv[1] == 'start':
         if os.uname()[0] != "SunOS":
-            start_xenstored()
-            start_consoled()
-            start_xenbackendd()
             start_blktapctrl()
         return daemon.start()
     elif sys.argv[1] == 'trace_start':
-        start_xenstored()
-        start_consoled()
-        start_xenbackendd()
         start_blktapctrl()
         return daemon.start(trace=1)
     elif sys.argv[1] == 'stop':
@@ -143,9 +98,6 @@
     elif sys.argv[1] == 'reload':
         return daemon.reloadConfig()
     elif sys.argv[1] == 'restart':
-        start_xenstored()
-        start_consoled()
-        start_xenbackendd()
         start_blktapctrl()
         return daemon.stop() or daemon.start()
     elif sys.argv[1] == 'status':

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>