added sysvinit service support
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Tue, 10 May 2022 02:39:45 +0000 (12:39 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Tue, 10 May 2022 02:39:45 +0000 (12:39 +1000)
Makefile
debian/changelog
debian/control
debian/postinst [new file with mode: 0755]
subhosts.conf [new file with mode: 0644]
subhosts.sh [new file with mode: 0755]

index fed3139a3c7b0507aec9e86667c7a0459fea3261..b12ee7038b1dc179de338f9ac918ff2acaaf6cc4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,15 @@
-SBINDIR = $(DESTDIR)/usr/sbin
-#ETCDIR = $(DESTDIR)/etc/overlay
-#MAN1DIR = $(DESTDIR)/usr/share/man/man1
+ETCDIR = $(DESTDIR)/etc
+INITDIR = $(DESTDIR)/etc/init.d
 MAN8DIR = $(DESTDIR)/usr/share/man/man8
+SBINDIR = $(DESTDIR)/usr/sbin
 VARLIBDIR = $(DESTDIR)/var/lib/overlay-boot
 
-#SBINCFILES =
-#SBINFILES = overlay-boot overlay-go overlay-stop
-# The SBINFILES are installed via links; see debian/overlay-boot.links
-#ETCFILES =
-#MAN1FILES = 
 MAN8FILES = overlay-boot.8 overlay-go.8 overlay-stop.8 overlay-diskfile.8
-#HTMLDOC = $(MAN8FILES:%=%.html)
 VARLIBFILES = overlay-boot overlay-go overlay-stop functions reaper
 VARLIBFILES += overlay-init overlay-postmount overlay-premount
 VARLIBFILES += overlay-diskfile
+INITFILES = subhosts
+ETCFILES = subhosts.conf
 
 # The default is to build asm/reaper
 REAPER = src/reaper
@@ -27,6 +23,14 @@ $(REAPER):
 reaper: $(REAPER)
        mv $< $@
 
+# Specific rule: the sysvinit init file
+$(INITDIR)/subhosts: subhosts.sh | $(INITDIR)/
+       cp $< $@
+
+# Specific rule: the sysvinit init configuration file
+$(ETCDIR)/subhosts.conf: subhosts.conf | $(ETCDIR)/
+       cp $< $@
+
 # Generic rule: any dependee directory needs to be created
 %/:
        mkdir -p $@
@@ -53,11 +57,10 @@ clean:
 .INTERMEDIATE: reaper $(MAN8FILES)
 
 # Make target: enumerates that which should be installed
-#INSTALLTARGETS = $(addprefix $(SBINDIR)/,$(SBINFILES))
-#INSTALLTARGETS += $(addprefix $(ETCDIR)/,$(ETCFILES))
-#INSTALLTARGETS += $(addprefix $(MAN1DIR)/,$(MAN1FILES))
 INSTALLTARGETS += $(addprefix $(MAN8DIR)/,$(MAN8FILES))
 INSTALLTARGETS += $(addprefix $(VARLIBDIR)/,$(VARLIBFILES))
+INSTALLTARGETS += $(addprefix $(INITDIR)/,$(INITFILES))
+
 install: $(INSTALLTARGETS)
 
 # Make target: make a .deb file in ../
index 7250ff5cfacdc7fed2e577dbebc1a25ae89f5967..68b416d08fb776e15cef2f3e5da0d03c7d8a12bf 100644 (file)
@@ -1,3 +1,8 @@
+overlay-boot (0.1.6) unstable; urgency=medium
+
+  * added sysvinit service support
+
+ -- Ralph Ronnquist <ralph.ronnquist@gmail.com>  Tue, 10 May 2022 12:38:32 +1000
 overlay-boot (0.1.5) unstable; urgency=medium
 
   * with optional cpuset accounting
index ae3ce67301e4655813b744a1eeaaf808087996b7..98f5ba8a5112c439298f2863370d04c3be62fe8f 100644 (file)
@@ -12,7 +12,7 @@ Vcs-Git: https://borta.rrq.id.au/git?p=ralph/overlay-boot.git
 Package: overlay-boot
 Architecture: any
 Depends: coreutils (>=  8.32-4+b1), util-linux (>= 2.36.1-8+devuan2),
- mount, iproute2, ifupdown, dash
+ mount, iproute2, ifupdown, dash, procps
 Description: Admin scripts for running overlay subhosts
  Overlay subhosting uses unshare and chroot for running services within
  independent overlay filesystems, with a common kernel but independent
diff --git a/debian/postinst b/debian/postinst
new file mode 100755 (executable)
index 0000000..cedfe50
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+case "$1" in
+    configure)
+       update-rc.d subhosts defaults || true
+       ;;
+    *)
+       :
+       ;;
+esac
diff --git a/subhosts.conf b/subhosts.conf
new file mode 100644 (file)
index 0000000..2eac9ad
--- /dev/null
@@ -0,0 +1,5 @@
+# This file is used by subhosts boot facility to start overlay-boot(8)
+# subhosts upon system boot. Lines with '#' and blank lines are
+# ignored. Other lines should be an enumeration of subhosts to start
+# by means of the full pathnames for their overlay-boot configuration
+# files.
diff --git a/subhosts.sh b/subhosts.sh
new file mode 100755 (executable)
index 0000000..daff12e
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/env /lib/init/init-d-script
+### BEGIN INIT INFO
+# Provides:          subhosts
+# Required-Start:    $syslog $time $remote_fs
+# Required-Stop:     $syslog $time $remote_fs
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Start subhosts
+# Description:       Init script to start subhosts as per /etc/subhosts.conf
+### END INIT INFO
+
+# Note that this facility only acts on start/stop/status, and it does
+# not have any running daemon of its own. The started subhosts will
+# "run" separately.
+
+DAEMON=none
+NAME=subhosts
+
+do_status_override() {
+    pgrep -a overlay-boot | awk '{print $4}'
+}
+
+do_start_override() {
+    if [ -r /etc/subhosts.conf ] ; then
+       for SUB in $(grep -v '#' /etc/subhosts.conf) ; do
+           echo "overlay-boot $SUB" >&2
+           overlay-boot $SUB | logger -p boot.info -s
+       done
+    fi
+}
+
+do_stop_override() {
+    for SUB in $(do_status_override) ; do
+       echo "overlay-stop $SUB" >&2
+       overlay-stop $SUB | logger -p boot.info -s
+    done
+}