Zhou Zheng Sheng has uploaded a new change for review.
Change subject: make vdsmd.init.in adapt to both Fedora and Ubuntu ......................................................................
make vdsmd.init.in adapt to both Fedora and Ubuntu
The patch is on going work of porting VDSM to Ubuntu http://www.ovirt.org/VDSM_on_Ubuntu
Change-Id: I186743ed7fd345bf150047d4005818e1df3c07fc Signed-off-by: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com --- M vdsm/vdsmd.init.in 1 file changed, 75 insertions(+), 24 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/89/13489/1
diff --git a/vdsm/vdsmd.init.in b/vdsm/vdsmd.init.in index c804ce8..85bc61b 100755 --- a/vdsm/vdsmd.init.in +++ b/vdsm/vdsmd.init.in @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash # # Copyright 2006-2010 Red Hat, Inc. and/or its affiliates. # @@ -23,6 +23,16 @@
. @LIBEXECDIR@/ovirt_functions.sh
+choosePath() { + for P in "$@"; do + if [ -e "$P" ]; then + echo "$P" + return 0 + fi + done + echo "$1" +} + VDSM_BIN=@VDSMDIR@/vdsm CONF_FILE=@CONFDIR@/vdsm.conf GETCONFITEM=@VDSMDIR@/get-conf-item @@ -33,7 +43,24 @@ DOM_METADATA_BACKUP_DIR=/var/log/vdsm/backup CORE_PATTERN=/proc/sys/kernel/core_pattern QEMU_DUMP_PATH="/var/log/core" -NEEDED_SERVICES="iscsid multipathd ntpd wdmd sanlock network" +SERVICE="$(choosePath /sbin/service /usr/sbin/service)" +LOCK_PATH="$(choosePath /var/lock/subsys /var/lock)" + +ISCSID=iscsid +LIBVIRTD=libvirtd +MULTIPATHD=multipathd +NETWORK=network +NTPD=ntpd +SANLOCK=sanlock +WDMD=wdmd +if grep -i ubuntu /etc/*-release >/dev/null 2>&1; then + ISCSID=open-iscsi + LIBVIRTD=libvirt-bin + MULTIPATHD=multipath-tools + NETWORK=netowking + NTPD=ntp +fi +NEEDED_SERVICES="$ISCSID $MULTIPATHD $NTPD $WDMD $SANLOCK $NETWORK" CONFLICTING_SERVICES="libvirt-guests"
# trigger for reconfiguration @@ -41,7 +68,7 @@
LCONF=/etc/libvirt/libvirtd.conf QCONF=/etc/libvirt/qemu.conf -LDCONF=/etc/sysconfig/libvirtd +LDCONF="$(choosePath /etc/sysconfig/libvirtd /etc/default/libvirt-bin)" QLCONF=/etc/libvirt/qemu-sanlock.conf
is_coredump=`$GETCONFITEM $CONF_FILE vars core_dump_enable false | tr A-Z a-z` @@ -49,10 +76,17 @@
SYSTEMCTL_SKIP_REDIRECT=true
-. /etc/init.d/functions - -log_failure_msg() { echo -n "$@"; failure "$@"; echo; } -log_success_msg() { echo -n "$@"; success "$@"; echo; } +if [ -e /etc/init.d/functions ]; then + . /etc/init.d/functions + log_failure_msg() { echo -n "$@"; failure "$@"; echo; } + log_success_msg() { echo -n "$@"; success "$@"; echo; } +else + . /lib/lsb/init-functions + # log_failure_msg and log_success_msg are defined already + # in /lib/lsb/init-functions + failure() { local rc=$?; log_failure_msg; return "$rc"; } + success() { log_success_msg; return 0; } +fi
mk_data_center() { local dc @@ -122,13 +156,13 @@
for srv in $CONFLICTING_SERVICES do - /sbin/chkconfig $srv off - if /sbin/service $srv status > /dev/null 2>&1; + disable_service_sysv $srv + if "$SERVICE" $srv status > /dev/null 2>&1; then if [ "$srv" == "libvirt-guests" ]; then - /bin/rm -f /var/lock/subsys/libvirt-guests + /bin/rm -f "$LOCK_PATH/libvirt-guests" else - /sbin/service $srv stop + "$SERVICE" $srv stop fi fi done @@ -145,10 +179,10 @@
for srv in $NEEDED_SERVICES do - if ! /sbin/service $srv status > /dev/null 2>&1; + if ! "$SERVICE" $srv status > /dev/null 2>&1; then echo "Starting $srv..." - /sbin/service $srv start + "$SERVICE" $srv start ret_val=$? if [ $ret_val -ne 0 ] then @@ -158,7 +192,7 @@ fi done
- /sbin/service iscsid force-start + "$SERVICE" $ISCSID force-start || true }
test_lo() { @@ -216,7 +250,7 @@ # Remove configuration created by vdsm (old "# by vdsm" and the new format) # Argument: configuration file that will be inspected remove_vdsm_conf() { - sed -i --copy -e "/${start_conf_section}/,/${end_conf_section}/d" \ + sed -i -e "/${start_conf_section}/,/${end_conf_section}/d" \ -e "/$by_vdsm/d" "$@" }
@@ -363,7 +397,7 @@ ovirt_store_config "$lconf" "$qconf" "$ldconf" "$llogr"
if libvirt_should_use_upstart; then - /sbin/initctl restart libvirtd 2>/dev/null || : + /sbin/initctl restart $LIBVIRTD 2>/dev/null || : else /bin/systemctl restart libvirtd.service fi @@ -394,12 +428,22 @@ configure_libvirt $args }
+disable_service_sysv() { + if [ -e /sbin/chkconfig ]; then + /sbin/chkconfig "$1" off + elif [ -e /usr/sbin/update-rc.d ]; then + /usr/sbin/update-rc.d "$1" disable + else + false + fi +} + stop_libvirtd_sysv() { # stop libvirt SysV service if we intend to configure upstart
- if libvirt_should_use_upstart && ! [[ -f /etc/init/libvirtd.conf ]]; then - /sbin/chkconfig libvirtd off - /sbin/service libvirtd stop + if libvirt_should_use_upstart && ! [[ -f /etc/init/"$LIBVIRTD".conf ]]; then + disable_service_sysv $LIBVIRTD + "$SERVICE" $LIBVIRTD stop fi }
@@ -408,7 +452,7 @@ local startout
if ! libvirt_should_use_upstart; then - /sbin/service libvirtd start + "$SERVICE" $LIBVIRTD start return fi
@@ -422,7 +466,7 @@ /sbin/initctl reload-configuration fi
- startout=`/sbin/initctl start libvirtd 2>&1` + startout=`/sbin/initctl start $LIBVIRTD 2>&1` if [[ "$?" -eq 0 || "$startout" =~ .*already\ running.* ]]; then return 0 @@ -505,12 +549,19 @@ echo $"Starting up vdsm daemon: " local vdsm_nice=`$GETCONFITEM $CONF_FILE vars vdsm_nice -5`
+ if type daemon >/dev/null 2>&1; then + RUNDAEMON="daemon --user=vdsm" + elif type start_daemon >/dev/null 2>&1; then + RUNDAEMON="start_daemon -n $vdsm_nice -- /usr/bin/sudo -u vdsm" + else + RUNDAEMON="false" + fi LIBVIRT_LOG_FILTERS=`$GETCONFITEM $CONF_FILE vars libvirt_log_filters "1:libvirt 1:remote"` \ LIBVIRT_LOG_OUTPUTS=`$GETCONFITEM $CONF_FILE vars libvirt_log_outputs "1:file:/var/log/vdsm/libvirt.log"` \ - LC_ALL=C NICELEVEL=$vdsm_nice daemon --user=vdsm @VDSMDIR@/respawn --minlifetime 10 --daemon --masterpid $RESPAWNPIDFILE $VDSM_BIN + LC_ALL=C NICELEVEL=$vdsm_nice $RUNDAEMON @VDSMDIR@/respawn --minlifetime 10 --daemon --masterpid $RESPAWNPIDFILE $VDSM_BIN RETVAL=$? [ "$RETVAL" -eq 0 ] && log_success_msg $"$prog start" || log_failure_msg $"$prog start" - [ "$RETVAL" -eq 0 ] && touch /var/lock/subsys/vdsmd + [ "$RETVAL" -eq 0 ] && touch "$LOCK_PATH/vdsmd" }
stop() { @@ -525,7 +576,7 @@ killproc -p $PIDFILE -d 2 RETVAL=$? [ "$RETVAL" -eq 0 ] && log_success_msg $"$prog stop" || log_failure_msg $"$prog stop" - [ "$RETVAL" -eq 0 ] && rm -f /var/lock/subsys/vdsmd + [ "$RETVAL" -eq 0 ] && rm -f "LOCK_PATH/vdsmd" fi python @VDSMDIR@/hooks.pyc after_vdsm_stop return $RETVAL
-- To view, visit http://gerrit.ovirt.org/13489 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange Gerrit-Change-Id: I186743ed7fd345bf150047d4005818e1df3c07fc Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com
oVirt Jenkins CI Server has posted comments on this change.
Change subject: make vdsmd.init.in adapt to both Fedora and Ubuntu ......................................................................
Patch Set 1:
Build Started http://jenkins.ovirt.org/job/vdsm_pep8_gerrit/1764/ (1/2)
-- To view, visit http://gerrit.ovirt.org/13489 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I186743ed7fd345bf150047d4005818e1df3c07fc Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
oVirt Jenkins CI Server has posted comments on this change.
Change subject: make vdsmd.init.in adapt to both Fedora and Ubuntu ......................................................................
Patch Set 1:
Build Started http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/1815/ (2/2)
-- To view, visit http://gerrit.ovirt.org/13489 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I186743ed7fd345bf150047d4005818e1df3c07fc Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
oVirt Jenkins CI Server has posted comments on this change.
Change subject: make vdsmd.init.in adapt to both Fedora and Ubuntu ......................................................................
Patch Set 1:
Build Successful
http://jenkins.ovirt.org/job/vdsm_pep8_gerrit/1764/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/1815/ : SUCCESS
-- To view, visit http://gerrit.ovirt.org/13489 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I186743ed7fd345bf150047d4005818e1df3c07fc Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
oVirt Jenkins CI Server has posted comments on this change.
Change subject: make vdsmd.init.in adapt to both Fedora and Ubuntu ......................................................................
Patch Set 2:
Build Started http://jenkins.ovirt.org/job/vdsm_pep8_gerrit/1765/ (1/2)
-- To view, visit http://gerrit.ovirt.org/13489 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I186743ed7fd345bf150047d4005818e1df3c07fc Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
oVirt Jenkins CI Server has posted comments on this change.
Change subject: make vdsmd.init.in adapt to both Fedora and Ubuntu ......................................................................
Patch Set 2:
Build Started http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/1816/ (2/2)
-- To view, visit http://gerrit.ovirt.org/13489 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I186743ed7fd345bf150047d4005818e1df3c07fc Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
oVirt Jenkins CI Server has posted comments on this change.
Change subject: make vdsmd.init.in adapt to both Fedora and Ubuntu ......................................................................
Patch Set 2:
Build Successful
http://jenkins.ovirt.org/job/vdsm_pep8_gerrit/1765/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/1816/ : SUCCESS
-- To view, visit http://gerrit.ovirt.org/13489 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I186743ed7fd345bf150047d4005818e1df3c07fc Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
Zhou Zheng Sheng has posted comments on this change.
Change subject: make vdsmd.init.in adapt to both Fedora and Ubuntu ......................................................................
Patch Set 2: I would prefer that you didn't submit this
(1 inline comment)
.................................................... File vdsm/vdsmd.init.in Line 574: else Line 575: killproc -p $PIDFILE -d 2 Line 576: RETVAL=$? Line 577: [ "$RETVAL" -eq 0 ] && log_success_msg $"$prog stop" || log_failure_msg $"$prog stop" Line 578: [ "$RETVAL" -eq 0 ] && rm -f "LOCK_PATH/vdsmd" Oops. Miss a $ here. Line 579: fi Line 580: python @VDSMDIR@/hooks.pyc after_vdsm_stop Line 581: return $RETVAL Line 582: }
-- To view, visit http://gerrit.ovirt.org/13489 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I186743ed7fd345bf150047d4005818e1df3c07fc Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
Dan Kenigsberg has posted comments on this change.
Change subject: make vdsmd.init.in adapt to both Fedora and Ubuntu ......................................................................
Patch Set 2: I would prefer that you didn't submit this
(1 inline comment)
Your changes seem fine, but they only add to the monstrosity that is vdsmd.init.
Can we be more brutal, and break vdsmd.init apart? No other sysv service is that huge, and not other upstart service use such a horrible script.
.................................................... File vdsm/vdsmd.init.in Line 248: Line 249: # Remove configuration created by vdsm (old "# by vdsm" and the new format) Line 250: # Argument: configuration file that will be inspected Line 251: remove_vdsm_conf() { Line 252: sed -i -e "/${start_conf_section}/,/${end_conf_section}/d" \ this --copy is (used to be?) important for ovirt-node. Line 253: -e "/$by_vdsm/d" "$@" Line 254: } Line 255: Line 256: set_if_default() {
-- To view, visit http://gerrit.ovirt.org/13489 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I186743ed7fd345bf150047d4005818e1df3c07fc Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
Zhou Zheng Sheng has posted comments on this change.
Change subject: make vdsmd.init.in adapt to both Fedora and Ubuntu ......................................................................
Patch Set 2:
Thanks Dan. I agree that the init file is huge. When I read the code, the complexity comes from the actual work it does. (1) In systemd we can define conflicting and dependency service, but sysv init file lacks this ability. So we implement these functions in the init script. (2) It detects and modifies libvirt conf files. (3) Many trivial but necessary works like mk_data_center, mk_core_path, mk_dom_backup, /bin/chmod 1777 /dev/shm...
I think we can improve the situation for (1) by implementing some of the service management utility functions in VDSM-tools in a portable way. Improve (2) by using augtool. For (3), we are already doing the best. I think it's better to keep those trivial but necessary things in one place and manage them together. After these optimizations, the size of the init script may be halved.
I once tried to break it and found there would be much testing work to prove we do it right, and might introduce ugly bugs. Now I'm glad we all agree to break it.
-- To view, visit http://gerrit.ovirt.org/13489 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I186743ed7fd345bf150047d4005818e1df3c07fc Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
Zhou Zheng Sheng has abandoned this change.
Change subject: make vdsmd.init.in adapt to both Fedora and Ubuntu ......................................................................
Patch Set 2: Abandoned
This patch makes vdsmd.init.in more complicated. So I submit new patches to break vdsmd.init.in into pieces, then port it to Ubuntu. The newly submit patches are as follow.
http://gerrit.ovirt.org/13701 http://gerrit.ovirt.org/13702
-- To view, visit http://gerrit.ovirt.org/13489 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: abandon Gerrit-Change-Id: I186743ed7fd345bf150047d4005818e1df3c07fc Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
vdsm-patches@lists.fedorahosted.org