[Ovirt-devel] [PATCH] Moving sysvinit scripts into the ovirt-managed-node RPM.
Darryl L. Pierce
dpierce at redhat.com
Mon Jun 30 15:38:46 UTC 2008
From: Darryl Pierce <dpierce at redhat.com>
Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
ovirt-host-creator/common-post.ks | 239 -------------------------
ovirt-managed-node/ovirt-managed-node.spec | 14 ++
ovirt-managed-node/src/init.d/ovirt | 51 ++++++
ovirt-managed-node/src/init.d/ovirt-early | 104 +++++++++++
ovirt-managed-node/src/init.d/ovirt-functions | 18 ++
ovirt-managed-node/src/init.d/ovirt-post | 37 ++++
ovirt-managed-node/src/ovirt-identify-node.c | 2 +-
7 files changed, 225 insertions(+), 240 deletions(-)
create mode 100644 ovirt-managed-node/src/init.d/ovirt
create mode 100644 ovirt-managed-node/src/init.d/ovirt-early
create mode 100644 ovirt-managed-node/src/init.d/ovirt-functions
create mode 100644 ovirt-managed-node/src/init.d/ovirt-post
diff --git a/ovirt-host-creator/common-post.ks b/ovirt-host-creator/common-post.ks
index 723b838..47736db 100644
--- a/ovirt-host-creator/common-post.ks
+++ b/ovirt-host-creator/common-post.ks
@@ -12,141 +12,6 @@ cat > /etc/sysconfig/iptables << \EOF
COMMIT
EOF
-echo "Writing ovirt-functions script"
-# common functions
-cat > /etc/init.d/ovirt-functions << \EOF
-# -*-Shell-script-*-
-
-find_srv() {
- local dnsreply
- dnsreply=$(dig +short -t srv _$1._$2.$(dnsdomainname))
- if [ $? -eq 0 ]; then
- set _ $dnsreply; shift
- SRV_HOST=$4; SRV_PORT=$3
- else
- SRV_HOST=; SRV_PORT=
- fi
-}
-
-die()
-{
- echo "$@" 1>&2; failure; echo 1>&2; exit 1
-}
-
-EOF
-
-echo "Writing ovirt-early init script"
-# next the dynamic bridge setup service
-cat > /etc/init.d/ovirt-early << \EOF
-#!/bin/bash
-#
-# ovirt-early Start early ovirt services
-#
-# chkconfig: 3 01 99
-# description: ovirt-early services
-#
-
-# Source functions library
-. /etc/init.d/functions
-. /etc/init.d/ovirt-functions
-
-configure_from_network() {
- DEVICE=$1
- if [ -n "$DEVICE" ]; then
- printf .
- # setup temporary interface to retrieve configuration
- echo "network --device $DEVICE --bootproto dhcp" | nash
- if [ $? -eq 0 ]; then
- printf .
- # from network-scripts/ifup-post
- IPADDR=$(LC_ALL=C ip -o -4 addr ls dev ${DEVICE} | awk '{ print $4 ; exit }')
- eval $(ipcalc --silent --hostname ${IPADDR} ; echo "status=$?")
- if [ "$status" = "0" ]; then
- hostname $HOSTNAME
- # retrieve remote config
- find_srv ovirt tcp
- printf .
- if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ]; then
- wget --quiet -O - "http://$SRV_HOST:$SRV_PORT/ovirt/cfgdb/$(hostname)" \
- | augtool > /dev/null 2>&1
- if [ $? -eq 0 ]; then
- printf "remote config applied."
- return
- fi
- fi
- fi
- fi
- fi
- # default oVirt network configuration:
- # bridge each ethernet device in the system
- ETHDEVS=$(cd /sys/class/net && ls -d eth*)
- for eth in $ETHDEVS; do
- BRIDGE=ovirtbr`echo $eth | cut -b4-`
- printf '%s\n' "DEVICE=$eth" ONBOOT=yes "BRIDGE=$BRIDGE" \
- > /etc/sysconfig/network-scripts/ifcfg-$eth
- printf '%s\n' "DEVICE=$BRIDGE" BOOTPROTO=dhcp \
- ONBOOT=yes TYPE=Bridge PEERNTP=yes \
- > /etc/sysconfig/network-scripts/ifcfg-$BRIDGE
- done
- printf "default config applied."
-}
-
-start() {
- # find boot interface from cmdline
- # IPAPPEND 2 in pxelinux.cfg appends e.g. BOOTIF=01-00-16-3e-12-34-57
- BOOTIF=
- for i in $(cat /proc/cmdline); do
- case $i in
- BOOTIF=??-??-??-??-??-??-??)
- i=${i/#BOOTIF=??-/}
- BOOTMAC=${i//-/:}
- BOOTIF=$(grep -l $BOOTMAC /sys/class/net/eth*/address|rev|cut -d/ -f2|rev)
- ;;
- esac
- done
- configure_from_network $BOOTIF
-
- # find all of the partitions on the system
-
- # get the system pagesize
- PAGESIZE=`getconf PAGESIZE`
-
- # look first at raw partitions
- BLOCKDEVS=`ls /dev/sd? /dev/hd? 2>/dev/null`
-
- # now LVM partitions
- LVMDEVS="$DEVICES `lvscan | awk '{print $2}' | tr -d \"'\"`"
-
- SWAPDEVS="$LVMDEVS"
- for dev in $BLOCKDEVS; do
- SWAPDEVS="$SWAPDEVS `fdisk -l $dev 2>/dev/null | tr '*' ' ' \
- | awk '$5 ~ /82/ {print $1}'`"
- done
-
- # now check if any of these partitions are swap, and activate if so
- for device in $SWAPDEVS; do
- sig=`dd if=$device bs=1 count=10 skip=$(( $PAGESIZE - 10 )) \
- 2>/dev/null`
- if [ "$sig" = "SWAPSPACE2" ]; then
- swapon $device
- fi
- done
-
-}
-
-case "$1" in
- start)
- start
- ;;
- *)
- echo "Usage: ovirt-early {start}"
- exit 2
-esac
-EOF
-
-chmod +x /etc/init.d/ovirt-early
-chkconfig ovirt-early on
-
# just to get a boot warning to shut up
touch /etc/resolv.conf
@@ -159,110 +24,6 @@ fi
EOF
chmod +x /etc/dhclient-exit-hooks
-echo "Writing ovirt init script"
-# ovirt startup script to do krb init
-cat > /etc/init.d/ovirt << \EOF
-#!/bin/bash
-#
-# ovirt Start ovirt services
-#
-# chkconfig: 3 11 99
-# description: ovirt services
-#
-
-# Source functions library
-. /etc/init.d/functions
-. /etc/init.d/ovirt-functions
-
-start() {
- echo -n $"Starting ovirt: "
-
- find_srv ipa tcp
- krb5_conf=/etc/krb5.conf
- if [ ! -s $krb5_conf ]; then
- rm -f $krb5_conf
- # FIXME this is IPA specific
- wget -q http://$SRV_HOST:$SRV_PORT/ipa/config/krb5.ini -O $krb5_conf \
- || die "Failed to get $krb5_conf"
- fi
- IPA_HOST=$SRV_HOST
- IPA_PORT=$SRV_PORT
-
- find_srv identify tcp
- krb5_tab=/etc/libvirt/krb5.tab
- ovirt-awake start $krb5_tab $SRV_HOST $SRV_PORT
-
- find_srv collectd tcp
- collectd_conf=/etc/collectd.conf
- if [ -f $collectd_conf.in -a $SRV_HOST -a $SRV_PORT ]; then
- sed -e "s/@COLLECTD_SERVER@/$SRV_HOST/" \
- -e "s/@COLLECTD_PORT@/$SRV_PORT/" $collectd_conf.in \
- > $collectd_conf \
- || die "Failed to write $collectd_conf"
- fi
-
- success
- echo
-}
-
-case "$1" in
- start)
- start
- ;;
- *)
- echo "Usage: ovirt {start}"
- exit 2
-esac
-EOF
-
-chmod +x /etc/init.d/ovirt
-chkconfig ovirt on
-
-echo "Writing ovirt-post init script"
-# ovirt startup script to finish init, started after libvirt
-cat > /etc/init.d/ovirt-post << \EOF
-#!/bin/bash
-#
-# ovirt Start ovirt services
-#
-# chkconfig: 3 98 02
-# description: ovirt-post services
-#
-
-# Source functions library
-. /etc/init.d/functions
-. /etc/init.d/ovirt-functions
-
-start() {
- echo -n $"Starting ovirt-post: "
-
- find_srv identify tcp
- UUID=`hal-get-property --udi \
- /org/freedesktop/Hal/devices/computer --key system.hardware.uuid`
-
- if [ -z $UUID ]; then
- ovirt-identify-node -s $SRV_HOST -p $SRV_PORT
- else
- ovirt-identify-node -s $SRV_HOST -p $SRV_PORT -u $UUID
- fi
-
- success
- echo
-}
-
-case "$1" in
- start)
- start
- ;;
- *)
- echo "Usage: ovirt-post {start}"
- exit 2
-esac
-EOF
-
-chmod +x /etc/init.d/ovirt-post
-chkconfig ovirt-post on
-
mkdir -p /etc/chkconfig.d
echo "# chkconfig: 345 98 02" > /etc/chkconfig.d/collectd
chkconfig collectd on
diff --git a/ovirt-managed-node/ovirt-managed-node.spec b/ovirt-managed-node/ovirt-managed-node.spec
index ee2f153..260a6fc 100644
--- a/ovirt-managed-node/ovirt-managed-node.spec
+++ b/ovirt-managed-node/ovirt-managed-node.spec
@@ -33,6 +33,16 @@ mkdir -p $RPM_BUILD_ROOT/sbin
cp ovirt-awake $RPM_BUILD_ROOT/sbin
cp ovirt-identify-node $RPM_BUILD_ROOT/sbin
+mkdir -p $RPM_BUILD_ROOT/etc/init.d
+cp init.d/ovirt-functions $RPM_BUILD_ROOT/etc/init.d
+cp init.d/ovirt-early $RPM_BUILD_ROOT/etc/init.d
+cp init.d/ovirt $RPM_BUILD_ROOT/etc/init.d
+cp init.d/ovirt-post $RPM_BUILD_ROOT/etc/init.d
+
+%post
+chkconfig ovirt-early on
+chkconfig ovirt on
+chkconfig ovirt-post on
%clean
rm -rf $RPM_BUILD_ROOT
@@ -40,5 +50,9 @@ rm -rf $RPM_BUILD_ROOT
%files
%defattr(755,root,root)
%doc README NEWS AUTHOR ChangeLog
+/etc/init.d/ovirt-functions
+/etc/init.d/ovirt-early
+/etc/init.d/ovirt
+/etc/init.d/ovirt-post
/sbin/ovirt-awake
/sbin/ovirt-identify-node
diff --git a/ovirt-managed-node/src/init.d/ovirt b/ovirt-managed-node/src/init.d/ovirt
new file mode 100644
index 0000000..a67c6bd
--- /dev/null
+++ b/ovirt-managed-node/src/init.d/ovirt
@@ -0,0 +1,51 @@
+#!/bin/bash
+#
+# ovirt Start ovirt services
+#
+# chkconfig: 3 11 99
+# description: ovirt services
+#
+
+# Source functions library
+. /etc/init.d/functions
+. /etc/init.d/ovirt-functions
+
+start() {
+ echo -n $"Starting ovirt: "
+
+ find_srv ipa tcp
+ krb5_conf=/etc/krb5.conf
+ if [ ! -s $krb5_conf ]; then
+ rm -f $krb5_conf
+ # FIXME this is IPA specific
+ wget -q http://$SRV_HOST:$SRV_PORT/ipa/config/krb5.ini -O $krb5_conf \
+ || die "Failed to get $krb5_conf"
+ fi
+ IPA_HOST=$SRV_HOST
+ IPA_PORT=$SRV_PORT
+
+ find_srv identify tcp
+ krb5_tab=/etc/libvirt/krb5.tab
+ ovirt-awake start $krb5_tab $SRV_HOST $SRV_PORT
+
+ find_srv collectd tcp
+ collectd_conf=/etc/collectd.conf
+ if [ -f $collectd_conf.in -a $SRV_HOST -a $SRV_PORT ]; then
+ sed -e "s/@COLLECTD_SERVER@/$SRV_HOST/" \
+ -e "s/@COLLECTD_PORT@/$SRV_PORT/" $collectd_conf.in \
+ > $collectd_conf \
+ || die "Failed to write $collectd_conf"
+ fi
+
+ success
+ echo
+}
+
+case "$1" in
+ start)
+ start
+ ;;
+ *)
+ echo "Usage: ovirt {start}"
+ exit 2
+esac
diff --git a/ovirt-managed-node/src/init.d/ovirt-early b/ovirt-managed-node/src/init.d/ovirt-early
new file mode 100644
index 0000000..3b4cf98
--- /dev/null
+++ b/ovirt-managed-node/src/init.d/ovirt-early
@@ -0,0 +1,104 @@
+#!/bin/bash
+#
+# ovirt-early Start early ovirt services
+#
+# chkconfig: 3 01 99
+# description: ovirt-early services
+#
+
+# Source functions library
+. /etc/init.d/functions
+. /etc/init.d/ovirt-functions
+
+configure_from_network() {
+ DEVICE=$1
+ if [ -n "$DEVICE" ]; then
+ printf .
+ # setup temporary interface to retrieve configuration
+ echo "network --device $DEVICE --bootproto dhcp" | nash
+ if [ $? -eq 0 ]; then
+ printf .
+ # from network-scripts/ifup-post
+ IPADDR=$(LC_ALL=C ip -o -4 addr ls dev ${DEVICE} | awk '{ print $4 ; exit }')
+ eval $(ipcalc --silent --hostname ${IPADDR} ; echo "status=$?")
+ if [ "$status" = "0" ]; then
+ hostname $HOSTNAME
+ # retrieve remote config
+ find_srv ovirt tcp
+ printf .
+ if [ -n "$SRV_HOST" -a -n "$SRV_PORT" ]; then
+ wget --quiet -O - "http://$SRV_HOST:$SRV_PORT/ovirt/cfgdb/$(hostname)" \
+ | augtool > /dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ printf "remote config applied."
+ return
+ fi
+ fi
+ fi
+ fi
+ fi
+ # default oVirt network configuration:
+ # bridge each ethernet device in the system
+ ETHDEVS=$(cd /sys/class/net && ls -d eth*)
+ for eth in $ETHDEVS; do
+ BRIDGE=ovirtbr`echo $eth | cut -b4-`
+ printf '%s\n' "DEVICE=$eth" ONBOOT=yes "BRIDGE=$BRIDGE" \
+ > /etc/sysconfig/network-scripts/ifcfg-$eth
+ printf '%s\n' "DEVICE=$BRIDGE" BOOTPROTO=dhcp \
+ ONBOOT=yes TYPE=Bridge PEERNTP=yes \
+ > /etc/sysconfig/network-scripts/ifcfg-$BRIDGE
+ done
+ printf "default config applied."
+}
+
+start() {
+ # find boot interface from cmdline
+ # IPAPPEND 2 in pxelinux.cfg appends e.g. BOOTIF=01-00-16-3e-12-34-57
+ BOOTIF=
+ for i in $(cat /proc/cmdline); do
+ case $i in
+ BOOTIF=??-??-??-??-??-??-??)
+ i=${i/#BOOTIF=??-/}
+ BOOTMAC=${i//-/:}
+ BOOTIF=$(grep -l $BOOTMAC /sys/class/net/eth*/address|rev|cut -d/ -f2|rev)
+ ;;
+ esac
+ done
+ configure_from_network $BOOTIF
+
+ # find all of the partitions on the system
+
+ # get the system pagesize
+ PAGESIZE=`getconf PAGESIZE`
+
+ # look first at raw partitions
+ BLOCKDEVS=`ls /dev/sd? /dev/hd? 2>/dev/null`
+
+ # now LVM partitions
+ LVMDEVS="$DEVICES `lvscan | awk '{print $2}' | tr -d \"'\"`"
+
+ SWAPDEVS="$LVMDEVS"
+ for dev in $BLOCKDEVS; do
+ SWAPDEVS="$SWAPDEVS `fdisk -l $dev 2>/dev/null | tr '*' ' ' \
+ | awk '$5 ~ /82/ {print $1}'`"
+ done
+
+ # now check if any of these partitions are swap, and activate if so
+ for device in $SWAPDEVS; do
+ sig=`dd if=$device bs=1 count=10 skip=$(( $PAGESIZE - 10 )) \
+ 2>/dev/null`
+ if [ "$sig" = "SWAPSPACE2" ]; then
+ swapon $device
+ fi
+ done
+
+}
+
+case "$1" in
+ start)
+ start
+ ;;
+ *)
+ echo "Usage: ovirt-early {start}"
+ exit 2
+esac
diff --git a/ovirt-managed-node/src/init.d/ovirt-functions b/ovirt-managed-node/src/init.d/ovirt-functions
new file mode 100644
index 0000000..98257fb
--- /dev/null
+++ b/ovirt-managed-node/src/init.d/ovirt-functions
@@ -0,0 +1,18 @@
+# -*-Shell-script-*-
+
+find_srv() {
+ local dnsreply
+ dnsreply=$(dig +short -t srv _$1._$2.$(dnsdomainname))
+ if [ $? -eq 0 ]; then
+ set _ $dnsreply; shift
+ SRV_HOST=$4; SRV_PORT=$3
+ else
+ SRV_HOST=; SRV_PORT=
+ fi
+}
+
+die()
+{
+ echo "$@" 1>&2; failure; echo 1>&2; exit 1
+}
+
diff --git a/ovirt-managed-node/src/init.d/ovirt-post b/ovirt-managed-node/src/init.d/ovirt-post
new file mode 100644
index 0000000..2fb07a4
--- /dev/null
+++ b/ovirt-managed-node/src/init.d/ovirt-post
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# ovirt Start ovirt services
+#
+# chkconfig: 3 98 02
+# description: ovirt-post services
+#
+
+# Source functions library
+. /etc/init.d/functions
+. /etc/init.d/ovirt-functions
+
+start() {
+ echo -n $"Starting ovirt-post: "
+
+ find_srv identify tcp
+ UUID=`hal-get-property --udi \
+ /org/freedesktop/Hal/devices/computer --key system.hardware.uuid`
+
+ if [ -z $UUID ]; then
+ ovirt-identify-node -s $SRV_HOST -p $SRV_PORT
+ else
+ ovirt-identify-node -s $SRV_HOST -p $SRV_PORT -u $UUID
+ fi
+
+ success
+ echo
+}
+
+case "$1" in
+ start)
+ start
+ ;;
+ *)
+ echo "Usage: ovirt-post {start}"
+ exit 2
+esac
diff --git a/ovirt-managed-node/src/ovirt-identify-node.c b/ovirt-managed-node/src/ovirt-identify-node.c
index 0368717..819f700 100644
--- a/ovirt-managed-node/src/ovirt-identify-node.c
+++ b/ovirt-managed-node/src/ovirt-identify-node.c
@@ -283,7 +283,7 @@ ssize_t safewrite(int fd, const void *buf, size_t count)
{
size_t nwritten = 0;
while (count > 0) {
- ssize_t r = write(fd, buf+nwritten, count);
+ ssize_t r = write(fd, buf, count);
if (r < 0 && errno == EINTR)
continue;
--
1.5.5.1
More information about the ovirt-devel
mailing list