aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Guthrie <colin@mageia.org>2011-11-03 09:33:21 +0000
committerColin Guthrie <colin@mageia.org>2011-11-03 09:33:21 +0000
commite70ce2525aeca478bf0128c988d45f25713fd5fd (patch)
tree38180bc32a51c68029aa5c780d5951eed56ad2d2
parentaf4af7aa58704add139718564d1e6df80662554b (diff)
downloadrpm-helper-e70ce2525aeca478bf0128c988d45f25713fd5fd.tar
rpm-helper-e70ce2525aeca478bf0128c988d45f25713fd5fd.tar.gz
rpm-helper-e70ce2525aeca478bf0128c988d45f25713fd5fd.tar.bz2
rpm-helper-e70ce2525aeca478bf0128c988d45f25713fd5fd.tar.xz
rpm-helper-e70ce2525aeca478bf0128c988d45f25713fd5fd.zip
Ensure we calculate the true systemd unit name.
When passing just a sysvinit name, we synthesise a systemd unit name via the amazingly cunning and subtle technique of adding '.service' on to the name. This is very effective for referring to units for most commands as even if an actual unit file of this name exists systemd might be providing the unit for this service via a different name, but just symlinking to the sysvinit name in order to prevent the sysvinit script from firing. This is done with e.g. the dm and networkmanager services. When using the symlinked name, systemctl will refuse to enable or disable the unit (see https://bugs.mageia.org/show_bug.cgi?id=3188) and this is expected behaviour. Thus we use readlink to attempt to resolve the link to a real name.
-rwxr-xr-xadd-service20
-rwxr-xr-xdel-service21
2 files changed, 40 insertions, 1 deletions
diff --git a/add-service b/add-service
index 1b5ac54..26bc04e 100755
--- a/add-service
+++ b/add-service
@@ -46,6 +46,26 @@ units_to_enable= # units enabled by msec
# catch the most common usage.
if [ -z "$units" ]; then
units="$srv.service"
+
+ # We need to normalise the systemd unit name as the native unit may not have
+ # the same filename (sans it's .service suffix) as sysvinit script.
+ # In this case, symlinks are used to mask the sysvinit file, but for enabling
+ # and disabling units we must use the official name.
+ SYSTEMUNITDIR=/lib/systemd/system
+ USERUNITDIR=/etc/systemd/system
+ RUNTIMEUNITDIR=/run/systemd/system
+
+ searchunit=
+ if [ -f "$SYSTEMUNITDIR/$units" ]; then
+ searchunit=$(/usr/bin/readlink "$SYSTEMUNITDIR/$units")
+ elif [ -f "$USERUNITDIR/$units" ]; then
+ searchunit=$(/usr/bin/readlink "$USERUNITDIR/$units")
+ elif [ -f "$RUNTIMEUNITDIR/$units" ]; then
+ searchunit=$(/usr/bin/readlink "$RUNTIMEUNITDIR/$units")
+ fi
+ if [ -n "$searchunit" ]; then
+ units=$searchunit
+ fi
fi
add_service() {
diff --git a/del-service b/del-service
index f519065..6051808 100755
--- a/del-service
+++ b/del-service
@@ -39,13 +39,32 @@ else
shift 2
fi
units="$*" # systemd units
-units_to_remove=
# If only a sysvinit service is given, then deal with a systemd unit of the same
# name. Specific specs can enable specific unit names as needed but this should
# catch the most common usage.
if [ -z "$units" ]; then
units="$srv.service"
+
+ # We need to normalise the systemd unit name as the native unit may not have
+ # the same filename (sans it's .service suffix) as sysvinit script.
+ # In this case, symlinks are used to mask the sysvinit file, but for enabling
+ # and disabling units we must use the official name.
+ SYSTEMUNITDIR=/lib/systemd/system
+ USERUNITDIR=/etc/systemd/system
+ RUNTIMEUNITDIR=/run/systemd/system
+
+ searchunit=
+ if [ -f "$SYSTEMUNITDIR/$units" ]; then
+ searchunit=$(/usr/bin/readlink "$SYSTEMUNITDIR/$units")
+ elif [ -f "$USERUNITDIR/$units" ]; then
+ searchunit=$(/usr/bin/readlink "$USERUNITDIR/$units")
+ elif [ -f "$RUNTIMEUNITDIR/$units" ]; then
+ searchunit=$(/usr/bin/readlink "$RUNTIMEUNITDIR/$units")
+ fi
+ if [ -n "$searchunit" ]; then
+ units=$searchunit
+ fi
fi
if [ $num = 0 ]; then