16 Commits

Author SHA1 Message Date
82bf65d4fa Move remaining shutdown services to its own place 2018-03-27 19:39:43 +07:00
f8a8bc673b Separate shutdown services 2018-03-26 16:45:26 +07:00
65e0733db7 README 2018-01-12 17:23:51 +07:00
d9721360b1 clean up /tmp 2018-01-11 18:10:16 +07:00
Daniel Néri
a3bcf72edb core-services/01-static-devnodes.sh: Honour modprobe blacklists 2018-01-11 12:18:02 +07:00
f3b0b94b3b Add opentmpfiles 2018-01-11 12:11:00 +07:00
Faule Socke
d100216548 Fixed sysctl-file processing order
To avoid local administrator settings getting overwritten by vendor
settings.

Since Artix doesn't have the same issue as Void, this patch can be
applied with no problem.
2018-01-11 11:41:20 +07:00
953c999ccf Various Runit changes (#5)
* Move runit binaries to a dedicated directory

* Adjust options for cp command during install (#71)

* Add opensysusers initscript compatiblity
2018-01-07 12:23:25 -03:00
253e6b1c5e Add an option on whether to use OpenRC or runit as its service manager (#4)
* Add an option on whether to use OpenRC or runit as its service manager

* Move runlevels boot and default to stage2
2018-01-07 12:22:17 -03:00
Chris Cromer
3f8be91085 Merge pull request #2 from Megver83/master
Add OpenRC support for managing services
2017-12-08 16:42:00 -03:00
Chris Cromer
8aebbc7784 Merge pull request #1 from konimex/master
Add openrc cgroup + patches from Void
2017-12-08 16:38:02 -03:00
David P
cd027fc19e Add OpenRC support for managing services 2017-11-20 15:05:18 -03:00
Olivier Mauras
207a4e6ebc core-services/00-pseudofs.sh: Add securityfs mountpoint - Needed for LSM support 2017-10-21 08:45:36 +07:00
Alain Kalker
3fd1449a1f Fix another always succeeding test 2017-10-21 08:44:47 +07:00
Aloz1
6b361ce618 deactivate_crypt should not try to close encrypted volumes that are still mounted during shutdown
* deactivate_crypt should not try to close encrypted volumes that are still mounted during shutdown.

When shutting down or rebooting a system with full disk encryption (as per https://wiki.voidlinux.eu/install_LVM_LUKS and https://wiki.voidlinux.eu/install_LVM_LUKS_on_UEFI_GPT), deactivate_crypt will irrespectively try and close all encrypted partitions, including '/'. On some systems, (including my own) this causes lockups on shutdown or reboot.

This commit ensures that only encrypted volumes with nothing mounted are closed (which should only be '/' at that point in shutdown).

* Reduced if statement to a one liner
2017-10-21 08:43:23 +07:00
c327918eb2 Add openrc cgroup 2017-08-28 00:15:04 +07:00
21 changed files with 111 additions and 72 deletions

18
1
View File

@@ -5,15 +5,21 @@ PATH=/usr/bin:/usr/sbin
. /etc/runit/functions
msg "Welcome to Artix Linux!"
[ -r /etc/runit/rc.conf ] && . /etc/runit/rc.conf
# Start core services: one-time system tasks.
detect_virt
for f in /etc/runit/core-services/*.sh; do
msg "Welcome to Artix Linux!"
if [ -x /usr/bin/openrc ] && [ "$SVMANAGER" = "openrc" ]; then
# Start core services: we'll use OpenRC for this.
msg "Initializing runlevel sysinit with OpenRC..."
openrc sysinit || msg_error "Failed to start sysinit runlevel"
else
# Start core services: one-time system tasks.
detect_virt
for f in /etc/runit/core-services/*.sh; do
[ -r $f ] && . $f
done
done
fi
dmesg >/var/log/dmesg.log
if [ $(sysctl -n kernel.dmesg_restrict 2>/dev/null) -eq 1 ]; then

7
2
View File

@@ -13,6 +13,13 @@ done
[ -x /etc/runit/rc.local ] && /etc/runit/rc.local
# The reason that boot is not in stage 1 is because if something hangs
# we can still listen for signals, however stage 1 does NOT accept signals
if [ -x /usr/bin/openrc ] && [ "$SVMANAGER" = "openrc" ]; then
openrc boot
openrc default
fi
runsvchdir "${runlevel}"
mkdir -p /run/runit/runsvdir
ln -s /etc/runit/runsvdir/current /run/runit/service

47
3
View File

@@ -11,49 +11,10 @@ if [ -e /run/runit/reboot ]; then
chmod 100 /run/runit/reboot
fi
echo
msg "Waiting for services to stop..."
sv force-stop /run/runit/service/*
sv exit /run/runit/service/*
[ -x /etc/runit/rc.shutdown ] && /etc/runit/rc.shutdown
msg "Saving random seed..."
( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1 )
for f in /etc/runit/shutdown-services/*.sh; do
[ -r $f ] && . $f
done
if [ -z "$VIRTUALIZATION" -a -n "$HARDWARECLOCK" ]; then
hwclock --systohc ${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z)}
fi
halt -w # for utmp
if [ -z "$VIRTUALIZATION" ]; then
msg "Stopping udev..."
udevadm control --exit
fi
msg "Sending TERM signal to processes..."
pkill --inverse -s0,1 -TERM
sleep 1
msg "Sending KILL signal to processes..."
pkill --inverse -s0,1 -KILL
if [ -z "$VIRTUALIZATION" ]; then
msg "Unmounting filesystems, disabling swap..."
swapoff -a
umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
msg "Remounting rootfs read-only..."
mount -o remount,ro /
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
msg "Stage 3 completed."

View File

@@ -6,14 +6,14 @@ all:
$(CC) $(CFLAGS) pause.c -o pause $(LDFLAGS)
install:
install -d ${DESTDIR}${PREFIX}/bin
install -m755 halt ${DESTDIR}${PREFIX}/bin/halt-runit
install -m755 pause ${DESTDIR}${PREFIX}/bin/pause-runit
install -m755 shutdown ${DESTDIR}${PREFIX}/bin/shutdown-runit
install -m755 modules-load ${DESTDIR}${PREFIX}/bin/modules-load
install -m755 zzz ${DESTDIR}${PREFIX}/bin/zzz-runit
ln -sf halt-runit ${DESTDIR}${PREFIX}/bin/poweroff-runit
ln -sf halt-runit ${DESTDIR}${PREFIX}/bin/reboot-runit
install -d ${DESTDIR}${PREFIX}/lib/runit-artix/bin
install -m755 halt ${DESTDIR}${PREFIX}/lib/runit-artix/bin/halt
install -m755 pause ${DESTDIR}${PREFIX}/lib/runit-artix/bin/pause
install -m755 shutdown ${DESTDIR}${PREFIX}/lib/runit-artix/bin/shutdown
install -m755 modules-load ${DESTDIR}${PREFIX}/lib/runit-artix/bin/modules-load
install -m755 zzz ${DESTDIR}${PREFIX}/lib/runit-artix/bin/zzz
ln -sf halt ${DESTDIR}${PREFIX}/lib/runit-artix/bin/poweroff
ln -sf halt ${DESTDIR}${PREFIX}/lib/runit-artix/bin/reboot
install -d ${DESTDIR}${PREFIX}/share/man/man1
install -m644 pause.1 ${DESTDIR}${PREFIX}/share/man/man1
install -d ${DESTDIR}${PREFIX}/share/man/man8
@@ -26,7 +26,9 @@ install:
install -d ${DESTDIR}/etc/runit/sv
install -d ${DESTDIR}/etc/runit/runsvdir
install -d ${DESTDIR}/etc/runit/core-services
install -d ${DESTDIR}/etc/runit/shutdown-services
install -m644 core-services/*.sh ${DESTDIR}/etc/runit/core-services
install -m644 shutdown-services/*.sh ${DESTDIR}/etc/runit/shutdown-services
install -m755 ${SCRIPTS} ${DESTDIR}/etc/runit
install -m644 functions $(DESTDIR)/etc/runit
install -m644 crypt.awk ${DESTDIR}/etc/runit
@@ -35,8 +37,8 @@ install:
install -m755 rc.shutdown ${DESTDIR}/etc/runit
ln -sf /run/runit/reboot ${DESTDIR}/etc/runit/
ln -sf /run/runit/stopit ${DESTDIR}/etc/runit/
cp -aP runsvdir/* ${DESTDIR}/etc/runit/runsvdir/
cp -aP services/* ${DESTDIR}/etc/runit/sv/
cp -R --no-dereference --preserve=mode,links -v runsvdir/* ${DESTDIR}/etc/runit/runsvdir/
cp -R --no-dereference --preserve=mode,links -v services/* ${DESTDIR}/etc/runit/sv/
clean:
-rm -f halt pause

View File

@@ -4,21 +4,24 @@ This repository contains the runit init scripts for the Artix Linux
distribution.
This work is based on Void Linux's
[runit-void](https://github.com/voidlinux/void-runit). Patches to Void
[void-runit](https://github.com/voidlinux/void-runit). Patches to Void
Linux's repo will also be applied here.
## Dependencies
- GNU coreutils
- A POSIX shell
- A POSIX awk
- procps-ng (needs pkill -s0,1)
- runit
- opentmpfiles
- opensysusers
### How to use it
To see enabled services for "current" runlevel:
$ ls -l /var/service
$ ls -l /run/runit/service
To see available runlevels (default and single, which just runs sulogin):
@@ -26,21 +29,21 @@ To see available runlevels (default and single, which just runs sulogin):
To enable and start a service into the "current" runlevel:
# ln -s /etc/runit/sv/<service> /var/service
# ln -s /etc/runit/sv/<service> /run/runit/service
To disable and remove a service:
# rm -f /var/service/<service>
# rm -f /run/runit/service/<service>
To view status of all services for "current" runlevel:
# sv status /var/service/*
# sv status /run/runit/service/*
Feel free to send patches and contribute with improvements!
## Copyright
runit-cromnix is in the public domain.
runit-artix is in the public domain.
To the extent possible under law, the creator of this work has waived
all copyright and related or neighboring rights to this work.

View File

@@ -8,8 +8,10 @@ mountpoint -q /dev || mount -o mode=0755,nosuid -t devtmpfs dev /dev
mkdir -p -m0755 /run/runit /run/lvm /run/user /run/lock /run/log /dev/pts /dev/shm
mountpoint -q /dev/pts || mount -o mode=0620,gid=5,nosuid,noexec -n -t devpts devpts /dev/pts
mountpoint -q /dev/shm || mount -o mode=1777,nosuid,nodev -n -t tmpfs shm /dev/shm
mountpoint -q /sys/kernel/security || mount -n -t securityfs securityfs /sys/kernel/security
if [ -z "$VIRTUALIZATION" ]; then
mountpoint -q /sys/fs/cgroup || mount -o mode=0755 -t tmpfs cgroup /sys/fs/cgroup
mountpoint -q /sys/fs/cgroup/openrc || mkdir -p /sys/fs/cgroup/openrc && mount -t cgroup -o none,name=openrc cgroup /sys/fs/cgroup/openrc
awk '$4 == 1 { system("mountpoint -q /sys/fs/cgroup/" $1 " || { mkdir -p /sys/fs/cgroup/" $1 " && mount -t cgroup -o " $1 " cgroup /sys/fs/cgroup/" $1 " ;}" ) }' /proc/cgroups
fi

View File

@@ -2,5 +2,5 @@
# Load them by looking at the output of `kmod static-nodes`.
for f in $(kmod static-nodes 2>/dev/null|awk '/Module/ {print $2}'); do
modprobe -q $f 2>/dev/null
modprobe -bq $f 2>/dev/null
done

View File

@@ -10,6 +10,11 @@ else
msg_warn "cannot find udevd!"
fi
if [ -x /usr/bin/tmpfiles ]; then
msg "Setting up tmpfiles.d entries for /dev..."
tmpfiles --prefix=/dev --create --boot
fi
if [ -n "${_udevd}" ]; then
msg "Starting udev and waiting for devices to settle..."
${_udevd} --daemon

View File

@@ -19,3 +19,13 @@ if [ -n "$TIMEZONE" ]; then
msg "Setting up timezone to '${TIMEZONE}'..."
ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
fi
msg "Setting up sysusers.d entries..."
if [ -x /usr/bin/sysusers ]; then
sysusers
fi
msg "Setting up tmpfiles.d entries..."
if [ -x /usr/bin/tmpfiles ]; then
tmpfiles --exclude-prefix=/dev --create --remove --boot
fi

View File

@@ -3,10 +3,10 @@
if [ -x /sbin/sysctl -o -x /bin/sysctl ]; then
msg "Loading sysctl(8) settings..."
for i in /run/sysctl.d/*.conf \
/etc/sysctl.d/*.conf \
/usr/local/lib/sysctl.d/*.conf \
/usr/lib/sysctl.d/*.conf \
/etc/sysctl.conf; do
/etc/sysctl.conf \
/etc/sysctl.d/*.conf; do
if [ -e "$i" ]; then
printf '* Applying %s ...\n' "$i"

View File

@@ -7,5 +7,6 @@ fi
if [ ! -e /var/log/btmp ]; then
install -m0600 -o root -g utmp /dev/null /var/log/btmp
fi
install -dm1777 /tmp/.X11-unix /tmp/.ICE-unix
rm -rf /tmp
install -dm1777 /tmp /tmp/.X11-unix /tmp/.ICE-unix
rm -f /etc/nologin /forcefsck /forcequotacheck /fastboot

View File

@@ -49,7 +49,9 @@ deactivate_vgs() {
deactivate_crypt() {
if [ -x /sbin/dmsetup -o -x /bin/dmsetup ]; then
msg "Deactivating Crypt Volumes"
dmsetup ls --target crypt --exec 'cryptsetup close'
for v in $(dmsetup ls --target crypt --exec "dmsetup info -c --noheadings -o open,name"); do
[ ${v%%:*} -eq 0 ] && cryptsetup close ${v##*:}
done
deactivate_vgs "Crypt"
fi
}

View File

@@ -1,5 +1,8 @@
# /etc/runit/rc.conf - system configuration
# Set the service manager (available options: "runit" or "openrc")
#SVMANAGER="runit"
# Set the host name.
#
# NOTE: it's preferred to declare the hostname in /etc/hostname instead:

View File

@@ -1,4 +1,4 @@
if [ -x /sbin/agetty -o /bin/agetty ]; then
if [ -x /sbin/agetty -o -x /bin/agetty ]; then
# util-linux specific settings
if [ "${tty}" = "tty1" ]; then
GETTY_ARGS="--noclear"

View File

@@ -0,0 +1,3 @@
msg "Waiting for services to stop..."
sv force-stop /run/runit/service/*
sv exit /run/runit/service/*

View File

@@ -0,0 +1,2 @@
msg "Saving random seed..."
( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1 )

View File

@@ -0,0 +1,6 @@
if [ -z "$VIRTUALIZATION" ] && [ -n "$HARDWARECLOCK" ]; then
msg "Saving hardware clock..."
hwclock --systohc ${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z)}
fi
halt -w # for utmp

View File

@@ -0,0 +1,4 @@
if [ -z "$VIRTUALIZATION" ]; then
msg "Stopping udev..."
udevadm control --exit
fi

View File

@@ -0,0 +1,5 @@
msg "Sending TERM signal to processes..."
pkill --inverse -s0,1 -TERM
sleep 1
msg "Sending KILL signal to processes..."
pkill --inverse -s0,1 -KILL

View File

@@ -0,0 +1,8 @@
if [ -z "$VIRTUALIZATION" ]; then
msg "Unmounting filesystems, disabling swap..."
swapoff -a
umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
msg "Remounting rootfs read-only..."
mount -o remount,ro /
fi
sync

View File

@@ -0,0 +1,9 @@
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