[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Ovirt-devel] [PATCH-node]: Re-arrange the node spec file to use scripts



-- 
Chris Lalancette
commit 56f847792a30f26891940d21fe7bb10df8c2abd9
Author: Chris Lalancette <clalance redhat com>
Date:   Thu Sep 11 13:43:25 2008 +0200

    A rewrite of the ovirt-node.spec script, which cascaded into a bunch of
    other files.  The impetus for doing this is that we want to have an
    external script that takes care of setting up a host for either 'stateless'
    or 'stateful' operation.  They share some things in common, but some things
    are different.  Towards that end, there is a script now that has to be called
    to setup a host; we call it in the kickstart %post to setup stateless, and
    the user has to take explicit action to setup stateful.
    
    Signed-off-by: Chris Lalancette <clalance redhat com>

diff --git a/ovirt-listen-awake/Makefile.am b/ovirt-listen-awake/Makefile.am
index 66f6380..9e0f676 100644
--- a/ovirt-listen-awake/Makefile.am
+++ b/ovirt-listen-awake/Makefile.am
@@ -17,4 +17,6 @@
 
 bin_PROGRAMS = ovirt-listen-awake
 
+EXTRA_DIST = ovirt-listen-awake.init ovirt-install-host ovirt-uninstall-host
+
 ovirt_listen_awake_SOURCES = ovirt-listen-awake.c
