Skip to contentSkip to conversation

master - lvmconf: fix systemd unit existence check for lvmconf --services --startstopservices

PATCH Peter Rajnoha 1 participant 1 message Apr 5, 2017

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=448bf9491a10715650569d5eeceb1026941d70ae
Commit:        448bf9491a10715650569d5eeceb1026941d70ae
Parent:        afa844817a716f054f1e56612fa19522225797f4
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Wed Apr 5 11:06:56 2017 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Wed Apr 5 11:06:56 2017 +0200

lvmconf: fix systemd unit existence check for lvmconf --services --startstopservices

We have to unset the LoadState variable from previous use when we check for systemd unit state. We use this variable to check if systemd services are loaded or not and if it is loaded, we issue systemctl commands to enable/disable and start/stop the service. We don't issue these commands if the unit is not loaded to avoid error messages which may confuse users.

---
 WHATS_NEW          |    1 +
 scripts/lvmconf.sh |    6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
WHATS_NEW +1 -0
index abff1c8..57e01d4 100644
@@ -1,5 +1,6 @@
 Version 2.02.170 - 
 ==================================
+  Fix systemd unit existence check for lvmconf --services --startstopservices.
   Check and use PATH_MAX buffers when creating vgrename device paths.
 
 Version 2.02.169 - 28th March 2017
scripts/lvmconf.sh +4 -2
index a86036d..caf7fae 100644
@@ -361,7 +361,8 @@ function set_service {
     if [ "$type" = "systemd" ]; then
         if [ "$action" = "activate" ]; then
             for i in $@; do
-                eval $($SYSTEMCTL_BIN show $i -p LoadState)
+                unset LoadState
+                eval $($SYSTEMCTL_BIN show $i -p LoadState 2>/dev/null)
                 test  "$LoadState" = "loaded" || continue
                 $SYSTEMCTL_BIN enable $i
                 if [ "$START_STOP_SERVICES" = "1" ]; then
@@ -370,7 +371,8 @@ function set_service {
             done
         elif [ "$action" = "deactivate" ]; then
             for i in $@; do
-                eval $($SYSTEMCTL_BIN show $i -p LoadState)
+                unset LoadState
+                eval $($SYSTEMCTL_BIN show $i -p LoadState 2>/dev/null)
                 test  "$LoadState" = "loaded" || continue
                 $SYSTEMCTL_BIN disable $i
                 if [ "$START_STOP_SERVICES" = "1" ]; then