Skip to content

Commit

Permalink
systemd: Beautified the plugin code that discover new services and st…
Browse files Browse the repository at this point in the history
…opping old ones
  • Loading branch information
Ratler committed Jul 12, 2012
1 parent ef97271 commit fc2d92b
Showing 1 changed file with 10 additions and 30 deletions.
40 changes: 10 additions & 30 deletions system/systemd/plugin.d/systemd.plugin
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit fc2d92b

Please sign in to comment.