runit: traer stages de define-alpine

This commit is contained in:
Cat /dev/Nulo 2023-02-02 18:28:47 -03:00
parent 51b29b7d3d
commit 2e1d79886c
4 changed files with 90 additions and 0 deletions

View file

@ -53,6 +53,12 @@ export class Runit {
await this.getScript("05-misc.sh") 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 // https://wiki.gentoo.org/wiki/Runit#Reboot_and_shutdown
await alpine.sudoWriteExecutable( await alpine.sudoWriteExecutable(
"/usr/local/sbin/rpoweroff", "/usr/local/sbin/rpoweroff",

22
runit/scripts/1 Normal file
View file

@ -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..."

19
runit/scripts/2 Normal file
View file

@ -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: ................................'

43
runit/scripts/3 Normal file
View file

@ -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