Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.

Commit 69d6b8a

Browse files
committed
initial commit
0 parents  commit 69d6b8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1302
-0
lines changed

1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
# vim: set ts=4 sw=4 et:
3+
4+
PATH=/usr/bin:/usr/sbin
5+
6+
. /etc/runit/functions
7+
8+
msg "Welcome to Cromnix!"
9+
10+
[ -r /etc/runit/rc.conf ] && . /etc/runit/rc.conf
11+
12+
# Start core services: one-time system tasks.
13+
detect_virt
14+
for f in /etc/runit/core-services/*.sh; do
15+
[ -r $f ] && . $f
16+
done
17+
18+
dmesg >/var/log/dmesg.log
19+
if [ $(sysctl -n kernel.dmesg_restrict 2>/dev/null) -eq 1 ]; then
20+
chmod 0600 /var/log/dmesg.log
21+
else
22+
chmod 0644 /var/log/dmesg.log
23+
fi
24+
25+
mkdir -p /run/runit
26+
install -m100 /dev/null /run/runit/stopit
27+
28+
msg "Initialization complete, running stage 2..."

2

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
# vim: set ts=4 sw=4 et:
3+
4+
PATH=/usr/bin:/usr/sbin
5+
6+
runlevel=default
7+
for arg in $(cat /proc/cmdline); do
8+
if [ -d /etc/runit/runsvdir/"$arg" ]; then
9+
echo "Runlevel detected: '$arg' (via kernel cmdline)"
10+
runlevel="$arg"
11+
fi
12+
done
13+
14+
[ -x /etc/runit/rc.local ] && /etc/runit/rc.local
15+
16+
runsvchdir "${runlevel}"
17+
mkdir -p /run/runit/runsvdir
18+
ln -s /etc/runit/runsvdir/current /run/runit/runsvdir/current
19+
20+
exec env - PATH=$PATH \
21+
runsvdir -P /run/runit/runsvdir/current 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'

3

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
# vim: set ts=4 sw=4 et:
3+
4+
PATH=/usr/bin:/usr/sbin
5+
6+
. /etc/runit/functions
7+
detect_virt
8+
[ -r /etc/runit/rc.conf ] && . /etc/runit/rc.conf
9+
10+
if [ -e /run/runit/reboot ]; then
11+
chmod 100 /run/runit/reboot
12+
fi
13+
14+
echo
15+
msg "Waiting for services to stop..."
16+
sv force-stop /var/service/*
17+
sv exit /var/service/*
18+
19+
[ -x /etc/runit/rc.shutdown ] && /etc/runit/rc.shutdown
20+
21+
msg "Saving random seed..."
22+
( 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 )
23+
24+
if [ -z "$VIRTUALIZATION" -a -n "$HARDWARECLOCK" ]; then
25+
hwclock --systohc ${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z)}
26+
fi
27+
28+
halt -w # for utmp
29+
30+
if [ -z "$VIRTUALIZATION" ]; then
31+
msg "Stopping udev..."
32+
udevadm control --exit
33+
fi
34+
35+
msg "Sending TERM signal to processes..."
36+
pkill --inverse -s0,1 -TERM
37+
sleep 1
38+
msg "Sending KILL signal to processes..."
39+
pkill --inverse -s0,1 -KILL
40+
41+
if [ -z "$VIRTUALIZATION" ]; then
42+
msg "Unmounting filesystems, disabling swap..."
43+
swapoff -a
44+
umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
45+
msg "Remounting rootfs read-only..."
46+
mount -o remount,ro /
47+
fi
48+
49+
sync
50+
51+
if [ -z "$VIRTUALIZATION" ]; then
52+
deactivate_vgs
53+
deactivate_crypt
54+
if [ -e /run/runit/reboot ] && command -v kexec >/dev/null; then
55+
msg "Triggering kexec..."
56+
kexec -e 2>/dev/null
57+
# not reached when kexec was successful.
58+
fi
59+
fi

Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
PREFIX ?= /usr
2+
SCRIPTS= 1 2 3 ctrlaltdel
3+
4+
all:
5+
$(CC) $(CFLAGS) halt.c -o halt $(LDFLAGS)
6+
$(CC) $(CFLAGS) pause.c -o pause $(LDFLAGS)
7+
8+
install:
9+
install -d ${DESTDIR}${PREFIX}/bin
10+
install -m755 halt ${DESTDIR}${PREFIX}/bin/halt-runit
11+
install -m755 pause ${DESTDIR}${PREFIX}/bin/pause-runit
12+
install -m755 shutdown ${DESTDIR}${PREFIX}/bin/shutdown-runit
13+
install -m755 modules-load ${DESTDIR}${PREFIX}/bin/modules-load
14+
install -m755 zzz ${DESTDIR}${PREFIX}/bin/zzz-runit
15+
ln -sf halt-runit ${DESTDIR}${PREFIX}/bin/poweroff-runit
16+
ln -sf halt-runit ${DESTDIR}${PREFIX}/bin/reboot-runit
17+
install -d ${DESTDIR}${PREFIX}/share/man/man1
18+
install -m644 pause.1 ${DESTDIR}${PREFIX}/share/man/man1
19+
install -d ${DESTDIR}${PREFIX}/share/man/man8
20+
install -m644 zzz.8 ${DESTDIR}${PREFIX}/share/man/man8/zzz-runit.8
21+
install -m644 shutdown.8 ${DESTDIR}${PREFIX}/share/man/man8/shutdown-runit.8
22+
install -m644 halt.8 ${DESTDIR}${PREFIX}/share/man/man8/halt-runit.8
23+
install -m644 modules-load.8 ${DESTDIR}${PREFIX}/share/man/man8
24+
ln -sf halt-runit.8 ${DESTDIR}${PREFIX}/share/man/man8/poweroff-runit.8
25+
ln -sf halt-runit.8 ${DESTDIR}${PREFIX}/share/man/man8/reboot-runit.8
26+
install -d ${DESTDIR}/etc/sv
27+
install -d ${DESTDIR}/etc/runit/runsvdir
28+
install -d ${DESTDIR}/etc/runit/core-services
29+
install -m644 core-services/*.sh ${DESTDIR}/etc/runit/core-services
30+
install -m755 ${SCRIPTS} ${DESTDIR}/etc/runit
31+
install -m644 functions $(DESTDIR)/etc/runit
32+
install -m644 crypt.awk ${DESTDIR}/etc/runit
33+
install -m644 rc.conf ${DESTDIR}/etc/runit
34+
install -m755 rc.local ${DESTDIR}/etc/runit
35+
install -m755 rc.shutdown ${DESTDIR}/etc/runit
36+
ln -sf /run/runit/reboot ${DESTDIR}/etc/runit/
37+
ln -sf /run/runit/stopit ${DESTDIR}/etc/runit/
38+
cp -aP runsvdir/* ${DESTDIR}/etc/runit/runsvdir/
39+
cp -aP services/* ${DESTDIR}/etc/sv/
40+
41+
clean:
42+
-rm -f halt pause
43+
44+
.PHONY: all install clean

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Runit init scripts for Cromnix
2+
3+
This repository contains the runit init scripts for the Cromnix Linux
4+
distribution.
5+
6+
This work is based on Void Linux's
7+
[runit-void](https://github.com/voidlinux/void-runit). Patches to Void
8+
Linux's repo will also be applied here.
9+
10+
## Dependencies
11+
12+
- A POSIX shell
13+
- A POSIX awk
14+
- procps-ng (needs pkill -s0,1)
15+
- runit
16+
17+
### How to use it
18+
19+
To see enabled services for "current" runlevel:
20+
21+
$ ls -l /var/service
22+
23+
To see available runlevels (default and single, which just runs sulogin):
24+
25+
$ ls -l /etc/runit/runsvdir
26+
27+
To enable and start a service into the "current" runlevel:
28+
29+
# ln -s /etc/sv/<service> /var/service
30+
31+
To disable and remove a service:
32+
33+
# rm -f /var/service/<service>
34+
35+
To view status of all services for "current" runlevel:
36+
37+
# sv status /var/service/*
38+
39+
Feel free to send patches and contribute with improvements!
40+
41+
## Copyright
42+
43+
runit-cromnix is in the public domain.
44+
45+
To the extent possible under law, the creator of this work has waived
46+
all copyright and related or neighboring rights to this work.
47+
48+
http://creativecommons.org/publicdomain/zero/1.0/

core-services/00-pseudofs.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# vim: set ts=4 sw=4 et:
2+
3+
msg "Mounting pseudo-filesystems..."
4+
mountpoint -q /proc || mount -o nosuid,noexec,nodev -t proc proc /proc
5+
mountpoint -q /sys || mount -o nosuid,noexec,nodev -t sysfs sys /sys
6+
mountpoint -q /run || mount -o mode=0755,nosuid,nodev -t tmpfs run /run
7+
mountpoint -q /dev || mount -o mode=0755,nosuid -t devtmpfs dev /dev
8+
mkdir -p -m0755 /run/runit /run/lvm /run/user /run/lock /run/log /dev/pts /dev/shm
9+
mountpoint -q /dev/pts || mount -o mode=0620,gid=5,nosuid,noexec -n -t devpts devpts /dev/pts
10+
mountpoint -q /dev/shm || mount -o mode=1777,nosuid,nodev -n -t tmpfs shm /dev/shm
11+
12+
if [ -z "$VIRTUALIZATION" ]; then
13+
mountpoint -q /sys/fs/cgroup || mount -o mode=0755 -t tmpfs cgroup /sys/fs/cgroup
14+
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
15+
fi

core-services/01-static-devnodes.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Some kernel modules must be loaded before starting udev(7).
2+
# Load them by looking at the output of `kmod static-nodes`.
3+
4+
for f in $(kmod static-nodes 2>/dev/null|awk '/Module/ {print $2}'); do
5+
modprobe -q $f 2>/dev/null
6+
done

core-services/02-kmods.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# vim: set ts=4 sw=4 et:
2+
3+
[ -n "$VIRTUALIZATION" ] && return 0
4+
# Do not try to load modules if kernel does not support them.
5+
[ ! -e /proc/modules ] && return 0
6+
7+
msg "Loading kernel modules..."
8+
modules-load -v | tr '\n' ' ' | sed 's:insmod [^ ]*/::g; s:\.ko\(\.gz\)\? ::g'
9+
echo

