Package: sysv-rc
Version: 2.88dsf-34
Severity: wishlist

Attached you can find a simple patch to make service(8) systemd-aware.

The reload action falls back to the sysv init script just in case the
systemd service file does not (yet) support reload for a specific
service.
diff --git i/debian/service/service w/debian/service/service
index 693bc6a..aef69ac 100755
--- i/debian/service/service
+++ w/debian/service/service
@@ -11,6 +11,7 @@
 # Copyright (C) 2006 Red Hat, Inc. All rights reserved.
 # Copyright (C) 2008 Canonical Ltd.
 #   * August 2008 - Dustin Kirkland <kirkl...@canonical.com>
+# Copyright (C) 2013 Michael Stapelberg <stapelb...@debian.org>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -47,12 +48,18 @@ SERVICE=
 ACTION=
 SERVICEDIR="/etc/init.d"
 OPTIONS=
+is_systemd=
+
 
 if [ $# -eq 0 ]; then
    echo "${USAGE}" >&2
    exit 1
 fi
 
+if [ -d /run/systemd/system ]; then
+   is_systemd=1
+fi
+
 cd /
 while [ $# -gt 0 ]; do
   case "${1}" in
@@ -98,10 +105,16 @@ while [ $# -gt 0 ]; do
           exit 0
        elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
           SERVICE="${1}"
-          if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
-            env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" stop
-            env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" start
-            exit $?
+          # On systems using systemd, we just perform a normal restart:
+          # A restart with systemd is already a full restart.
+          if [ -n "$is_systemd" ]; then
+             ACTION="restart"
+          else
+             if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
+               env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" stop
+               env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" start
+               exit $?
+             fi
           fi
        elif [ -z "${SERVICE}" ]; then
          SERVICE="${1}"
@@ -131,10 +144,49 @@ then
    esac
 fi
 
-# Otherwise, use the traditional sysvinit
-if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
-   exec env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" ${ACTION} ${OPTIONS}
-else
-   echo "${SERVICE}: unrecognized service" >&2
-   exit 1
+run_via_sysvinit() {
+   # Otherwise, use the traditional sysvinit
+   if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
+      exec env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" ${ACTION} ${OPTIONS}
+   else
+      echo "${SERVICE}: unrecognized service" >&2
+      exit 1
+   fi
+}
+
+# When this machine is running systemd, standard service calls are turned into
+# systemctl calls.
+if [ -n "$is_systemd" ]
+then
+   case "${ACTION}" in
+      start|stop|restart|status)
+         exec systemctl ${ACTION} ${SERVICE}.service
+      ;;
+      reload)
+         _canreload="$(systemctl -p CanReload show ${SERVICE}.service 2>/dev/null)"
+         if [ "$_canreload" = "CanReload=no" ]; then
+            run_via_sysvinit
+         else
+            exec systemctl reload "${SERVICE}.service"
+         fi
+         ;;
+      force-stop)
+         exec systemctl --signal=KILL kill "${SERVICE}.service"
+         ;;
+      force-reload)
+         _canreload="$(systemctl -p CanReload show ${SERVICE}.service 2>/dev/null)"
+         if [ "$_canreload" = "CanReload=no" ]; then
+            exec systemctl restart "${SERVICE}.service"
+         else
+            exec systemctl reload "${SERVICE}.service"
+         fi
+         ;;
+      *)
+         # We try to run non-standard actions by running
+         # the init script directly.
+         run_via_sysvinit
+         ;;
+   esac
 fi
+
+run_via_sysvinit

Reply via email to