[node-patches] Change in ovirt-node[master]: Move hooks to their own service

rbarry at redhat.com rbarry at redhat.com
Wed Apr 1 18:27:00 UTC 2015


Ryan Barry has uploaded a new change for review.

Change subject: Move hooks to their own service
......................................................................

Move hooks to their own service

Don't run hooks as part of post anymore. Run them as their own
service after vdsm, so we can avoid any potential races with
with libvirt starting

Change-Id: I0fac31b94ed0531c3c10d2c86fd7f819549cc3a1
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M .gitignore
M configure.ac
M ovirt-node.spec.in
M scripts/Makefile.am
A scripts/ovirt-hooks.sh.in
M scripts/ovirt-init-functions.sh.in
M services/Makefile.am
A services/init.d/ovirt-hooks
A services/ovirt-hooks.service
9 files changed, 157 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/65/39465/1

diff --git a/.gitignore b/.gitignore
index a96cdfb..28f6a6d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,7 @@
 py-compile
 scripts/ovirt-functions
 scripts/ovirt-init-functions.sh
+scripts/ovirt-hooks.sh
 .project
 .pydevproject
 .settings
diff --git a/configure.ac b/configure.ac
index 7a988c4..6178e4a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -135,6 +135,7 @@
                 recipe/image-minimizer.ks
                 scripts/ovirt-functions
                 scripts/ovirt-init-functions.sh
+                scripts/ovirt-hooks.sh
                 semodule/ovirt.te
                 ovirt-node.spec])
 AC_OUTPUT
diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index 344e7ff..63271d0 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -1031,6 +1031,7 @@
 %{_libexecdir}/ovirt-admin-shell
 %{_libexecdir}/ovirt-config-password
 %{_libexecdir}/ovirt-init-functions.sh
+%{_libexecdir}/ovirt-hooks
 %{_sbindir}/persist
 %{_sbindir}/unpersist
 %{_sbindir}/ovirt-node-upgrade
@@ -1051,6 +1052,7 @@
 %{_unitdir}/ovirt-post.service
 %{_unitdir}/ovirt-early.service
 %{_unitdir}/ovirt-kdump.service
+%{_unitdir}/ovirt-hooks.service
 %else
 %{_initrddir}/ovirt-awake
 %{_initrddir}/ovirt-early
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 9facb20..d7d68bd 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -35,6 +35,7 @@
   ovirt-config-uninstall \
   ovirt-functions \
   ovirt-init-functions.sh \
+  ovirt-hooks.sh \
   ovirt-auto-install.py \
   ovirt-admin-shell \
   ovirt-node-igor-slave
@@ -49,6 +50,7 @@
 install-exec-hook:
 	mv $(DESTDIR)$(libexecdir)/ovirt-auto-install.py $(DESTDIR)$(libexecdir)/ovirt-auto-install
 	mv $(DESTDIR)$(sbindir)/ovirt-node-upgrade.py $(DESTDIR)$(sbindir)/ovirt-node-upgrade
+	mv $(DESTDIR)$(libexecdir)/ovirt-hooks.sh $(DESTDIR)$(libexecdir)/ovirt-hooks
 
 	mkdir -p --mode=0755 \
 	  $(DESTDIR)$(localboottriggerdir) \