diff --git a/ovirt-listen-awake/ovirt-install-host b/ovirt-listen-awake/ovirt-install-host
new file mode 100644
index 0000000..db12431
--- /dev/null
+++ b/ovirt-listen-awake/ovirt-install-host
@@ -0,0 +1,102 @@
+#!/bin/bash
+
+. /etc/init.d/ovirt-functions
+
+PATH=$PATH:/sbin:/usr/sbin
+
+usage() {
+    echo "Usage: ovirt-install-host <stateless|stateful>"
+    exit 1    
+}
+
+if [ $# -ne 1 ]; then
+    usage
+fi
+
+backup_file() {
+    dir=$(dirname "$1")
+    case $dir in /*);; *) die "unexpected non-absolute dir: $dir";; esac
+    mkdir -p "$OVIRT_BACKUP_DIR/${dir:1}"
+    cp -pf "$1" "$OVIRT_BACKUP_DIR/${dir:1}"
+}
+
+add_if_not_exist() {
+    string="$1"
+    file="$2"
+
+    grep -qE "^[[:space:]]*$string($|#|[[:space:]])" "$file" \
+	|| echo "$string" >> "$file"
+}
+
+if [ "$1" = "stateless" ]; then
+    chkconfig --level 3 ovirt-early on
+    chkconfig --level 3 ovirt on
+    chkconfig --level 3 ovirt-post on
+    chkconfig --level 3 collectd on
+
+    ovirt_setup_libvirtd
+
+    # make sure we don't autostart virbr0 on libvirtd startup
+    rm -f /etc/libvirt/qemu/networks/autostart/default.xml
+
+    # remove the /etc/krb5.conf file; it will be fetched on bootup
+    rm -f /etc/krb5.conf
+
+    g=$(printf '\33[1m\33[32m')    # similar to g=$(tput bold; tput setaf 2)
+    n=$(printf '\33[m')            # similar to n=$(tput sgr0)
+    version=$(rpm -q --qf '%{version}' ovirt-node)
+    release=$(rpm -q --qf '%{release}' ovirt-node)
+    cat <<EOF > /etc/issue
+
+           888     888 ${g}d8b$n         888
+           888     888 ${g}Y8P$n         888
+           888     888             888
+   .d88b.  Y88b   d88P 888 888d888 888888
+  d88''88b  Y88b d88P  888 888P'   888
+  888  888   Y88o88P   888 888     888
+  Y88..88P    Y888P    888 888     Y88b.
+   'Y88P'      Y8P     888 888      'Y888
+
+  oVirt Node release ${version}-${release}
+
+  Virtualization just got the ${g}Green Light$n
+
+EOF
+    cp -p /etc/issue /etc/issue.net
+elif [ "$1" = "stateful" ]; then
+    echo "This script will make a number of changes to your system to enable it"
+    echo "to work as an oVirt node.  You can later undo these changes by"
+    echo "running /usr/sbin/ovirt-uninstall-host.  Do you want to proceed? [y/N]?"
+    read yesno
+
+    if [ "$yesno" != "y" -a "$yesno" != "Y" ]; then
+	exit 2
+    fi
+
+    mkdir -p $OVIRT_BACKUP_DIR
+
+    backup_file /etc/sysconfig/network
+    sed -i -e 's/^HOSTNAME=.*/HOSTNAME=physical.priv.ovirt.org/' /etc/sysconfig/network
+
+    backup_file /etc/hosts
+    add_if_not_exist "192.168.50.1 physical.priv.ovirt.org" /etc/hosts
+    add_if_not_exist "192.168.50.2 management.priv.ovirt.org" /etc/hosts
+
+    chkconfig ovirt-listen-awake on
+    chkconfig collectd on
+
+    backup_file /etc/sysconfig/libvirtd
+    backup_file /etc/libvirt/qemu.conf
+    backup_file /etc/libvirt/libvirtd.conf
+    backup_file /etc/sasl2/libvirt.conf
+    backup_file /etc/krb5.conf
+    ovirt_setup_libvirtd
+
+    backup_file /etc/sysconfig/iptables
+    lokkit -n -t ovirtbr0
+
+    echo "Setup complete.  To make the changes take effect, shut down any"
+    echo "running guests and reboot the host"
+else
+    usage
+fi
\ No newline at end of file
diff --git a/ovirt-listen-awake/ovirt-listen-awake.init b/ovirt-listen-awake/ovirt-listen-awake.init
new file mode 100644
index 0000000..a6bb78a
--- /dev/null
+++ b/ovirt-listen-awake/ovirt-listen-awake.init
@@ -0,0 +1,49 @@
+#!/bin/bash
+#
+#
+# ovirt-listen-awake       startup script for ovirt-listen-awake
+#
+# chkconfig: - 97 03
+# description: ovirt-listen-awake is a daemon to listen for requests from
+#    the ovirt VM manager.  When it receives one, it contacts the machine
+#    back with details so that it is added to the ovirt host pool.
+
+DAEMON=/usr/sbin/ovirt-listen-awake
+
+. /etc/init.d/functions
+
+start() {
+    echo -n "Starting ovirt-listen-awake: "
+    daemon $DAEMON
+    RETVAL=$?
+    echo
+}
+
+stop() {
+    echo -n "Shutting down ovirt-listen-awake: "
+    killproc ovirt-listen-awake
+    RETVAL=$?
+    echo
+}
+
+case "$1" in
+    start)
+	start
+	;;
+    stop)
+	stop
+	;;
+    restart)
+	stop
+	start
+	;;
+    status)
+	status $DAEMON
+	RETVAL=$?
+	;;
+    *)
+      echo "Usage: ovirt-listen-awake {start|stop|restart|status}"
+      exit 1
+  ;;
+esac
+exit $RETVAL
diff --git a/ovirt-listen-awake/ovirt-uninstall-host b/ovirt-listen-awake/ovirt-uninstall-host
new file mode 100644
index 0000000..53841e0
--- /dev/null
+++ b/ovirt-listen-awake/ovirt-uninstall-host
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+. /etc/init.d/ovirt-functions
+
+PATH=$PATH:/sbin:/usr/sbin
+
+if [ $# -ne 0 ]; then
+    echo "Usage: ovirt-uninstall-host"
+    exit 1
+fi
+
+if [ ! -d $OVIRT_BACKUP_DIR ]; then
+    echo "The oVirt backup directory $OVIRT_BACKUP_DIR doesn't exist; can't"
+    echo "uninstall the host"
+    exit 2
+fi
+
+unbackup_file() {
+    # note that $1 will have a / on the front, so we don't need to add our own
+    cp -pf "$OVIRT_BACKUP_DIR$1" "$1"
+}
+
+chkconfig ovirt-listen-awake off
+chkconfig collectd off
+
+unbackup_file /etc/sysconfig/network
+unbackup_file /etc/hosts
+unbackup_file /etc/sysconfig/libvirtd
+unbackup_file /etc/libvirt/qemu.conf
+unbackup_file /etc/libvirt/libvirtd.conf
+unbackup_file /etc/sasl2/libvirt.conf
+unbackup_file /etc/sysconfig/iptables
+unbackup_file /etc/krb5.conf
\ No newline at end of file
diff --git a/ovirt-node.spec b/ovirt-node.spec
index 736338d..7674921 100644
--- a/ovirt-node.spec
+++ b/ovirt-node.spec
@@ -15,6 +15,8 @@ BuildRequires:  libvirt-devel
 BuildRequires:  dbus-devel hal-devel
 Requires:       libvirt
 Requires:       hal
+Requires:       collectd
+Requires:       cyrus-sasl-gssapi
 ExclusiveArch:  %{ix86} x86_64
 
 %define app_root %{_datadir}/%{name}
@@ -44,6 +46,10 @@ make
 %{__install} -p -m0755 scripts/ovirt-awake %{buildroot}%{_sbindir}
 %{__install} -p -m0755 ovirt-identify-node/ovirt-identify-node %{buildroot}%{_sbindir}
 %{__install} -p -m0755 ovirt-listen-awake/ovirt-listen-awake %{buildroot}%{_sbindir}
+%{__install} -Dp -m0755 ovirt-listen-awake/ovirt-listen-awake.init %{buildroot}%{_initrddir}/ovirt-listen-awake
+%{__install} -Dp -m0755 ovirt-listen-awake/ovirt-install-host %{buildroot}%{_sbindir}
+%{__install} -Dp -m0755 ovirt-listen-awake/ovirt-uninstall-host %{buildroot}%{_sbindir}
+
 
 %{__install} -p -m0644 scripts/ovirt-functions %{buildroot}%{_initrddir}
 %{__install} -p -m0755 scripts/ovirt-early %{buildroot}%{_initrddir}
@@ -52,8 +58,6 @@ make
 
 %{__install} -p -m0644 scripts/collectd %{buildroot}%{_sysconfdir}/chkconfig.d
 %{__install} -p -m0644 scripts/collectd.conf.in %{buildroot}%{_sysconfdir}
-%{__install} -p -m0755 scripts/kvm-ifup %{buildroot}%{_sysconfdir}
-%{__install} -p -m0755 scripts/dhclient-exit-hooks %{buildroot}%{_sysconfdir}
 
 %{__install} -p -m0755 logrotate/ovirt-logrotate %{buildroot}%{_sysconfdir}/cron.hourly
 %{__install} -p -m0644 logrotate/ovirt-logrotate.conf %{buildroot}%{_sysconfdir}/logrotate.d
@@ -65,66 +69,19 @@ echo "oVirt Node release %{version}-%{release}" > %{buildroot}%{_sysconfdir}/ovi
 
 %post
 /sbin/chkconfig --add ovirt-early
-/sbin/chkconfig ovirt-early on
 /sbin/chkconfig --add ovirt
-/sbin/chkconfig ovirt on
 /sbin/chkconfig --add ovirt-post
-/sbin/chkconfig ovirt-post on
+# this is ugly; we need collectd to start *after* libvirtd, so we own the
+# /etc/chkconfig.d/collectd file, and then have to re-define collectd here
 /sbin/chkconfig --add collectd
-/sbin/chkconfig collectd on
-
-# just to get a boot warning to shut up
-touch /etc/resolv.conf
-
-# make libvirtd listen on the external interfaces
-sed -i -e "s/^#\(LIBVIRTD_ARGS=\"--listen\"\).*/\1/" /etc/sysconfig/libvirtd
-
-# set up qemu daemon to allow outside VNC connections
-sed -i -e "s/^[[:space:]]*#[[:space:]]*\(vnc_listen = \"0.0.0.0\"\).*/\1/" \
-    /etc/libvirt/qemu.conf
-
-# set up libvirtd to listen on TCP (for kerberos)
-sed -i -e "s/^[[:space:]]*#[[:space:]]*\(listen_tcp\)\>.*/\1 = 1/" \
-    -e "s/^[[:space:]]*#[[:space:]]*\(listen_tls\)\>.*/\1 = 0/" \
-    /etc/libvirt/libvirtd.conf
-
-# make sure we don't autostart virbr0 on libvirtd startup
-rm -f /etc/libvirt/qemu/networks/autostart/default.xml
-
-# with the new libvirt (0.4.0), make sure we we setup gssapi in the mech_list
-if [ `egrep -c "^mech_list: gssapi" /etc/sasl2/libvirt.conf` -eq 0 ]; then
-    sed -i -e "s/^\([[:space:]]*mech_list.*\)/#\1/" /etc/sasl2/libvirt.conf
-    echo "mech_list: gssapi" >> /etc/sasl2/libvirt.conf
-fi
-
-# remove the /etc/krb5.conf file; it will be fetched on bootup
-rm -f /etc/krb5.conf
-
-g=$(printf '\33[1m\33[32m')    # similar to g=$(tput bold; tput setaf 2)
-n=$(printf '\33[m')            # similar to n=$(tput sgr0)
-cat <<EOF > /etc/issue
-
-           888     888 ${g}d8b$n         888
-           888     888 ${g}Y8P$n         888
-           888     888             888
-   .d88b.  Y88b   d88P 888 888d888 888888
-  d88''88b  Y88b d88P  888 888P'   888
-  888  888   Y88o88P   888 888     888
-  Y88..88P    Y888P    888 888     Y88b.
-   'Y88P'      Y8P     888 888      'Y888
-
-  oVirt Node release %{version}-%{release}
-
-  Virtualization just got the ${g}Green Light$n
-
-EOF
-cp -p /etc/issue /etc/issue.net
+/sbin/chkconfig --add ovirt-listen-awake
 
 %preun
 if [ "$1" = 0 ] ; then
   /sbin/chkconfig --del ovirt-early
   /sbin/chkconfig --del ovirt
   /sbin/chkconfig --del ovirt-post
+  /sbin/chkconfig --del ovirt-listen-awake
 fi
 
 %files
@@ -132,11 +89,12 @@ fi
 %{_sbindir}/ovirt-awake
 %{_sbindir}/ovirt-identify-node
 %{_sbindir}/ovirt-listen-awake
+%{_sbindir}/ovirt-install-host
+%{_sbindir}/ovirt-uninstall-host
 %{_initrddir}/ovirt-early
 %{_initrddir}/ovirt
 %{_initrddir}/ovirt-post
-%{_sysconfdir}/kvm-ifup
-%{_sysconfdir}/dhclient-exit-hooks
+%{_initrddir}/ovirt-listen-awake
 %config %{_sysconfdir}/logrotate.d/ovirt-logrotate.conf
 %config %{_sysconfdir}/cron.hourly/ovirt-logrotate
 %defattr(-,root,root,0644)
@@ -149,6 +107,10 @@ fi
 %doc ovirt-identify-node/COPYING
 
 %changelog
+* Thu Sep 11 2008 Chris Lalancette <clalance redhat com> - 0.92 0.7
+- Add the ovirt-install- and ovirt-uninstall-host scripts, and refactor
+  post to accomodate
+
 * Mon Sep  8 2008 Jim Meyering <meyering redhat com> - 0.92 0.6
 - Update ovirt-identify-node's build rule.
 
diff --git a/scripts/dhclient-exit-hooks b/scripts/dhclient-exit-hooks
deleted file mode 100644
index 7dd53c0..0000000
--- a/scripts/dhclient-exit-hooks
+++ /dev/null
@@ -1,5 +0,0 @@
-if [ -n "$new_ntp_servers" ]; then
-    for ntp_server in $new_ntp_servers; do
-        echo "$ntp_server" >> /etc/ntp/step-tickers
-    done
-fi
diff --git a/scripts/kvm-ifup b/scripts/kvm-ifup
deleted file mode 100644
index 243e02f..0000000
--- a/scripts/kvm-ifup
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-switch=$(ip route list | awk '/^default / { print $NF }')
-ifconfig $1 0.0.0.0 up
-brctl addif ${switch} $1
diff --git a/scripts/ovirt b/scripts/ovirt
index 232da49..0878a9e 100644
--- a/scripts/ovirt
+++ b/scripts/ovirt
@@ -2,7 +2,7 @@
 #
 # ovirt Start ovirt services
 #
-# chkconfig: 3 11 99
+# chkconfig: - 11 99
 # description: ovirt services
 #
 
diff --git a/scripts/ovirt-early b/scripts/ovirt-early
index 31463b3..8024b3b 100755
--- a/scripts/ovirt-early
+++ b/scripts/ovirt-early
@@ -2,7 +2,7 @@
 #
 # ovirt-early Start early ovirt services
 #
-# chkconfig: 3 01 99
+# chkconfig: - 01 99
 # description: ovirt-early services
 #
 
diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions
index 083e13d..3bec877 100644
--- a/scripts/ovirt-functions
+++ b/scripts/ovirt-functions
@@ -5,6 +5,8 @@ OVIRT_LOGFILE=/var/log/ovirt.log
 # label of the oVirt partition
 OVIRT_LABEL=OVIRT
 
+OVIRT_BACKUP_DIR=/var/lib/ovirt-backup
+
 find_srv()
 {
     local dnsreply
@@ -21,3 +23,27 @@ die()
 {
     echo "$@" 1>&2; failure; echo 1>&2; exit 1
 }
+
+ovirt_setup_libvirtd() {
+    # just to get a boot warning to shut up
+    touch /etc/resolv.conf
+
+    # make libvirtd listen on the external interfaces
+    sed -i -e 's/^#\(LIBVIRTD_ARGS="--listen"\).*/\1/' \
+       /etc/sysconfig/libvirtd
+
+    # set up qemu daemon to allow outside VNC connections
+    sed -i -e 's/^[[:space:]]*#[[:space:]]*\(vnc_listen = "0.0.0.0"\).*/\1/' \
+       /etc/libvirt/qemu.conf
+    # set up libvirtd to listen on TCP (for kerberos)
+    sed -i -e "s/^[[:space:]]*#[[:space:]]*\(listen_tcp\)\>.*/\1 = 1/" \
+       -e "s/^[[:space:]]*#[[:space:]]*\(listen_tls\)\>.*/\1 = 0/" \
+       /etc/libvirt/libvirtd.conf
+
+    # with libvirt (0.4.0), make sure we we setup gssapi in the mech_list
+    sasl_conf=/etc/sasl2/libvirt.conf
+    if ! grep -qE "^mech_list: gssapi" $sasl_conf ; then
+       sed -i -e "s/^\([[:space:]]*mech_list.*\)/#\1/" $sasl_conf
+       echo "mech_list: gssapi" >> $sasl_conf
+    fi
+}
diff --git a/scripts/ovirt-post b/scripts/ovirt-post
index 1267f40..d989940 100644
--- a/scripts/ovirt-post
+++ b/scripts/ovirt-post
@@ -2,7 +2,7 @@
 #
 # ovirt Start ovirt services
 #
-# chkconfig: 3 98 02
+# chkconfig: - 98 02
 # description: ovirt-post services
 #
 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]