From 2e1d79886c88a346dadccfb5ccad5c5d43ef02b8 Mon Sep 17 00:00:00 2001 From: Nulo Date: Thu, 2 Feb 2023 18:28:47 -0300 Subject: [PATCH] runit: traer stages de define-alpine --- runit/index.ts | 6 ++++++ runit/scripts/1 | 22 ++++++++++++++++++++++ runit/scripts/2 | 19 +++++++++++++++++++ runit/scripts/3 | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 runit/scripts/1 create mode 100644 runit/scripts/2 create mode 100644 runit/scripts/3 diff --git a/runit/index.ts b/runit/index.ts index ed4cc75..f5d1e96 100644 --- a/runit/index.ts +++ b/runit/index.ts @@ -53,6 +53,12 @@ export class Runit { await this.getScript("05-misc.sh") ); + for (let stage = 1; stage <= 3; stage++) + await alpine.writeExecutable( + "/etc/runit/" + stage, + await this.getScript("" + stage) + ); + // https://wiki.gentoo.org/wiki/Runit#Reboot_and_shutdown await alpine.sudoWriteExecutable( "/usr/local/sbin/rpoweroff", diff --git a/runit/scripts/1 b/runit/scripts/1 new file mode 100644 index 0000000..61bfb8b --- /dev/null +++ b/runit/scripts/1 @@ -0,0 +1,22 @@ +#!/bin/sh + +PATH=/bin:/usr/bin:/usr/sbin:/sbin + +. /etc/runit/functions + +msg "Welcome to Nulo!" + +[ -r /etc/rc.conf ] && . /etc/rc.conf + +# Start core services: one-time system tasks. +detect_virt +for f in /etc/runit/core-services/*.sh; do + [ -r $f ] && . $f +done + +# create files for controlling runit +mkdir -p /run/runit +install -m000 /dev/null /run/runit/stopit +install -m000 /dev/null /run/runit/reboot + +msg "Initialization complete, running stage 2..." diff --git a/runit/scripts/2 b/runit/scripts/2 new file mode 100644 index 0000000..305ed35 --- /dev/null +++ b/runit/scripts/2 @@ -0,0 +1,19 @@ +#!/bin/sh +PATH=/bin:/usr/bin:/usr/sbin:/sbin + +runlevel=default +for arg in $(cat /proc/cmdline); do + if [ -d /etc/runit/runsvdir/"$arg" ]; then + echo "Runlevel detected: '$arg' (via kernel cmdline)" + runlevel="$arg" + fi +done + +[ -x /etc/rc.local ] && /etc/rc.local + +runsvchdir "${runlevel}" +mkdir -p /run/runit/runsvdir +ln -s /etc/runit/runsvdir/current /run/runit/runsvdir/current + +exec env - PATH=$PATH \ + runsvdir -P /run/runit/runsvdir/current 'log: ................................' diff --git a/runit/scripts/3 b/runit/scripts/3 new file mode 100644 index 0000000..845c4d1 --- /dev/null +++ b/runit/scripts/3 @@ -0,0 +1,43 @@ +#!/bin/sh +PATH=/bin:/usr/bin:/usr/sbin:/sbin + +. /etc/runit/functions +detect_virt +[ -r /etc/rc.conf ] && . /etc/rc.conf + +echo +msg "Waiting for services to stop..." +sv force-stop /etc/service/* +sv exit /etc/service/* + +[ -x /etc/rc.shutdown ] && /etc/rc.shutdown + +if [ -z "$VIRTUALIZATION" -a -n "$HARDWARECLOCK" ]; then + hwclock --systohc ${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z)} +fi + +halt -w # for wtmp + +if [ -z "$VIRTUALIZATION" ]; then + msg "Stopping udev..." + udevadm control --exit +fi + +if [ -z "$VIRTUALIZATION" ]; then + msg "Unmounting filesystems, disabling swap..." + swapoff -a + umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs +fi + +sync + +if [ -z "$VIRTUALIZATION" ]; then + deactivate_vgs + deactivate_crypt + if [ -e /run/runit/reboot ] && command -v kexec >/dev/null; then + msg "Triggering kexec..." + kexec -e 2>/dev/null + # not reached when kexec was successful. + fi +fi +