systemd.eclass: add systemd_reenable function
authorMike Gilbert <floppym@gentoo.org>
Fri, 25 Aug 2017 18:54:41 +0000 (14:54 -0400)
committerMike Gilbert <floppym@gentoo.org>
Sun, 3 Sep 2017 01:14:43 +0000 (21:14 -0400)
eclass/systemd.eclass

index 4b7f5c4cb5fe7dcff7e84b8cd6d8a8f1d0a51598..63ff5609589d31992688cb3e95f62ee4e66266d1 100644 (file)
@@ -418,3 +418,24 @@ systemd_tmpfiles_create() {
        type systemd-tmpfiles &> /dev/null || return 0
        systemd-tmpfiles --create "${@}"
 }
+
+# @FUNCTION: systemd_reenable
+# @USAGE: <unit> ...
+# @DESCRIPTION:
+# Re-enables units if they are currently enabled. This resets symlinks to the
+# defaults specified in the [Install] section.
+#
+# This function is intended to fix broken symlinks that result from moving
+# the systemd system unit directory. It should be called from pkg_postinst
+# for system units that define the 'Alias' option in their [Install] section.
+# It is not necessary to call this function to fix dependency symlinks
+# generated by the 'WantedBy' and 'RequiredBy' options.
+systemd_reenable() {
+       type systemctl &>/dev/null || return 0
+       local x
+       for x; do
+               if systemctl --quiet --root="${ROOT}" is-enabled "${x}"; then
+                       systemctl --root="${ROOT}" reenable "${x}"
+               fi
+       done
+}