Browse Source

contrib: New `sysv-compat` section

See contrib/sysv-compat/README for more info

Signed-off-by: Mobin "Hojjat" Aydinfar <mobin@mobintestserver.ir>
Mobin Aydinfar 8 months ago
parent
commit
cfb33453f7
2 changed files with 59 additions and 0 deletions
  1. 49 0
      contrib/sysv-compat/40-dinit
  2. 10 0
      contrib/sysv-compat/README

+ 49 - 0
contrib/sysv-compat/40-dinit

@@ -0,0 +1,49 @@
+### this is sourced at the beginning of any initscript
+### This file used for forward /etc/init.d/$sv to dinit service $sv
+
+## If this file exist, We forward any initscript which has dinit service
+[ -e /run/lsb.sysvredirectdinit ] || forcesysv=1
+
+## Dinit services directories
+[ -d /etc/dinit.d ] && etc_dinit="/etc/dinit.d"
+[ -d /lib/dinit.d ] && lib_dinit="/lib/dinit.d"
+[ -d /usr/local/lib/dinit.d ] && local_lib_dinit="/usr/local/lib/dinit.d"
+
+# Get the service basename and action, like 40-systemd
+if [ -n "${__init_d_script_name:-}" ]; then
+    service="$__init_d_script_name"
+    action="$1"
+    [ x"${2:-}" = 'x--force-sysv' ] && forcesysv=1
+elif [ "${0##*/}" = "init-d-script" ] || [ "${0##*/}" = "${1:-}" ]; then
+    service="$1"
+    action="$2"
+    [ x"${3:-}" = 'x--force-sysv' ] && forcesysv=1
+else
+    service="$0"
+    action="${1:-}"
+    [ x"${2:-}" = 'x--force-sysv' ] && forcesysv=1
+fi
+service=${service##*/}
+service="${service%.sh}"
+for dinitsrv in ${etc_dinit:-} ${lib_dinit:-} ${local_lib_dinit:-}; do
+    if [ -e "$dinitsrv"/"$service" ]; then
+        has_dinit=1
+        break
+    fi
+done
+if [ -z "${forcesysv:-}" ] && [ -n "${has_dinit:-}" ]; then # Forward
+    case "$action" in
+        start|stop|restart|reload|status)
+            dinitctl "$action" "$service" || true
+            exit 0
+        ;;
+        force-stop|force-reload|force-restart)
+            dinitctl --force "${action##*-}" "$service" || true
+            exit 0
+        ;;
+        *)
+            echo "WARNING: $action not supported by dinitctl, giving up"
+            exit 0
+        ;;
+    esac
+fi

+ 10 - 0
contrib/sysv-compat/README

@@ -0,0 +1,10 @@
+Some hacks for compatibility with sysvinit
+------------------------------------------
+
+These files designed for more smooth switching between sysvinit and dinit.
+
+Currently it has these files:
+
+- `40-dinit`: This script will forward sysv script to their equivalents if they have dinit equivalents.
+  Should be installed in directory that sourced by init-functions. For example in /lib/lsb/init-functions.d/
+  for Debian systems.