From c04d0f711fe5f8d9be60f6ac5793663e530bc3da Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Sun, 26 Dec 2010 12:53:08 +0100 Subject: [PATCH] Try to catch direct init script invocations and redirect to systemctl MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Install lsb-base hook which redirects calls to SysV init scripts to systemctl: /etc/init.d/ → systemctl --- debian/changelog | 2 ++ debian/lsb-base-logging.sh | 74 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 debian/lsb-base-logging.sh diff --git a/debian/changelog b/debian/changelog index a2cdceaa..1eab11e1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,8 @@ systemd (13-1) experimental; urgency=low * Revert upstream change which requires libnotify 0.7 (not yet available in Debian). * Use dh-autoreconf for updating the build system. + * Install lsb-base hook which redirects calls to SysV init scripts to + systemctl: /etc/init.d/ → systemctl * Install a (auto)mount unit to mount /lib/init/rw early during boot. -- Tollef Fog Heen Sat, 20 Nov 2010 09:28:01 +0100 diff --git a/debian/lsb-base-logging.sh b/debian/lsb-base-logging.sh new file mode 100644 index 00000000..cad93c9f --- /dev/null +++ b/debian/lsb-base-logging.sh @@ -0,0 +1,74 @@ +# -*-Shell-script-*- +# /etc/lsb-base-logging.sh + +if [ -e /sys/fs/cgroup/systemd ] ; then + + # Some init scripts use "set -e" and "set -u", we don't want that + # here + set +e + set +u + + if [ -n "$DPKG_MAINTSCRIPT_PACKAGE" ] ; then + # If we are called by a maintainer script, chances are good that a + # new or updated sysv init script was installed. Reload daemon to + # pick up any changes. + echo "Reloading systemd" + systemctl daemon-reload + fi + + # Redirect SysV init scripts when executed by the user + if [ $PPID -ne 1 ] && [ -z "$init" ] && [ -z "$_SYSTEMCTL_SKIP_REDIRECT" ] ; then + case "$0" in + /etc/init.d/*) + _use_systemctl=1 + ;; + esac + else + export _SYSTEMCTL_SKIP_REDIRECT="true" + fi +else + _use_systemctl=0 +fi + +systemctl_redirect () { + local s + local rc + local prog=${1##*/} + local command=$2 + + case "$command" in + start) + s="Starting $prog (via systemctl)" + ;; + stop) + s="Stopping $prog (via systemctl)" + ;; + reload|force-reload) + s="Reloading $prog configuration (via systemctl)" + ;; + restart) + s="Restarting $prog (via systemctl)" + ;; + esac + + service="${prog%.sh}.service" + [ "$command" = status ] || log_daemon_msg "$s" "$service" + /bin/systemctl $command "$service" + rc=$? + [ "$command" = status ] || log_end_msg $rc + + return $rc +} + +if [ "$_use_systemctl" = "1" ]; then + if [ "x$1" = xstart -o \ + "x$1" = xstop -o \ + "x$1" = xrestart -o \ + "x$1" = xreload -o \ + "x$1" = xforce-reload -o \ + "x$1" = xstatus ] ; then + + systemctl_redirect $0 $1 + exit $? + fi +fi -- 2.39.5