[Lunar-commits] <moonbase-core> systemd: Beautified the plugin code that discover new services and stopping old ones

Stefan Wold ratler at lunar-linux.org
Thu Jul 12 23:05:41 CEST 2012


commit fc2d92bba7b72ad0a34e5796f34d12d978370d23
Author: Stefan Wold <ratler at lunar-linux.org>
Date: Thu, 12 Jul 2012 14:05:41 -0700
URL: https://github.com/lunar-linux/moonbase-core/commit/fc2d92bba7b72ad0a34e5796f34d12d978370d23

systemd: Beautified the plugin code that discover new services and stopping old ones
---
  system/systemd/plugin.d/systemd.plugin                       +10/-30   
  1 files changed, 10 insertions (+), 30 deletions (-)

--- a/system/systemd/plugin.d/systemd.plugin
+++ b/system/systemd/plugin.d/systemd.plugin
@@ -13,7 +13,7 @@
 
 plugin_systemd_configure()
 {
-  local SERVICES SERVICE SYSTEMD_SERVICES SYSTEMD_SERVICE SYSTEMD_TEMP FOUND
+  local SERVICES SERVICE SYSTEMD_SERVICES
   debug_msg "plugin_systemd_configure ($@)"
   if [ -d $SCRIPT_DIRECTORY/systemd.d ]; then
     cd $SCRIPT_DIRECTORY/systemd.d
@@ -24,22 +24,9 @@ plugin_systemd_configure()
     for SERVICE in $SERVICES; do
       # don't ask for '@' services - these should always be installed but
       # never linked directly. Also ask for new or renamed services.
-      if echo $SERVICE | grep -q @ ; then
+      if echo $SERVICE | grep -q @ || echo $SYSTEMD_SERVICES | egrep -q "(^| )$SERVICE( |$)"; then
         continue
       fi
-
-      # Keep processing new or renamed services. This is a bit of a hack
-      # but the previous solution using grep was not possible even with
-      # word boundary flag due to possible chars in a servce like '-' and '.'.
-      FOUND=false
-      for SYSTEMD_SERVICE in $SYSTEMD_SERVICES; do
-        if [ "$SERVICE" == "$SYSTEMD_SERVICE" ]; then
-          FOUND=true
-          break
-        fi
-      done
-      [ "$FOUND" == "true" ] && continue
-
       message "${MESSAGE_COLOR}$SERVICE: $(grep Description= $SERVICE | cut -d= -f2-)${DEFAULT_COLOR}"
       if query "Invoke $SERVICE via systemd automatically at boot ?"  y
       then
@@ -55,22 +42,15 @@ plugin_systemd_configure()
     # Look for renamed or removed services and stop and disable them.
     # If we don't do it here it will be too late and there will be rogue
     # processes left behind after a successful install
-    for SYSTEMD_SERVICE in $SYSTEMD_SERVICES; do
-      FOUND=false
-      for SERVICE in $SERVICES; do
-        if [ "$SYSTEMD_SERVICE" == "$SERVICE" ]; then
-          FOUND=true
-          SYSTEMD_TEMP+=" $SERVICE"
-          break
-        fi
-      done
-      [ "$FOUND" == "true" ] && continue
-
-      verbose_msg "Stopping removed service ($SYSTEMD_SERVICE)"
-      systemctl stop $SYSTEMD_SERVICE &> /dev/null
-      systemctl disable $SYSTEMD_SERVICE &> /dev/null
+    for SERVICE in $SYSTEMD_SERVICES; do
+      if ! echo $SERVICES | egrep -q "(^| )$SERVICE( |$)"; then
+        verbose_msg "Stopping removed service ($SERVICE)"
+        systemctl stop $SERVICE &> /dev/null
+        systemctl disable $SERVICE &> /dev/null
+        SYSTEMD_SERVICES=$(echo $SYSTEMD_SERVICES | sed -r "s;(^| )$SERVICE( |$);\1;")
+      fi
     done
-    SYSTEMD_SERVICES=$SYSTEMD_TEMP
+
     set_module_config "SYSTEMD_SERVICES" "$SYSTEMD_SERVICES"
   fi
   return 2




More information about the Lunar-commits mailing list