From 24b5f1e505939533fc65369fce4bae70fd2a2862 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Tue, 10 May 2022 12:39:45 +1000 Subject: [PATCH] added sysvinit service support --- Makefile | 27 +++++++++++++++------------ debian/changelog | 5 +++++ debian/control | 2 +- debian/postinst | 10 ++++++++++ subhosts.conf | 5 +++++ subhosts.sh | 37 +++++++++++++++++++++++++++++++++++++ 6 files changed, 73 insertions(+), 13 deletions(-) create mode 100755 debian/postinst create mode 100644 subhosts.conf create mode 100755 subhosts.sh diff --git a/Makefile b/Makefile index fed3139..b12ee70 100644 --- 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 ../ diff --git a/debian/changelog b/debian/changelog index 7250ff5..68b416d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,8 @@ +overlay-boot (0.1.6) unstable; urgency=medium + + * added sysvinit service support + + -- Ralph Ronnquist Tue, 10 May 2022 12:38:32 +1000 overlay-boot (0.1.5) unstable; urgency=medium * with optional cpuset accounting diff --git a/debian/control b/debian/control index ae3ce67..98f5ba8 100644 --- a/debian/control +++ b/debian/control @@ -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 index 0000000..cedfe50 --- /dev/null +++ b/debian/postinst @@ -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 index 0000000..2eac9ad --- /dev/null +++ b/subhosts.conf @@ -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 index 0000000..daff12e --- /dev/null +++ b/subhosts.sh @@ -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 +} -- 2.39.2