]> err.no Git - systemd/commitdiff
Try to catch direct init script invocations and redirect to systemctl
authorMichael Biebl <biebl@debian.org>
Sun, 26 Dec 2010 11:53:08 +0000 (12:53 +0100)
committerTollef Fog Heen <tfheen@err.no>
Sun, 26 Dec 2010 11:53:08 +0000 (12:53 +0100)
Install lsb-base hook which redirects calls to SysV init scripts to
systemctl: /etc/init.d/<foo> <action> → systemctl <action> <foo.service>

debian/changelog
debian/lsb-base-logging.sh [new file with mode: 0644]

index a2cdceaa48b21f4f7b7b5017cb94fd6a92f63835..1eab11e1f15ff943faa7d5256ab487376101ed09 100644 (file)
@@ -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/<foo> <action> → systemctl <action> <foo.service>
   * Install a (auto)mount unit to mount /lib/init/rw early during boot.
 
  -- Tollef Fog Heen <tfheen@debian.org>  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 (file)
index 0000000..cad93c9
--- /dev/null
@@ -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