core-services/02-udev.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# vim: set ts=4 sw=4 et:
2+
3+
[ -n "$VIRTUALIZATION" ] && return 0
4+
5+
if [ -x /usr/lib/systemd/systemd-udevd ]; then
6+
_udevd=/usr/lib/systemd/systemd-udevd
7+
elif [ -x /sbin/udevd -o -x /bin/udevd ]; then
8+
_udevd=udevd
9+
else
10+
msg_warn "cannot find udevd!"
11+
fi
12+
13+
if [ -n "${_udevd}" ]; then
14+
msg "Starting udev and waiting for devices to settle..."
15+
${_udevd} --daemon
16+
udevadm trigger --action=add --type=subsystems
17+
udevadm trigger --action=add --type=devices
18+
udevadm settle
19+
fi

core-services/03-console-setup.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# vim: set ts=4 sw=4 et:
2+
3+
[ -n "$VIRTUALIZATION" ] && return 0
4+
5+
TTYS=${TTYS:-12}
6+
if [ -n "$FONT" ]; then
7+
msg "Setting up TTYs font to '${FONT}'..."
8+
9+
_index=0
10+
while [ ${_index} -le $TTYS ]; do
11+
setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} \
12+
$FONT -C "/dev/tty${_index}"
13+
_index=$((_index + 1))
14+
done
15+
fi
16+
17+
if [ -n "$KEYMAP" ]; then
18+
msg "Setting up keymap to '${KEYMAP}'..."
19+
loadkeys -q -u ${KEYMAP}
20+
fi
21+
22+
if [ -n "$HARDWARECLOCK" ]; then
23+
msg "Setting up RTC to '${HARDWARECLOCK}'..."
24+
TZ=$TIMEZONE hwclock --systz \
25+
${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z) --noadjfile} || emergency_shell
26+
fi

0 commit comments

Comments
 (0)