From fc2d92bba7b72ad0a34e5796f34d12d978370d23 Mon Sep 17 00:00:00 2001 From: Stefan Wold Date: Thu, 12 Jul 2012 23:05:41 +0200 Subject: [PATCH] systemd: Beautified the plugin code that discover new services and stopping old ones --- system/systemd/plugin.d/systemd.plugin | 40 +++++++------------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/system/systemd/plugin.d/systemd.plugin b/system/systemd/plugin.d/systemd.plugin index 1e75ac049..ceeda296e 100644 --- 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