[node-patches] Change in ovirt-node[master]: Add on-shutdown hooks
rbarry at redhat.com
rbarry at redhat.com
Thu Apr 9 16:43:54 UTC 2015
Ryan Barry has uploaded a new change for review.
Change subject: Add on-shutdown hooks
......................................................................
Add on-shutdown hooks
With requests to save some files which aren't managed by the TUI
or our config classes on reboot, add on-shutdown hooks which run
when the system comes down so we can execute things there.
For now, this is only used for saving virt-who config files.
Change-Id: I2cc830b1b4b28db29a3fe995ac31c36b15cf6676
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1209356
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M hooks/Makefile.am
M hooks/README
A hooks/on-shutdown/01-save-virtwho.py
M ovirt-node.spec.in
M services/init/ovirt-node-hooks.conf
M services/ovirt-node-hooks.service
6 files changed, 37 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/30/39730/1
diff --git a/hooks/Makefile.am b/hooks/Makefile.am
index f008d35..ff68c45 100644
--- a/hooks/Makefile.am
+++ b/hooks/Makefile.am
@@ -16,7 +16,15 @@
# also available at http://www.gnu.org/copyleft/gpl.html.
onbootdir = $(libexecdir)/ovirt-node/hooks/on-boot
+onshutdowndir = $(libexecdir)/ovirt-node/hooks/on-shutdown
dist_onboot_SCRIPTS = \
on-boot/03-validate-owner-ssh-keys \
$(NULL)
+
+dist_onshutdown_SCRIPTS = \
+ on-shutdown/01-save-virtwho.py
+
+install-data-hook:
+ mv $(DESTDIR)$(libexecdir)/ovirt-node/hooks/on-shutdown/01-save-virtwho.py \
+ $(DESTDIR)$(libexecdir)/ovirt-node/hooks/on-shutdown/01-save-virtwho
diff --git a/hooks/README b/hooks/README
index b544b01..ae75767 100644
--- a/hooks/README
+++ b/hooks/README
@@ -1,2 +1,2 @@
on-boot dir contains scripts that will run during the boot.
-
+on-shutdown dir contains scripts that will be run during shutdown.
diff --git a/hooks/on-shutdown/01-save-virtwho.py b/hooks/on-shutdown/01-save-virtwho.py
new file mode 100755
index 0000000..a33022f
--- /dev/null
+++ b/hooks/on-shutdown/01-save-virtwho.py
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# 01-save-virtwho - Copyright (C) 2015 Red Hat, Inc.
+#
+# 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.
+from glob import glob
+from ovirt.node.utils.fs import Config
+
+
+if __name__ == "__main__":
+ for f in glob("/etc/virt-who.d/*"):
+ try:
+ Config().persist(f)
+ except:
+ "Couldn't persist {f}!".format(f=f)
+ raise
diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index 513acca..28a0107 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -638,6 +638,7 @@
%{__install} -d -m0755 %{buildroot}%{_libexecdir}/ovirt-node/hooks/post-upgrade
%{__install} -d -m0755 %{buildroot}%{_libexecdir}/ovirt-node/hooks/rollback
%{__install} -d -m0755 %{buildroot}%{_libexecdir}/ovirt-node/hooks/on-boot
+%{__install} -d -m0755 %{buildroot}%{_libexecdir}/ovirt-node/hooks/on-shutdown
%{__install} -d -m0755 %{buildroot}%{_libexecdir}/ovirt-node/hooks/on-changed-boot-image
# dracut patches for rhel6
diff --git a/services/init/ovirt-node-hooks.conf b/services/init/ovirt-node-hooks.conf
index a12d9ca..f70ed2f 100755
--- a/services/init/ovirt-node-hooks.conf
+++ b/services/init/ovirt-node-hooks.conf
@@ -1,4 +1,6 @@
start on started vdsmd
+stop on runlevel [S06]
task
exec /usr/libexec/ovirt-node-hooks trigger on-boot
+post-stop exec /usr/libexec/ovirt-node-hooks trigger on-shutdown
diff --git a/services/ovirt-node-hooks.service b/services/ovirt-node-hooks.service
index 84a0c4d..0f226fa 100644
--- a/services/ovirt-node-hooks.service
+++ b/services/ovirt-node-hooks.service
@@ -8,6 +8,7 @@
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/libexec/ovirt-node-hooks trigger on-boot
+ExecStop=/usr/libexec/ovirt-node-hooks trigger on-shutdown
[Install]
WantedBy=multi-user.target
--
To view, visit https://gerrit.ovirt.org/39730
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2cc830b1b4b28db29a3fe995ac31c36b15cf6676
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