systemd/debian/systemd.postinst
Michael Biebl d7e5781795 Use a file trigger to automatically enable service and socket units
A lot of packages simply install systemd units but do not enable them.
Running "systemctl enable" in the maintainer scripts is not really an
option since it is not guaranteed that systemd is installed. We
therefore implement a workaround for wheezy which is supposed to go away
in jessie once we have the necessary tools support in debhelper etc.

What the proposed workaround does is:
- Install a dpkg file trigger for /lib/systemd/system which triggers a
  script named /lib/systemd/debian-enable-units every time a package
  installs a systemd unit.
- Run this script also upon initial installation of systemd and once on
  upgrades from earlier releases.

The script in particular does the following:
- Run "systemctl enable" for each service or socket it finds in
  /lib/systemd/system but does that only once, so the administrator can
  disable them if wanted.
- Record the state and installed symlinks. When a package shipping
  systemd units is uninstalled, we remove those symlinks again.
- Use a blacklist for internal services.
- If systemd is not the active init, it will only create a tag file
  and next time we boot with systemd, the script will be run early
  during boot. For that we install a service named
  debian-enable-units.service which is run in basic.target.

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=692150
2013-02-09 16:42:15 +01:00

75 lines
1.9 KiB
Bash

#! /bin/sh
set -e
_systemctl() {
if [ -e /sys/fs/cgroup/systemd ]; then
systemctl "$@"
fi
}
if [ "$1" = triggered ]; then
/lib/systemd/debian-enable-units
exit 0
fi
# Run the script after the initial installation or once on upgrades
if [ -z "$2" ] || dpkg --compare-versions "$2" lt "44-9"; then
/lib/systemd/debian-enable-units
fi
if [ -n "$2" ]; then
_systemctl daemon-reexec || true
fi
# Do a one-time migration of the local time setting
if dpkg --compare-versions "$2" lt "33-1"; then
if [ -f /etc/default/rcS ]; then
. /etc/default/rcS
fi
if [ "$UTC" = "no" ] && [ ! -e /etc/adjtime ]; then
printf "0.0 0 0.0\n0\nLOCAL" > /etc/adjtime
fi
fi
# Do a one-time migration of the TMPTIME setting
if dpkg --compare-versions "$2" lt "36-2"; then
if [ -f /etc/default/rcS ]; then
. /etc/default/rcS
fi
if [ ! -e /etc/tmpfiles.d/tmp.conf ]; then
case "$TMPTIME" in
-*|infinite|infinity)
cat > /etc/tmpfiles.d/tmp.conf <<EOF
# Automatically migrated from TMPTIME in /etc/default/rcS
# Clear /var/tmp as in /usr/lib/tmpfiles.d/tmp.conf, but avoid clearing /tmp
d /var/tmp 1777 root root 30d
EOF
;;
esac
fi
fi
# Create /run/initctl → /dev/initctl compat symlink on upgrades
if [ -e /sys/fs/cgroup/systemd ]; then
_systemctl restart systemd-initctl.socket || true
fi
if dpkg --compare-versions "$2" lt "40-1"; then
# /lib/init/rw has been replaced by /run, so try to remove it on upgrades
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=643699
_systemctl stop lib-init-rw.automount lib-init-rw.mount || true
if [ -d /lib/init/rw ]; then
rmdir --ignore-fail-on-non-empty /lib/init/rw || true
fi
# Create /run/initctl → /dev/initctl compat symlink on upgrades
if [ -e /sys/fs/cgroup/systemd ]; then
ln -sf /dev/initctl /run/initctl
fi
fi
systemd-machine-id-setup
#DEBHELPER#