[1/5,v3] package/skeleton-init-openrc: add support for starting sysv scripts
diff mbox series

Message ID a240278d8a6fb32843c4bf55a531fb6d3916105d.1564920849.git.yann.morin.1998@free.fr
State New
Headers show
Series
  • [1/5,v3] package/skeleton-init-openrc: add support for starting sysv scripts
Related show

Commit Message

Yann E. MORIN Aug. 4, 2019, 12:14 p.m. UTC
From: Michał Łyszczek <michal.lyszczek@bofc.pl>

Add an OpenRC service that starts and stops sysv-init scripts. We order
that scrpt 'after local' so that it is started after all other native
openrc services.

Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
[yann.morin.1998@free.fr:
  - don't propagate the micro optimisation for running .sh scripts
  - use spaces, not TABs
  - stop services in reverse order
  - reword commit log
]
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
---
 docs/manual/adding-packages-generic.txt       |  5 +++-
 package/openrc/sysv-rcs                       | 25 +++++++++++++++++++
 package/pkg-generic.mk                        |  3 ++-
 .../skeleton/etc/runlevels/default/sysv-rcs   |  1 +
 4 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100755 package/openrc/sysv-rcs
 create mode 120000 package/skeleton-init-openrc/skeleton/etc/runlevels/default/sysv-rcs

Patch
diff mbox series

diff --git a/docs/manual/adding-packages-generic.txt b/docs/manual/adding-packages-generic.txt
index 5ac07a81b4..b402767b05 100644
--- a/docs/manual/adding-packages-generic.txt
+++ b/docs/manual/adding-packages-generic.txt
@@ -542,7 +542,10 @@  different steps of the build process.
   sysvinit, etc.), openrc or for the systemd units. These commands
   will be run only when the relevant init system is installed (i.e.
   if systemd is selected as the init system in the configuration,
-  only +LIBFOO_INSTALL_INIT_SYSTEMD+ will be run).
+  only +LIBFOO_INSTALL_INIT_SYSTEMD+ will be run). The only exception
+  is when openrc is chosen as init system and +LIBFOO_INSTALL_INIT_OPENRC+
+  has not been set, in such situation +LIBFOO_INSTALL_INIT_SYSV+ will
+  be called, since openrc supports sysv init scripts.
 
 * +LIBFOO_HELP_CMDS+ lists the actions to print the package help, which
   is included to the main +make help+ output. These commands can print
diff --git a/package/openrc/sysv-rcs b/package/openrc/sysv-rcs
new file mode 100755
index 0000000000..606a73d2b4
--- /dev/null
+++ b/package/openrc/sysv-rcs
@@ -0,0 +1,25 @@ 
+#!/sbin/openrc-run
+
+description="start or stop sysv rc[S,K] scripts"
+
+depend() {
+    after local
+}
+
+start() {
+    einfo "Starting sysv rc scripts"
+    for i in /etc/init.d/S??*; do
+        # Ignore dangling symlinks (if any).
+        [ -e "$i" ] || continue
+        $i start
+    done
+}
+
+stop() {
+    einfo "Stopping sysv rc scripts"
+    for i in $(ls -r /etc/init.d/S??*); do
+        # Ignore dangling symlinks (if any).
+        [ -e "$i" ] || continue
+        $i stop
+    done
+}
diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
index 9620dec524..1f24b52a69 100644
--- a/package/pkg-generic.mk
+++ b/package/pkg-generic.mk
@@ -338,7 +338,8 @@  $(BUILD_DIR)/%/.stamp_target_installed:
 	$(if $(BR2_INIT_SYSV)$(BR2_INIT_BUSYBOX),\
 		$($(PKG)_INSTALL_INIT_SYSV))
 	$(if $(BR2_INIT_OPENRC), \
-		$($(PKG)_INSTALL_INIT_OPENRC))
+		$(or $($(PKG)_INSTALL_INIT_OPENRC), \
+			$($(PKG)_INSTALL_INIT_SYSV)))
 	$(foreach hook,$($(PKG)_POST_INSTALL_TARGET_HOOKS),$(call $(hook))$(sep))
 	$(Q)if test -n "$($(PKG)_CONFIG_SCRIPTS)" ; then \
 		$(RM) -f $(addprefix $(TARGET_DIR)/usr/bin/,$($(PKG)_CONFIG_SCRIPTS)) ; \
diff --git a/package/skeleton-init-openrc/skeleton/etc/runlevels/default/sysv-rcs b/package/skeleton-init-openrc/skeleton/etc/runlevels/default/sysv-rcs
new file mode 120000
index 0000000000..ef5e00823c
--- /dev/null
+++ b/package/skeleton-init-openrc/skeleton/etc/runlevels/default/sysv-rcs
@@ -0,0 +1 @@ 
+/etc/init.d/sysv-rcs
\ No newline at end of file