From 4003173f5ad8362570de1c34b2f77e3c6252f700 Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Sun, 29 Apr 2012 22:26:21 +0000 Subject: Fix handling of masked and symlinked unit names --- add-service | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'add-service') diff --git a/add-service b/add-service index 7e00cce..40e3985 100755 --- a/add-service +++ b/add-service @@ -56,21 +56,21 @@ find_unit() { # and disabling units we must use the official name. searchunit= - if [ -f "$USERUNITDIR/$unit" ]; then + if [ -e "$USERUNITDIR/$unit" ]; then if [ -L "$USERUNITDIR/$unit" ]; then - searchunit=$(/usr/bin/readlink "$USERUNITDIR/$unit") + searchunit=$(/usr/bin/readlink -f "$USERUNITDIR/$unit") else searchunit="$USERUNITDIR/$unit" fi - elif [ -f "$RUNTIMEUNITDIR/$unit" ]; then + elif [ -e "$RUNTIMEUNITDIR/$unit" ]; then if [ -L "$RUNTIMEUNITDIR/$unit" ]; then - searchunit=$(/usr/bin/readlink "$RUNTIMEUNITDIR/$unit") + searchunit=$(/usr/bin/readlink -f "$RUNTIMEUNITDIR/$unit") else searchunit="$RUNTIMEUNITDIR/$unit" fi - elif [ -f "$SYSTEMUNITDIR/$unit" ]; then + elif [ -e "$SYSTEMUNITDIR/$unit" ]; then if [ -L "$SYSTEMUNITDIR/$unit" ]; then - searchunit=$(/usr/bin/readlink "$SYSTEMUNITDIR/$unit") + searchunit=$(/usr/bin/readlink -f "$SYSTEMUNITDIR/$unit") else searchunit="$SYSTEMUNITDIR/$unit" fi @@ -174,7 +174,7 @@ check_sysvinit_service() { } if [ $num = 1 ]; then # First install mode - add_service + [ "null" != "$units" ] && add_service else # Upgrade mode. reloaded=no @@ -187,6 +187,7 @@ else if [ ! -f "${systemd_migration_dir}/$srv" ]; then full_path_units= for unit in $units; do + [ "null" = "$unit" ] && continue # We need a full path for the symlink. Also it's possible # that $unit contains "foo.service" where foo is actually # a sysvinit script and thus we'll not have anything native. @@ -253,6 +254,10 @@ else # If that is the case, we should still consider it "migrated" # even when we do not enable anything. touch "${systemd_migration_dir}/$srv" + elif [ "null" = "$units" ]; then + # New package masks the unit be we still consider this a migration + echo 1>&2 "Migrating sysvinit service '$srv': Masked under systemd." + touch "${systemd_migration_dir}/$srv" fi fi fi @@ -274,7 +279,7 @@ else done fi else - /bin/systemctl --quiet try-restart $unit + [ "null" != "$unit" ] && /bin/systemctl --quiet try-restart $unit fi done elif [ -f /etc/rc.d/init.d/$srv ]; then -- cgit v1.2.1