diff --git a/scripts/ovirt-hooks.sh.in b/scripts/ovirt-hooks.sh.in
new file mode 100644
index 0000000..b42b17f
--- /dev/null
+++ b/scripts/ovirt-hooks.sh.in
@@ -0,0 +1,99 @@
+#!/bin/bash
+#
+# ovirt-hooks.sh - Wrapps all functions needed by oVirt at boot time.
+#
+# Copyright (C) 2015 Red Hat, Inc.
+# Written by Ryan Barry <rbarry at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.  A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+#
+
+. /etc/init.d/functions
+. /usr/libexec/ovirt-functions
+. /usr/libexec/ovirt-init-functions.sh
+
+. @DRACUTDIR@/91ovirtnode/ovirt-boot-functions
+
+
+VAR_SUBSYS_OVIRT_HOOKS=/var/lock/subsys/ovirt-hooks
+HOOK_ON_BOOT_DIR=/usr/libexec/ovirt-node/hooks/on-boot
+
+start_ovirt_hooks () {
+    breakpoint "pre-hooks"
+    [ -f "$VAR_SUBSYS_OVIRT_HOOKS" ] && exit 0
+    {
+        log "Starting ovirt-hooks service"
+
+        touch $VAR_SUBSYS_OVIRT_HOOKS
+        # Run on-boot hooks
+        if [[ -d "$HOOK_ON_BOOT_DIR" ]] && [[ "$(ls -A $HOOK_ON_BOOT_DIR)" ]];
+        then
+            for handler in "$HOOK_ON_BOOT_DIR"/*;
+            do
+                log "Running handler: $handler"
+                "$handler" >> $OVIRT_LOGFILE 2>&1
+            done
+        fi
+
+        rm -f $VAR_SUBSYS_OVIRT_HOOKS
+
+        log "Completed ovirt-hooks"
+    } >> $OVIRT_LOGFILE 2>&1
+}
+
+stop_ovirt_hooks () {
+    {
+        log "Stopping ovirt-hooks"
+        # Placeholder in the unlikely case we want to add hooks for shutdown
+        log "Stopped ovirt-hooks"
+    } >> $OVIRT_LOGFILE 2>&1
+}
+
+restart_ovirt_hooks () {
+    echo "Restarting ovirt-hooks is not implemented"
+    return 0
+}
+
+status_ovirt_hooks () {
+    return 0
+}
+
+reload_ovirt_hooks () {
+    echo "Reloading ovirt-hooks is not implemented"
+    return 0
+}
+
+case "$1" in
+    "start")
+        start_ovirt_hooks
+        ;;
+    "stop")
+        stop_ovirt_hooks
+        ;;
+    "restart"|"try-restart")
+        restart_ovirt_hooks
+        ;;
+    "status")
+        status_ovirt_hooks
+        ;;
+    "reload"|"force-reload")
+        reload_ovirt_hooks
+        ;;
+    *)
+        echo "Please call with [start|stop]"
+        ;;
+
+esac
diff --git a/scripts/ovirt-init-functions.sh.in b/scripts/ovirt-init-functions.sh.in
index be153af..40a2af0 100644
--- a/scripts/ovirt-init-functions.sh.in
+++ b/scripts/ovirt-init-functions.sh.in
@@ -37,8 +37,6 @@
 AUGTOOL_CONFIG=/var/tmp/augtool-config
 EARLY_DIR=/etc/ovirt-early.d
 
-HOOK_ON_BOOT_DIR=/usr/libexec/ovirt-node/hooks/on-boot
-
 # Drop to a shell
 emergency_shell() {
     plymouth --hide-splash
@@ -1476,16 +1474,6 @@
         #iscsi installs with hang when network service is killed
         if [ -e "/dev/disk/by-label/Boot" ]; then
             rm  /var/lock/subsys/network
-        fi
-
-        # Run on-boot hooks
-        if [[ -d "$HOOK_ON_BOOT_DIR" ]] && [[ "$(ls -A $HOOK_ON_BOOT_DIR)" ]];
-        then
-            for handler in "$HOOK_ON_BOOT_DIR"/*;
-            do
-                log "Running handler: $handler"
-                "$handler" >> $OVIRT_LOGFILE 2>&1
-            done
         fi
 
         # FIXME is this still needed?
diff --git a/services/Makefile.am b/services/Makefile.am
index 1dec6e0..53c0667 100644
--- a/services/Makefile.am
+++ b/services/Makefile.am
@@ -27,6 +27,7 @@
   ovirt-firstboot.service \
   ovirt-cim.service \
   ovirt-kdump.service \
+  ovirt-hooks.service \
   ovirt-node-igor-slave.service
 else
 dist_initd_SCRIPTS = \
@@ -37,6 +38,7 @@
   init.d/ovirt-post \
   init.d/ovirt-firstboot \
   init.d/ovirt-cim \
+  init.d/ovirt-hooks\
   init.d/ovirt-node-igor-slave
 endif
 
diff --git a/services/init.d/ovirt-hooks b/services/init.d/ovirt-hooks
new file mode 100755
index 0000000..24e693c
--- /dev/null
+++ b/services/init.d/ovirt-hooks
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# ovirt Start ovirt hooks
+#
+### BEGIN INIT INFO
+# Provides: ovirt-hooks
+# Required-Start: vdsmd
+# Default-Start: 2 3 4 5
+# Description: Runs managed node post configuration hooks. 
+### END INIT INFO
+
+prog=ovirt-hooks
+
+case "$1" in
+    start)
+        echo -n "Starting ovirt-hooks: "
+        /usr/libexec/ovirt-hooks start
+        test $? == 0 && success || failure
+        echo
+        ;;
+    status)
+        status -l $prog
+        ;;
+    reload)
+        /usr/libexec/ovirt-hooks reload
+        ;;
+    stop)
+        echo -n "Stopping ovirt-hooks: "
+        /usr/libexec/ovirt-hooks stop
+        test $? == 0 && success || failure
+        echo
+        ;;
+    *)
+        echo "Usage: ovirt-hooks {start}"
+        exit 2
+esac
diff --git a/services/ovirt-hooks.service b/services/ovirt-hooks.service
new file mode 100644
index 0000000..86c9c15
--- /dev/null
+++ b/services/ovirt-hooks.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=oVirt Node post configuration service
+After=supervdsmd.service vdsmd.service sanlock.service
+Wants=vdsmd.service
+Before=getty at tty1.service vdsmd.service supervdsmd.service sanlock.service
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/usr/libexec/ovirt-hooks start
+ExecStop=/usr/libexec/ovirt-hooks stop
+
+[Install]
+WantedBy=multi-user.target


-- 
To view, visit https://gerrit.ovirt.org/39465
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0fac31b94ed0531c3c10d2c86fd7f819549cc3a1
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Ryan Barry <rbarry at redhat.com>



More information about the node-patches mailing list