Compare commits
31 Commits
Author | SHA1 | Date | |
---|---|---|---|
7f0feca5b2 | |||
a47df21b08 | |||
989a323867 | |||
3139aa4609 | |||
7cad901c86 | |||
d145dce79a | |||
fd63fdca89 | |||
7d09c40c88 | |||
d3a6d855ca | |||
5c42be6143 | |||
90b1e1c301 | |||
![]() |
65768e39ea | ||
ed2bb8edd7 | |||
a44aab979b | |||
![]() |
1e6537cb5c | ||
![]() |
1250ac8e8f | ||
![]() |
9aed8d1e97 | ||
![]() |
46604a1cb9 | ||
![]() |
d8dfa64afc | ||
![]() |
0b464e9da9 | ||
![]() |
4dcecb7d45 | ||
20a1ca16bc | |||
82bf65d4fa | |||
f8a8bc673b | |||
65e0733db7 | |||
d9721360b1 | |||
![]() |
a3bcf72edb | ||
f3b0b94b3b | |||
![]() |
d100216548 | ||
953c999ccf | |||
253e6b1c5e |
39
1
39
1
@@ -1,39 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# vim: set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
PATH=/usr/bin:/usr/sbin
|
|
||||||
|
|
||||||
. /etc/runit/functions
|
|
||||||
|
|
||||||
if [ -x /usr/bin/openrc ]; then
|
|
||||||
msg "Welcome to Artix Linux!"
|
|
||||||
|
|
||||||
# Start core services: we'll use OpenRC for this.
|
|
||||||
msg "Initializing services with OpenRC..."
|
|
||||||
|
|
||||||
for runlevel in sysinit boot default; do
|
|
||||||
openrc $runlevel || msg_error "Failed to start $runlevel runlevel"
|
|
||||||
done
|
|
||||||
else
|
|
||||||
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
|
|
||||||
[ -r $f ] && . $f
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
dmesg >/var/log/dmesg.log
|
|
||||||
if [ $(sysctl -n kernel.dmesg_restrict 2>/dev/null) -eq 1 ]; then
|
|
||||||
chmod 0600 /var/log/dmesg.log
|
|
||||||
else
|
|
||||||
chmod 0644 /var/log/dmesg.log
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p /run/runit
|
|
||||||
install -m100 /dev/null /run/runit/stopit
|
|
||||||
|
|
||||||
msg "Initialization complete, running stage 2..."
|
|
27
1.in
Executable file
27
1.in
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
PATH=/usr/bin:/usr/sbin
|
||||||
|
|
||||||
|
. @RCDIR@/rc.conf
|
||||||
|
. @RCDIR@/functions
|
||||||
|
|
||||||
|
# Prints distro name and URL
|
||||||
|
print_welcome
|
||||||
|
|
||||||
|
# log all console messages
|
||||||
|
bootlogd_start
|
||||||
|
|
||||||
|
run_hook sysinit_start
|
||||||
|
|
||||||
|
for sysinit in @RCDIR@/sysinit.d/*; do
|
||||||
|
. $sysinit
|
||||||
|
done
|
||||||
|
|
||||||
|
# Remove leftover files
|
||||||
|
# remove_leftover
|
||||||
|
|
||||||
|
run_hook sysinit_end
|
||||||
|
|
||||||
|
install -m100 /dev/null @RUNDIR@/stopit
|
||||||
|
|
||||||
|
status "Initialization complete"
|
19
2 → 2.in
19
2 → 2.in
@@ -1,21 +1,22 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
# vim: set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
PATH=/usr/bin:/usr/sbin
|
PATH=/usr/bin:/usr/sbin
|
||||||
|
|
||||||
|
. @RCDIR@/functions
|
||||||
|
|
||||||
|
status "Running stage 2"
|
||||||
|
|
||||||
runlevel=default
|
runlevel=default
|
||||||
for arg in $(cat /proc/cmdline); do
|
for arg in $(cat /proc/cmdline); do
|
||||||
if [ -d /etc/runit/runsvdir/"$arg" ]; then
|
if [ -d @RUNITDIR@/runsvdir/"$arg" ]; then
|
||||||
echo "Runlevel detected: '$arg' (via kernel cmdline)"
|
status "Runlevel detected: '$arg' (via kernel cmdline)"
|
||||||
runlevel="$arg"
|
runlevel="$arg"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
[ -x /etc/runit/rc.local ] && /etc/runit/rc.local
|
|
||||||
|
|
||||||
runsvchdir "${runlevel}"
|
runsvchdir "${runlevel}"
|
||||||
mkdir -p /run/runit/runsvdir
|
# mkdir -p @RUNDIR@/runsvdir
|
||||||
ln -s /etc/runit/runsvdir/current /run/runit/service
|
ln -s @RUNSVDIR@/current @SERVICEDIR@
|
||||||
|
|
||||||
exec env - PATH=$PATH \
|
exec env - PATH=$PATH \
|
||||||
runsvdir -P /run/runit/service 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'
|
runsvdir -P @SERVICEDIR@ 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'
|
59
3
59
3
@@ -1,59 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# vim: set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
PATH=/usr/bin:/usr/sbin
|
|
||||||
|
|
||||||
. /etc/runit/functions
|
|
||||||
detect_virt
|
|
||||||
[ -r /etc/runit/rc.conf ] && . /etc/runit/rc.conf
|
|
||||||
|
|
||||||
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 )
|
|
||||||
|
|
||||||
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
|
|
35
3.in
Executable file
35
3.in
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
PATH=/usr/bin:/usr/sbin
|
||||||
|
|
||||||
|
. @RCDIR@/rc.conf
|
||||||
|
. @RCDIR@/functions
|
||||||
|
. @RCDIR@/rc.shutdown
|
||||||
|
|
||||||
|
status "Stop services ..." sv force-stop @RUNDIR@/service/*
|
||||||
|
status "Exit services ..." sv exit @RUNDIR@/service/*
|
||||||
|
|
||||||
|
if [ -e @RUNDIR@/reboot ]; then
|
||||||
|
chmod 100 @RUNDIR@/reboot
|
||||||
|
fi
|
||||||
|
|
||||||
|
# avoid staircase effect
|
||||||
|
stty onlcr
|
||||||
|
|
||||||
|
echo " "
|
||||||
|
printhl "Initiating shutdown..."
|
||||||
|
echo " "
|
||||||
|
|
||||||
|
run_hook shutdown_start
|
||||||
|
|
||||||
|
for shutdown in @RCDIR@/shutdown.d/*; do
|
||||||
|
. $shutdown
|
||||||
|
done
|
||||||
|
|
||||||
|
run_hook shutdown_poweroff
|
||||||
|
|
||||||
|
if [ -e @RUNDIR@/reboot ]; then
|
||||||
|
[[ -x $(type -P kexec) ]] && kexec -e &>/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
status "Stage 3 completed."
|
143
Makefile
143
Makefile
@@ -1,44 +1,109 @@
|
|||||||
PREFIX ?= /usr
|
SYSCONFDIR = /etc
|
||||||
SCRIPTS= 1 2 3 ctrlaltdel
|
PREFIX ?= /usr
|
||||||
|
BINDIR = $(PREFIX)/bin
|
||||||
|
MANDIR = $(PREFIX)/share/man
|
||||||
|
LIBDIR = $(PREFIX)/lib
|
||||||
|
TMPFILESDIR = $(LIBDIR)/tmpfiles.d
|
||||||
|
RUNITDIR = $(SYSCONFDIR)/runit
|
||||||
|
SVDIR = $(RUNITDIR)/sv
|
||||||
|
RUNSVDIR = $(RUNITDIR)/runsvdir
|
||||||
|
SERVICEDIR = /etc/service
|
||||||
|
RUNDIR = /run/runit
|
||||||
|
RCBINDIR = $(PREFIX)/lib/rc/bin
|
||||||
|
RCDIR = $(SYSCONFDIR)/rc
|
||||||
|
|
||||||
all:
|
TMPFILES = tmpfile.conf
|
||||||
$(CC) $(CFLAGS) halt.c -o halt $(LDFLAGS)
|
|
||||||
$(CC) $(CFLAGS) pause.c -o pause $(LDFLAGS)
|
|
||||||
|
|
||||||
install:
|
BIN = zzz pause modules-load
|
||||||
install -d ${DESTDIR}${PREFIX}/bin
|
|
||||||
install -m755 halt ${DESTDIR}${PREFIX}/bin/halt-runit
|
STAGES = 1 2 3 ctrlaltdel
|
||||||
install -m755 pause ${DESTDIR}${PREFIX}/bin/pause-runit
|
|
||||||
install -m755 shutdown ${DESTDIR}${PREFIX}/bin/shutdown-runit
|
LN = ln -sf
|
||||||
install -m755 modules-load ${DESTDIR}${PREFIX}/bin/modules-load
|
CP = cp -R --no-dereference --preserve=mode,links -v
|
||||||
install -m755 zzz ${DESTDIR}${PREFIX}/bin/zzz-runit
|
RM = rm -f
|
||||||
ln -sf halt-runit ${DESTDIR}${PREFIX}/bin/poweroff-runit
|
RMD = rm -fr --one-file-system
|
||||||
ln -sf halt-runit ${DESTDIR}${PREFIX}/bin/reboot-runit
|
M4 = m4 -P
|
||||||
install -d ${DESTDIR}${PREFIX}/share/man/man1
|
CHMODAW = chmod a-w
|
||||||
install -m644 pause.1 ${DESTDIR}${PREFIX}/share/man/man1
|
CHMODX = chmod +x
|
||||||
install -d ${DESTDIR}${PREFIX}/share/man/man8
|
|
||||||
install -m644 zzz.8 ${DESTDIR}${PREFIX}/share/man/man8/zzz-runit.8
|
HASRC = yes
|
||||||
install -m644 shutdown.8 ${DESTDIR}${PREFIX}/share/man/man8/shutdown-runit.8
|
|
||||||
install -m644 halt.8 ${DESTDIR}${PREFIX}/share/man/man8/halt-runit.8
|
EDIT = sed \
|
||||||
install -m644 modules-load.8 ${DESTDIR}${PREFIX}/share/man/man8
|
-e "s|@RUNITDIR[@]|$(RUNITDIR)|g" \
|
||||||
ln -sf halt-runit.8 ${DESTDIR}${PREFIX}/share/man/man8/poweroff-runit.8
|
-e "s|@SERVICEDIR[@]|$(SERVICEDIR)|g" \
|
||||||
ln -sf halt-runit.8 ${DESTDIR}${PREFIX}/share/man/man8/reboot-runit.8
|
-e "s|@RUNSVDIR[@]|$(RUNSVDIR)|g" \
|
||||||
install -d ${DESTDIR}/etc/runit/sv
|
-e "s|@RUNDIR[@]|$(RUNDIR)|g" \
|
||||||
install -d ${DESTDIR}/etc/runit/runsvdir
|
-e "s|@RCDIR[@]|$(RCDIR)|g"
|
||||||
install -d ${DESTDIR}/etc/runit/core-services
|
|
||||||
install -m644 core-services/*.sh ${DESTDIR}/etc/runit/core-services
|
%: %.in Makefile
|
||||||
install -m755 ${SCRIPTS} ${DESTDIR}/etc/runit
|
@echo "GEN $@"
|
||||||
install -m644 functions $(DESTDIR)/etc/runit
|
@$(RM) "$@"
|
||||||
install -m644 crypt.awk ${DESTDIR}/etc/runit
|
@$(M4) $@.in | $(EDIT) >$@
|
||||||
install -m644 rc.conf ${DESTDIR}/etc/runit
|
@$(CHMODAW) "$@"
|
||||||
install -m755 rc.local ${DESTDIR}/etc/runit
|
@$(CHMODX) "$@"
|
||||||
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/
|
all: all-runit
|
||||||
cp -aP services/* ${DESTDIR}/etc/runit/sv/
|
|
||||||
|
ifeq ($(HASRC),yes)
|
||||||
|
|
||||||
|
all: all-rc
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
all-runit: $(STAGES)
|
||||||
|
$(CC) $(CFLAGS) pause.c -o pause $(LDFLAGS)
|
||||||
|
|
||||||
|
all-rc:
|
||||||
|
make RCDIR=$(RCDIR) -C rc
|
||||||
|
|
||||||
|
install-runit:
|
||||||
|
install -d $(DESTDIR)$(RUNITDIR)
|
||||||
|
install -m755 $(STAGES) $(DESTDIR)$(RUNITDIR)
|
||||||
|
|
||||||
|
$(LN) $(RUNDIR)/reboot $(DESTDIR)$(RUNITDIR)/
|
||||||
|
$(LN) $(RUNDIR)/stopit $(DESTDIR)$(RUNITDIR)/
|
||||||
|
|
||||||
|
install -d $(DESTDIR)$(SVDIR)
|
||||||
|
$(CP) sv/* $(DESTDIR)$(SVDIR)/
|
||||||
|
|
||||||
|
install -d $(DESTDIR)$(RUNSVDIR)
|
||||||
|
$(CP) runsvdir/* $(DESTDIR)$(RUNSVDIR)/
|
||||||
|
|
||||||
|
install -d $(DESTDIR)$(BINDIR)
|
||||||
|
install -m755 $(BIN) $(DESTDIR)$(BINDIR)
|
||||||
|
|
||||||
|
install -d $(DESTDIR)$(TMPFILESDIR)
|
||||||
|
install -m755 $(TMPFILES) $(DESTDIR)$(TMPFILESDIR)/runit.conf
|
||||||
|
|
||||||
|
install -d $(DESTDIR)$(MANDIR)/man1
|
||||||
|
install -m644 pause.1 $(DESTDIR)$(MANDIR)/man1
|
||||||
|
install -d $(DESTDIR)$(MANDIR)/man8
|
||||||
|
install -m644 zzz.8 $(DESTDIR)$(MANDIR)/man8/zzz.8
|
||||||
|
install -m644 modules-load.8 $(DESTDIR)$(MANDIR)/man8
|
||||||
|
|
||||||
|
install-rc:
|
||||||
|
make install BINDIR=$(BINDIR) RCDIR=$(RCDIR) RCBINDIR=$(RCBINDIR) MANDIR=$(MANDIR) DESTDIR=$(DESTDIR) -C rc
|
||||||
|
|
||||||
|
install: install-runit
|
||||||
|
ifeq ($(HASRC),yes)
|
||||||
|
install: install-rc
|
||||||
|
endif
|
||||||
|
|
||||||
|
clean-runit:
|
||||||
|
-rm -f pause
|
||||||
|
-rm -f $(STAGES)
|
||||||
|
|
||||||
|
clean-rc:
|
||||||
|
make -C rc clean
|
||||||
|
|
||||||
|
clean: clean-runit
|
||||||
|
ifeq ($(HASRC),yes)
|
||||||
|
clean: clean-rc
|
||||||
|
endif
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f halt pause
|
|
||||||
|
|
||||||
.PHONY: all install clean
|
|
||||||
|
.PHONY: all install clean install-runit install-rc clean-runit clean-rc all-runit all-rc
|
||||||
|
15
README.md
15
README.md
@@ -4,21 +4,24 @@ This repository contains the runit init scripts for the Artix Linux
|
|||||||
distribution.
|
distribution.
|
||||||
|
|
||||||
This work is based on Void Linux's
|
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.
|
Linux's repo will also be applied here.
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
|
- GNU coreutils
|
||||||
- A POSIX shell
|
- A POSIX shell
|
||||||
- A POSIX awk
|
- A POSIX awk
|
||||||
- procps-ng (needs pkill -s0,1)
|
- procps-ng (needs pkill -s0,1)
|
||||||
- runit
|
- runit
|
||||||
|
- opentmpfiles
|
||||||
|
- opensysusers
|
||||||
|
|
||||||
### How to use it
|
### How to use it
|
||||||
|
|
||||||
To see enabled services for "current" runlevel:
|
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):
|
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:
|
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:
|
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:
|
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!
|
Feel free to send patches and contribute with improvements!
|
||||||
|
|
||||||
## Copyright
|
## 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
|
To the extent possible under law, the creator of this work has waived
|
||||||
all copyright and related or neighboring rights to this work.
|
all copyright and related or neighboring rights to this work.
|
||||||
|
@@ -1,17 +0,0 @@
|
|||||||
# vim: set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
msg "Mounting pseudo-filesystems..."
|
|
||||||
mountpoint -q /proc || mount -o nosuid,noexec,nodev -t proc proc /proc
|
|
||||||
mountpoint -q /sys || mount -o nosuid,noexec,nodev -t sysfs sys /sys
|
|
||||||
mountpoint -q /run || mount -o mode=0755,nosuid,nodev -t tmpfs run /run
|
|
||||||
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
|
|
@@ -1,6 +0,0 @@
|
|||||||
# Some kernel modules must be loaded before starting udev(7).
|
|
||||||
# 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
|
|
||||||
done
|
|
@@ -1,9 +0,0 @@
|
|||||||
# vim: set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
[ -n "$VIRTUALIZATION" ] && return 0
|
|
||||||
# Do not try to load modules if kernel does not support them.
|
|
||||||
[ ! -e /proc/modules ] && return 0
|
|
||||||
|
|
||||||
msg "Loading kernel modules..."
|
|
||||||
modules-load -v | tr '\n' ' ' | sed 's:insmod [^ ]*/::g; s:\.ko\(\.gz\)\? ::g'
|
|
||||||
echo
|
|
@@ -1,19 +0,0 @@
|
|||||||
# vim: set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
[ -n "$VIRTUALIZATION" ] && return 0
|
|
||||||
|
|
||||||
if [ -x /usr/lib/systemd/systemd-udevd ]; then
|
|
||||||
_udevd=/usr/lib/systemd/systemd-udevd
|
|
||||||
elif [ -x /sbin/udevd -o -x /bin/udevd ]; then
|
|
||||||
_udevd=udevd
|
|
||||||
else
|
|
||||||
msg_warn "cannot find udevd!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${_udevd}" ]; then
|
|
||||||
msg "Starting udev and waiting for devices to settle..."
|
|
||||||
${_udevd} --daemon
|
|
||||||
udevadm trigger --action=add --type=subsystems
|
|
||||||
udevadm trigger --action=add --type=devices
|
|
||||||
udevadm settle
|
|
||||||
fi
|
|
@@ -1,26 +0,0 @@
|
|||||||
# vim: set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
[ -n "$VIRTUALIZATION" ] && return 0
|
|
||||||
|
|
||||||
TTYS=${TTYS:-12}
|
|
||||||
if [ -n "$FONT" ]; then
|
|
||||||
msg "Setting up TTYs font to '${FONT}'..."
|
|
||||||
|
|
||||||
_index=0
|
|
||||||
while [ ${_index} -le $TTYS ]; do
|
|
||||||
setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} \
|
|
||||||
$FONT -C "/dev/tty${_index}"
|
|
||||||
_index=$((_index + 1))
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$KEYMAP" ]; then
|
|
||||||
msg "Setting up keymap to '${KEYMAP}'..."
|
|
||||||
loadkeys -q -u ${KEYMAP}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$HARDWARECLOCK" ]; then
|
|
||||||
msg "Setting up RTC to '${HARDWARECLOCK}'..."
|
|
||||||
TZ=$TIMEZONE hwclock --systz \
|
|
||||||
${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z) --noadjfile} || emergency_shell
|
|
||||||
fi
|
|
@@ -1,70 +0,0 @@
|
|||||||
# vim: set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
[ -n "$VIRTUALIZATION" ] && return 0
|
|
||||||
|
|
||||||
msg "Remounting rootfs read-only..."
|
|
||||||
mount -o remount,ro / || emergency_shell
|
|
||||||
|
|
||||||
if [ -x /sbin/dmraid -o -x /bin/dmraid ]; then
|
|
||||||
msg "Activating dmraid devices..."
|
|
||||||
dmraid -i -ay
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -x /bin/btrfs ]; then
|
|
||||||
msg "Activating btrfs devices..."
|
|
||||||
btrfs device scan || emergency_shell
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -x /sbin/vgchange -o -x /bin/vgchange ]; then
|
|
||||||
msg "Activating LVM devices..."
|
|
||||||
vgchange --sysinit -a y || emergency_shell
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -e /etc/crypttab ]; then
|
|
||||||
msg "Activating encrypted devices..."
|
|
||||||
awk -f /etc/runit/crypt.awk /etc/crypttab
|
|
||||||
|
|
||||||
if [ -x /sbin/vgchange -o -x /bin/vgchange ]; then
|
|
||||||
msg "Activating LVM devices for dm-crypt..."
|
|
||||||
vgchange --sysinit -a y || emergency_shell
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -e /etc/zfs/zpool.cache -a -x /usr/bin/zfs ]; then
|
|
||||||
msg "Activating ZFS devices..."
|
|
||||||
zpool import -c /etc/zfs/zpool.cache -N -a
|
|
||||||
|
|
||||||
msg "Mounting ZFS file systems..."
|
|
||||||
zfs mount -a
|
|
||||||
|
|
||||||
msg "Sharing ZFS file systems..."
|
|
||||||
zfs share -a
|
|
||||||
|
|
||||||
# NOTE(dh): ZFS has ZVOLs, block devices on top of storage pools.
|
|
||||||
# In theory, it would be possible to use these as devices in
|
|
||||||
# dmraid, btrfs, LVM and so on. In practice it's unlikely that
|
|
||||||
# anybody is doing that, so we aren't supporting it for now.
|
|
||||||
fi
|
|
||||||
|
|
||||||
[ -f /fastboot ] && FASTBOOT=1
|
|
||||||
[ -f /forcefsck ] && FORCEFSCK="-f"
|
|
||||||
for arg in $(cat /proc/cmdline); do
|
|
||||||
case $arg in
|
|
||||||
fastboot) FASTBOOT=1;;
|
|
||||||
forcefsck) FORCEFSCK="-f";;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -z "$FASTBOOT" ]; then
|
|
||||||
msg "Checking filesystems:"
|
|
||||||
fsck -A -T -a -t noopts=_netdev $FORCEFSCK
|
|
||||||
if [ $? -gt 1 ]; then
|
|
||||||
emergency_shell
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
msg "Mounting rootfs read-write..."
|
|
||||||
mount -o remount,rw / || emergency_shell
|
|
||||||
|
|
||||||
msg "Mounting all non-network filesystems..."
|
|
||||||
mount -a -t "nosysfs,nonfs,nonfs4,nosmbfs,nocifs" -O no_netdev || emergency_shell
|
|
@@ -1,6 +0,0 @@
|
|||||||
# vim: set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
[ -n "$VIRTUALIZATION" ] && return 0
|
|
||||||
|
|
||||||
msg "Initializing swap..."
|
|
||||||
swapon -a || emergency_shell
|
|
@@ -1,21 +0,0 @@
|
|||||||
# vim: set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
msg "Initializing random seed..."
|
|
||||||
cp /var/lib/random-seed /dev/urandom >/dev/null 2>&1 || true
|
|
||||||
( 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 )
|
|
||||||
|
|
||||||
msg "Setting up loopback interface..."
|
|
||||||
ip link set up dev lo
|
|
||||||
|
|
||||||
[ -r /etc/hostname ] && read -r HOSTNAME < /etc/hostname
|
|
||||||
if [ -n "$HOSTNAME" ]; then
|
|
||||||
msg "Setting up hostname to '${HOSTNAME}'..."
|
|
||||||
printf "%s" "$HOSTNAME" > /proc/sys/kernel/hostname
|
|
||||||
else
|
|
||||||
msg_warn "Didn't setup a hostname!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$TIMEZONE" ]; then
|
|
||||||
msg "Setting up timezone to '${TIMEZONE}'..."
|
|
||||||
ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
|
|
||||||
fi
|
|
@@ -1,16 +0,0 @@
|
|||||||
# vim: set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
if [ -e "$i" ]; then
|
|
||||||
printf '* Applying %s ...\n' "$i"
|
|
||||||
sysctl -p "$i"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
@@ -1,11 +0,0 @@
|
|||||||
# vim: set ts=4 sw=4 et:
|
|
||||||
|
|
||||||
install -m0664 -o root -g utmp /dev/null /run/utmp
|
|
||||||
if [ ! -e /var/log/wtmp ]; then
|
|
||||||
install -m0664 -o root -g utmp /dev/null /var/log/wtmp
|
|
||||||
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 -f /etc/nologin /forcefsck /forcequotacheck /fastboot
|
|
@@ -4,7 +4,7 @@ PATH=/usr/bin:/usr/sbin
|
|||||||
MSG="System is going down..."
|
MSG="System is going down..."
|
||||||
|
|
||||||
# We check for this file in stage3 to halt or reboot
|
# We check for this file in stage3 to halt or reboot
|
||||||
touch /run/runit/reboot
|
touch @RUNDIR@/reboot
|
||||||
|
|
||||||
# Proceed with shutdown process
|
# Proceed with shutdown process
|
||||||
echo "$MSG" | wall
|
echo "$MSG" | wall
|
57
functions
57
functions
@@ -1,57 +0,0 @@
|
|||||||
# *-*-shell-*-*
|
|
||||||
|
|
||||||
msg() {
|
|
||||||
# bold
|
|
||||||
printf "\033[1m=> $@\033[m\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
msg_ok() {
|
|
||||||
# bold/green
|
|
||||||
printf "\033[1m\033[32m OK\033[m\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
msg_error() {
|
|
||||||
# bold/red
|
|
||||||
printf "\033[1m\033[31mERROR: $@\033[m\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
msg_warn() {
|
|
||||||
# bold/yellow
|
|
||||||
printf "\033[1m\033[33mWARNING: $@\033[m"
|
|
||||||
}
|
|
||||||
|
|
||||||
emergency_shell() {
|
|
||||||
echo
|
|
||||||
echo "Cannot continue due to errors above, starting emergency shell."
|
|
||||||
echo "When ready type exit to continue booting."
|
|
||||||
/bin/sh -l
|
|
||||||
}
|
|
||||||
|
|
||||||
detect_virt() {
|
|
||||||
# Detect LXC containers
|
|
||||||
[ ! -e /proc/self/environ ] && return
|
|
||||||
if grep -q lxc /proc/self/environ >/dev/null; then
|
|
||||||
export VIRTUALIZATION=1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
deactivate_vgs() {
|
|
||||||
_group=${1:-All}
|
|
||||||
if [ -x /sbin/vgchange -o -x /bin/vgchange ]; then
|
|
||||||
vgs=$(vgs|wc -l)
|
|
||||||
if [ $vgs -gt 0 ]; then
|
|
||||||
msg "Deactivating $_group LVM Volume Groups..."
|
|
||||||
vgchange -an
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
deactivate_crypt() {
|
|
||||||
if [ -x /sbin/dmsetup -o -x /bin/dmsetup ]; then
|
|
||||||
msg "Deactivating Crypt Volumes"
|
|
||||||
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
|
|
||||||
}
|
|
29
rc.conf
29
rc.conf
@@ -1,29 +0,0 @@
|
|||||||
# /etc/runit/rc.conf - system configuration
|
|
||||||
|
|
||||||
# Set the host name.
|
|
||||||
#
|
|
||||||
# NOTE: it's preferred to declare the hostname in /etc/hostname instead:
|
|
||||||
# - echo myhost > /etc/hostname
|
|
||||||
#
|
|
||||||
#HOSTNAME="artix"
|
|
||||||
|
|
||||||
# Set RTC to UTC or localtime.
|
|
||||||
#HARDWARECLOCK="UTC"
|
|
||||||
|
|
||||||
# Set timezone, availables timezones at /usr/share/zoneinfo.
|
|
||||||
#TIMEZONE="Europe/Madrid"
|
|
||||||
|
|
||||||
# Keymap to load, see loadkeys(8).
|
|
||||||
#KEYMAP="us"
|
|
||||||
|
|
||||||
# Console font to load, see setfont(8).
|
|
||||||
#FONT="lat9w-16"
|
|
||||||
|
|
||||||
# Console map to load, see setfont(8).
|
|
||||||
#FONT_MAP=
|
|
||||||
|
|
||||||
# Font unimap to load, see setfont(8).
|
|
||||||
#FONT_UNIMAP=
|
|
||||||
|
|
||||||
# Amount of ttys which should be setup.
|
|
||||||
#TTYS=6
|
|
55
rc/Makefile
Normal file
55
rc/Makefile
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
RCBIN = halt shutdown
|
||||||
|
RC = rc.local rc.shutdown functions rc.conf
|
||||||
|
|
||||||
|
LN = ln -sf
|
||||||
|
RM = rm -f
|
||||||
|
M4 = m4 -P
|
||||||
|
CHMODAW = chmod a-w
|
||||||
|
CHMODX = chmod +x
|
||||||
|
|
||||||
|
EDIT = sed -e "s|@RCDIR[@]|$(RCDIR)|g"
|
||||||
|
|
||||||
|
%: %.in Makefile
|
||||||
|
@echo "GEN $@"
|
||||||
|
@$(RM) "$@"
|
||||||
|
@$(M4) $@.in | $(EDIT) >$@
|
||||||
|
@$(CHMODAW) "$@"
|
||||||
|
@$(CHMODX) "$@"
|
||||||
|
|
||||||
|
all: $(RC) shutdown
|
||||||
|
$(CC) $(CFLAGS) halt.c -o halt $(LDFLAGS)
|
||||||
|
|
||||||
|
install:
|
||||||
|
install -d $(DESTDIR)$(RCDIR)
|
||||||
|
install -d $(DESTDIR)$(RCDIR)/sysinit.d
|
||||||
|
install -d $(DESTDIR)$(RCDIR)/shutdown.d
|
||||||
|
install -m755 $(RC) $(DESTDIR)$(RCDIR)
|
||||||
|
install -m644 sysinit.d/* $(DESTDIR)$(RCDIR)/sysinit.d
|
||||||
|
install -m644 shutdown.d/* $(DESTDIR)$(RCDIR)/shutdown.d
|
||||||
|
install -m644 crypt.awk $(DESTDIR)$(RCDIR)
|
||||||
|
|
||||||
|
install -d $(DESTDIR)$(RCBINDIR)
|
||||||
|
install -m644 $(RCBIN) $(DESTDIR)$(RCBINDIR)
|
||||||
|
|
||||||
|
$(LN) halt $(DESTDIR)$(RCBINDIR)/poweroff
|
||||||
|
$(LN) halt $(DESTDIR)$(RCBINDIR)/reboot
|
||||||
|
|
||||||
|
|
||||||
|
install_sysv:
|
||||||
|
install -d $(DESTDIR)$(BINDIR)
|
||||||
|
$(LN) runit-init $(DESTDIR)$(BINDIR)/init
|
||||||
|
$(LN) $(RCBINDIR)/halt $(DESTDIR)$(BINDIR)/halt
|
||||||
|
$(LN) $(RCBINDIR)/shutdown $(DESTDIR)$(BINDIR)/shutdown
|
||||||
|
$(LN) halt $(DESTDIR)$(BINDIR)/poweroff
|
||||||
|
$(LN) halt $(DESTDIR)$(BINDIR)/reboot
|
||||||
|
install -d $(DESTDIR)$(MANDIR)/man8
|
||||||
|
install -m644 shutdown.8 $(DESTDIR)$(MANDIR)/man8/shutdown.8
|
||||||
|
install -m644 halt.8 $(DESTDIR)$(MANDIR)/man8/halt.8
|
||||||
|
$(LN) halt.8 $(DESTDIR)$(MANDIR)/man8/poweroff.8
|
||||||
|
$(LN) halt.8 $(DESTDIR)$(MANDIR)/man8/reboot.8
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-rm -f halt
|
||||||
|
-rm -f shutdown $(RC)
|
||||||
|
|
||||||
|
.PHONY: all install install_sysv clean
|
103
rc/crypt.awk
Normal file
103
rc/crypt.awk
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
/^#/ || /^$/ { next }
|
||||||
|
NF>4 { print "a valid crypttab has max 4 cols not " NF >"/dev/stderr"; next }
|
||||||
|
{
|
||||||
|
# decode the src variants
|
||||||
|
split($2, o_src, "=")
|
||||||
|
if (o_src[1] == "UUID") ("blkid -l -o device -t " $2) | getline src;
|
||||||
|
else src=o_src[1];
|
||||||
|
|
||||||
|
# no password or none is given, ask fo it
|
||||||
|
if ( NF == 2 ) {
|
||||||
|
ccmd="cryptsetup luksOpen " src " " $1;
|
||||||
|
system(ccmd);
|
||||||
|
ccmd="";
|
||||||
|
}
|
||||||
|
else if (NF == 3 ) {
|
||||||
|
dest=$1
|
||||||
|
key=$3
|
||||||
|
split($3, po, "=");
|
||||||
|
if ( po[1] == "none") ccmd="cryptsetup luksOpen " src " " dest;
|
||||||
|
else ccmd="cryptsetup luksOpen -d " key " " src" " dest;
|
||||||
|
system(ccmd);
|
||||||
|
ccmd="";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# the option field is not empty parse the options
|
||||||
|
dest=$1
|
||||||
|
key=$3
|
||||||
|
split($4, opts, ",");
|
||||||
|
commonopts="";
|
||||||
|
swapopts="";
|
||||||
|
luksopts="";
|
||||||
|
for(i in opts) {
|
||||||
|
split(opts[i], para, "=");
|
||||||
|
par=para[1];
|
||||||
|
val=para[2];
|
||||||
|
if ( par == "readonly" || par == "read-only") commonopts=commonopts "-r ";
|
||||||
|
else if ( par == "discard" ) commonopts=commonopts "--allow-discards ";
|
||||||
|
else if ( par == "tries" ) commonopts=commonopts "-T " val " ";
|
||||||
|
else if ( par == "swap" ) makeswap="y";
|
||||||
|
else if ( par == "cipher" ) swapopts=swapopts "-c " val " ";
|
||||||
|
else if ( par == "size" ) swapopts=swapopts "-s " val " ";
|
||||||
|
else if ( par == "hash" ) swapopts=swapopts "-h " val " ";
|
||||||
|
else if ( par == "offset" ) swapopts=swapopts "-o " val " ";
|
||||||
|
else if ( par == "skip" ) swapopts=swapopts "-p " val " ";
|
||||||
|
else if ( par == "verify" ) swapopts=swapopts "-y ";
|
||||||
|
#else if ( par == "noauto" )
|
||||||
|
#else if ( par == "nofail" )
|
||||||
|
#else if ( par == "plain" )
|
||||||
|
#else if ( par == "timeout" )
|
||||||
|
#else if ( par == "tmp" )
|
||||||
|
else if ( par == "luks" ) use_luks="y";
|
||||||
|
else if ( par == "keyscript" ) {use_keyscript="y"; keyscript=val;}
|
||||||
|
else if ( par == "keyslot" || par == "key-slot" ) luksopts=luksopts "-S " val " ";
|
||||||
|
else if ( par == "keyfile-size" ) luksopts=luksopts "-l " val " ";
|
||||||
|
else if ( par == "keyfile-offset" ) luksopts=luksopts "-keyfile-offset=" val " ";
|
||||||
|
else if ( par == "header" ) luksopts=luksopts "--header=" val " ";
|
||||||
|
else {
|
||||||
|
print "option: " par " not supported " >"/dev/stderr";
|
||||||
|
makeswap="";
|
||||||
|
use_luks="";
|
||||||
|
use_keyscript="";
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( makeswap == "y" && use_luks != "y" ) {
|
||||||
|
ccmd="cryptsetup " swapopts commonopts "-d " key " create " dest " " src;
|
||||||
|
ccmd_2="mkswap /dev/mapper/" dest;
|
||||||
|
makeswap="";
|
||||||
|
use_luks="";
|
||||||
|
use_keyscript="";
|
||||||
|
system(ccmd);
|
||||||
|
system(ccmd_2);
|
||||||
|
ccmd="";
|
||||||
|
ccmd_2="";
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
if ( use_luks == "y" && makeswap != "y" ){
|
||||||
|
if ( use_keyscript == "y") {
|
||||||
|
ccmd=keyscript " | cryptsetup " luksopts commonopts "luksOpen -d - " src " " dest;
|
||||||
|
use_keyscript="";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ( key == "none" ){
|
||||||
|
ccmd="cryptsetup " luksopts commonopts "luksOpen " src " " dest;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ccmd="cryptsetup " luksopts commonopts "luksOpen -d " key " " src " " dest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print "use swap OR luks as option" >"/dev/stderr";
|
||||||
|
ccmd="";
|
||||||
|
}
|
||||||
|
makeswap="";
|
||||||
|
use_luks="";
|
||||||
|
use_keyscript="";
|
||||||
|
if ( ccmd != ""){
|
||||||
|
system(ccmd);
|
||||||
|
ccmd=""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
538
rc/functions.in
Normal file
538
rc/functions.in
Normal file
@@ -0,0 +1,538 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# rc functions
|
||||||
|
#
|
||||||
|
|
||||||
|
# sanitize PATH (will be overridden later when /etc/profile is sourced but is useful for udev)
|
||||||
|
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||||
|
|
||||||
|
# clear the TZ envvar, so daemons always respect /etc/localtime
|
||||||
|
# unset TZ
|
||||||
|
|
||||||
|
. /etc/profile.d/locale.sh
|
||||||
|
|
||||||
|
# width:
|
||||||
|
calc_columns () {
|
||||||
|
STAT_COL=80
|
||||||
|
if [[ ! -t 1 ]]; then
|
||||||
|
USECOLOR=""
|
||||||
|
elif [[ -t 0 ]]; then
|
||||||
|
# stty will fail when stdin isn't a terminal
|
||||||
|
STAT_COL=$(stty size)
|
||||||
|
# stty gives "rows cols"; strip the rows number, we just want columns
|
||||||
|
STAT_COL=${STAT_COL##* }
|
||||||
|
elif tput cols &>/dev/null; then
|
||||||
|
# is /usr/share/terminfo already mounted, and TERM recognized?
|
||||||
|
STAT_COL=$(tput cols)
|
||||||
|
fi
|
||||||
|
if (( STAT_COL == 0 )); then
|
||||||
|
# if output was 0 (serial console), set default width to 80
|
||||||
|
STAT_COL=80
|
||||||
|
USECOLOR=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# we use 13 characters for our own stuff
|
||||||
|
STAT_COL=$(( STAT_COL - 13 ))
|
||||||
|
|
||||||
|
if [[ -t 1 ]]; then
|
||||||
|
SAVE_POSITION="\e[s"
|
||||||
|
RESTORE_POSITION="\e[u"
|
||||||
|
DEL_TEXT="\e[$(( STAT_COL + 4 ))G"
|
||||||
|
else
|
||||||
|
SAVE_POSITION=""
|
||||||
|
RESTORE_POSITION=""
|
||||||
|
DEL_TEXT=""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
calc_columns
|
||||||
|
|
||||||
|
# disable colors on broken terminals
|
||||||
|
TERM_COLORS=$(tput colors 2>/dev/null)
|
||||||
|
if (( $? != 3 )); then
|
||||||
|
case $TERM_COLORS in
|
||||||
|
*[!0-9]*) USECOLOR="";;
|
||||||
|
[0-7]) USECOLOR="";;
|
||||||
|
'') USECOLOR="";;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
unset TERM_COLORS
|
||||||
|
|
||||||
|
unquote() {
|
||||||
|
local -r quotes=$'[\'"]'
|
||||||
|
|
||||||
|
if [[ ${1:0:1} = $quotes && ${1:(-1)} = "${1:0:1}" ]]; then
|
||||||
|
printf '%s' "${1:1:(-1)}"
|
||||||
|
else
|
||||||
|
printf '%s' "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# functions:
|
||||||
|
|
||||||
|
deltext() {
|
||||||
|
printf "${DEL_TEXT}"
|
||||||
|
}
|
||||||
|
|
||||||
|
printhl() {
|
||||||
|
printf "${C_OTHER}${PREFIX_HL} ${C_H1}${1}${C_CLEAR} \n"
|
||||||
|
}
|
||||||
|
|
||||||
|
printsep() {
|
||||||
|
printf "\n${C_SEPARATOR} ------------------------------\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
stat_busy() {
|
||||||
|
printf "${C_OTHER}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR} "
|
||||||
|
printf "${SAVE_POSITION}"
|
||||||
|
deltext
|
||||||
|
printf " ${C_OTHER}[${C_BUSY}BUSY${C_OTHER}]${C_CLEAR} "
|
||||||
|
}
|
||||||
|
|
||||||
|
stat_done() {
|
||||||
|
deltext
|
||||||
|
printf " ${C_OTHER}[${C_DONE}DONE${C_OTHER}]${C_CLEAR} \n"
|
||||||
|
}
|
||||||
|
|
||||||
|
stat_fail() {
|
||||||
|
deltext
|
||||||
|
printf " ${C_OTHER}[${C_FAIL}FAIL${C_OTHER}]${C_CLEAR} \n"
|
||||||
|
}
|
||||||
|
|
||||||
|
status() {
|
||||||
|
local quiet
|
||||||
|
case $1 in
|
||||||
|
-q)
|
||||||
|
quiet=1
|
||||||
|
;;&
|
||||||
|
-v)
|
||||||
|
# NOOP: supported for backwards compat
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
stat_busy "$1"
|
||||||
|
shift
|
||||||
|
if (( quiet )); then
|
||||||
|
"$@" &>/dev/null
|
||||||
|
else
|
||||||
|
"$@"
|
||||||
|
fi
|
||||||
|
local ret=$?
|
||||||
|
(( ret == 0 )) && stat_done || stat_fail
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
# usage : in_array( $needle, $haystack )
|
||||||
|
# return : 0 - found
|
||||||
|
# 1 - not found
|
||||||
|
in_array() {
|
||||||
|
local needle=$1; shift
|
||||||
|
local item
|
||||||
|
for item; do
|
||||||
|
[[ $item = "${needle}" ]] && return 0
|
||||||
|
done
|
||||||
|
return 1 # Not Found
|
||||||
|
}
|
||||||
|
|
||||||
|
kill_all() {
|
||||||
|
stat_busy "Sending TERM signal to processes"
|
||||||
|
pkill --inverse -s0,1 -TERM
|
||||||
|
if (( $? == 0 )); then
|
||||||
|
stat_done
|
||||||
|
else
|
||||||
|
stat_fail
|
||||||
|
sleep 1
|
||||||
|
status "Sending KILL signal to processes" pkill --inverse -s0,1 -KILL
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
print_welcome() {
|
||||||
|
# see os-release(5)
|
||||||
|
. /etc/os-release
|
||||||
|
|
||||||
|
echo " "
|
||||||
|
printhl "${PRETTY_NAME}\n"
|
||||||
|
printhl "${C_H2}${HOME_URL}"
|
||||||
|
printsep
|
||||||
|
}
|
||||||
|
|
||||||
|
load_modules() {
|
||||||
|
local rc=0
|
||||||
|
|
||||||
|
/usr/bin/modules-load
|
||||||
|
(( rc+=$? ))
|
||||||
|
|
||||||
|
return $rc
|
||||||
|
}
|
||||||
|
|
||||||
|
# Start/trigger udev, load MODULES, and settle udev
|
||||||
|
udevd_modprobe() {
|
||||||
|
# $1 = where we are being called from.
|
||||||
|
# This is used to determine which hooks to run.
|
||||||
|
status "Starting udev daemon" udevd --daemon
|
||||||
|
|
||||||
|
run_hook "$1_udevlaunched"
|
||||||
|
|
||||||
|
stat_busy "Triggering udev uevents"
|
||||||
|
udevadm trigger --action=add --type=subsystems
|
||||||
|
udevadm trigger --action=add --type=devices
|
||||||
|
stat_done
|
||||||
|
|
||||||
|
# Load modules from the MODULES array and modules-load.d
|
||||||
|
status "Loading user-specified modules" load_modules
|
||||||
|
|
||||||
|
status "Waiting for udev uevents to be processed" \
|
||||||
|
udevadm settle
|
||||||
|
|
||||||
|
run_hook "$1_udevsettled"
|
||||||
|
|
||||||
|
# in case loading a module changed the display mode
|
||||||
|
calc_columns
|
||||||
|
}
|
||||||
|
|
||||||
|
activate_vgs() {
|
||||||
|
[[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return 0
|
||||||
|
stat_busy "Activating LVM2 groups"
|
||||||
|
vgchange --sysinit -a y >/dev/null
|
||||||
|
(( $? == 0 )) && stat_done || stat_fail
|
||||||
|
}
|
||||||
|
|
||||||
|
do_unlock_legacy() {
|
||||||
|
# $1 = requested name
|
||||||
|
# $2 = source device
|
||||||
|
# $3 = password
|
||||||
|
# $4 = options
|
||||||
|
local open=create a=$1 b=$2 failed=0
|
||||||
|
# Ordering of options is different if you are using LUKS vs. not.
|
||||||
|
# Use ugly swizzling to deal with it.
|
||||||
|
# isLuks only gives an exit code but no output to stdout or stderr.
|
||||||
|
if cryptsetup isLuks "$2" 2>/dev/null; then
|
||||||
|
open=luksOpen
|
||||||
|
a=$2
|
||||||
|
b=$1
|
||||||
|
fi
|
||||||
|
case $3 in
|
||||||
|
SWAP)
|
||||||
|
local _overwriteokay=0
|
||||||
|
if [[ -b $2 && -r $2 ]]; then
|
||||||
|
# This is DANGEROUS! If there is any known file system,
|
||||||
|
# partition table, RAID, or LVM volume on the device,
|
||||||
|
# we don't overwrite it.
|
||||||
|
#
|
||||||
|
# 'blkid' returns 2 if no valid signature has been found.
|
||||||
|
# Only in this case should we allow overwriting the device.
|
||||||
|
#
|
||||||
|
# This sanity check _should_ be sufficient, but it might not.
|
||||||
|
# This may cause data loss if it is not used carefully.
|
||||||
|
blkid -p "$2" &>/dev/null
|
||||||
|
(( $? == 2 )) && _overwriteokay=1
|
||||||
|
fi
|
||||||
|
if (( _overwriteokay == 0 )); then
|
||||||
|
false
|
||||||
|
elif cryptsetup -d /dev/urandom $4 $open "$a" "$b" >/dev/null; then
|
||||||
|
printf "creating swapspace..\n"
|
||||||
|
mkswap -f -L $1 /dev/mapper/$1 >/dev/null
|
||||||
|
fi;;
|
||||||
|
ASK)
|
||||||
|
printf "\nOpening '$1' volume:\n"
|
||||||
|
cryptsetup $4 $open "$a" "$b" < /dev/console;;
|
||||||
|
/dev*)
|
||||||
|
local ckdev=${3%%:*}
|
||||||
|
local cka=${3#*:}
|
||||||
|
local ckb=${cka#*:}
|
||||||
|
local cka=${cka%:*}
|
||||||
|
local ckfile=/dev/ckfile
|
||||||
|
local ckdir=/dev/ckdir
|
||||||
|
case ${cka} in
|
||||||
|
*[!0-9]*)
|
||||||
|
# Use a file on the device
|
||||||
|
# cka is not numeric: cka=filesystem, ckb=path
|
||||||
|
mkdir ${ckdir}
|
||||||
|
mount -r -t ${cka} ${ckdev} ${ckdir}
|
||||||
|
dd if=${ckdir}/${ckb} of=${ckfile} >/dev/null 2>&1
|
||||||
|
umount ${ckdir}
|
||||||
|
rmdir ${ckdir};;
|
||||||
|
*)
|
||||||
|
# Read raw data from the block device
|
||||||
|
# cka is numeric: cka=offset, ckb=length
|
||||||
|
dd if=${ckdev} of=${ckfile} bs=1 skip=${cka} count=${ckb} >/dev/null 2>&1;;
|
||||||
|
esac
|
||||||
|
cryptsetup -d ${ckfile} $4 $open "$a" "$b" >/dev/null
|
||||||
|
dd if=/dev/urandom of=${ckfile} bs=1 count=$(stat -c %s ${ckfile}) conv=notrunc >/dev/null 2>&1
|
||||||
|
rm ${ckfile};;
|
||||||
|
/*)
|
||||||
|
cryptsetup -d "$3" $4 $open "$a" "$b" >/dev/null;;
|
||||||
|
*)
|
||||||
|
echo "$3" | cryptsetup $4 $open "$a" "$b" >/dev/null;;
|
||||||
|
esac
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
do_unlock() {
|
||||||
|
local name=$1 device=$2 password=$3 options=$4
|
||||||
|
|
||||||
|
printf "${C_MAIN}Unlocking $1${C_CLEAR}\n"
|
||||||
|
|
||||||
|
if [[ ${options:0:2} =~ -. ]]; then
|
||||||
|
do_unlock_legacy "$name" "$device" "$password" "$options"
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $password in
|
||||||
|
ASK|SWAP)
|
||||||
|
do_unlock_legacy "$name" "$device" "$password" "$options"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
do_unlock_legacy "$name" "$device" "$password" "$options"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
failed=$?
|
||||||
|
if (( $failed )); then
|
||||||
|
printf "${C_FAIL}Unlocking of $1 failed.${C_CLEAR}\n"
|
||||||
|
fi
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
deactivate_crypt() {
|
||||||
|
if [[ -x /usr/bin/dmsetup ]]; then
|
||||||
|
for v in $(dmsetup ls --target crypt --exec "dmsetup info -c --noheadings -o open,name"); do
|
||||||
|
[[ ${v%%:*} == "0" ]] && cryptsetup close ${v##*:}
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
set_timezone() {
|
||||||
|
local tz=$1 zonefile=/usr/share/zoneinfo/$1
|
||||||
|
|
||||||
|
[[ $tz ]] || return 1
|
||||||
|
|
||||||
|
if [[ ! -e $zonefile ]]; then
|
||||||
|
printf "error: \`%s' is not a valid time zone\n" "$tz"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -L /etc/localtime && /etc/localtime -ef $zonefile ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
ln -sf "/usr/share/zoneinfo/$tz" /etc/localtime
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Filesystem functions
|
||||||
|
# These can be overridden/reused for customizations like shutdown/loop-fsck.
|
||||||
|
NETFS="nfs,nfs4,smbfs,cifs,codafs,ncpfs,shfs,fuse,fuseblk,glusterfs,davfs,fuse.glusterfs"
|
||||||
|
|
||||||
|
# Check local filesystems
|
||||||
|
fsck_all() {
|
||||||
|
if [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline); then
|
||||||
|
FORCEFSCK="-f"
|
||||||
|
elif [[ -f /fastboot ]] || in_array fastboot $(< /proc/cmdline); then
|
||||||
|
return 0
|
||||||
|
elif [[ -e /run/initramfs/root-fsck ]]; then
|
||||||
|
IGNORE_MOUNTED="-M"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fsck -A -T -C${FSCK_FD} -a -t no${NETFS//,/,no},noopts=_netdev ${IGNORE_MOUNTED} -- ${FORCEFSCK}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Single-user login and/or automatic reboot after fsck (if needed)
|
||||||
|
fsck_reboot() {
|
||||||
|
# $1 = exit code returned by fsck
|
||||||
|
# Ignore conditions 'FS errors corrected' and 'Cancelled by the user'
|
||||||
|
(( ($1 | 33) == 33 )) && return 0
|
||||||
|
if (( $1 & 2 )); then
|
||||||
|
echo
|
||||||
|
echo "********************** REBOOT REQUIRED *********************"
|
||||||
|
echo "* *"
|
||||||
|
echo "* The system will be rebooted automatically in 15 seconds. *"
|
||||||
|
echo "* *"
|
||||||
|
echo "************************************************************"
|
||||||
|
echo
|
||||||
|
sleep 15
|
||||||
|
else
|
||||||
|
echo
|
||||||
|
echo "***************** FILESYSTEM CHECK FAILED ****************"
|
||||||
|
echo "* *"
|
||||||
|
echo "* Please repair manually and reboot. Note that the root *"
|
||||||
|
echo "* file system is currently mounted read-only. To remount *"
|
||||||
|
echo "* it read-write, type: mount -o remount,rw / *"
|
||||||
|
echo "* When you exit the maintenance shell, the system will *"
|
||||||
|
echo "* reboot automatically. *"
|
||||||
|
echo "* *"
|
||||||
|
echo "************************************************************"
|
||||||
|
echo
|
||||||
|
sulogin -p
|
||||||
|
fi
|
||||||
|
echo "Automatic reboot in progress..."
|
||||||
|
umount -a
|
||||||
|
mount -o remount,ro /
|
||||||
|
reboot -f
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
mount_all() {
|
||||||
|
mount -a -t "no${NETFS//,/,no}" -O no_netdev
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_leftover() {
|
||||||
|
status 'Removing leftover files' tmpfiles --create --remove --clean
|
||||||
|
}
|
||||||
|
|
||||||
|
bootlogd_stop() {
|
||||||
|
[[ -f /run/bootlogd.pid ]] || return 0
|
||||||
|
touch /var/log/boot
|
||||||
|
kill $(< /run/bootlogd.pid)
|
||||||
|
rm -f /run/bootlogd.pid
|
||||||
|
}
|
||||||
|
|
||||||
|
bootlogd_start(){
|
||||||
|
[[ ! -f /var/log/boot ]] && touch /var/log/boot
|
||||||
|
bootlogd -p /run/bootlogd.pid
|
||||||
|
}
|
||||||
|
|
||||||
|
console_setup(){
|
||||||
|
TTYS=${TTYS:-6}
|
||||||
|
if [ -n "$FONT" ]; then
|
||||||
|
_index=0
|
||||||
|
while [ ${_index} -le $TTYS ]; do
|
||||||
|
setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} \
|
||||||
|
$FONT -C "/dev/tty${_index}"
|
||||||
|
_index=$((_index + 1))
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if [ -n "$KEYMAP" ]; then
|
||||||
|
loadkeys -q -u ${KEYMAP}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
init_random_seed(){
|
||||||
|
cp /var/lib/random-seed /dev/urandom >/dev/null 2>&1 || true
|
||||||
|
( 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 )
|
||||||
|
}
|
||||||
|
|
||||||
|
save_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 )
|
||||||
|
}
|
||||||
|
|
||||||
|
mk_kmod_static_nodes(){
|
||||||
|
[[ -d /run/tmpfiles.d ]] || mkdir /run/tmpfiles.d
|
||||||
|
kmod static-nodes --format=tmpfiles --output=/run/tmpfiles.d/kmod.conf
|
||||||
|
}
|
||||||
|
|
||||||
|
mk_tmpfiles_dev(){
|
||||||
|
if [ -x /usr/bin/tmpfiles ]; then
|
||||||
|
tmpfiles --prefix=/dev --create --boot
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mk_tmpfiles_setup(){
|
||||||
|
if [ -x /usr/bin/tmpfiles ]; then
|
||||||
|
tmpfiles --exclude-prefix=/dev --create --remove --boot
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
mk_sysusers(){
|
||||||
|
if [ -x /usr/bin/sysusers ]; then
|
||||||
|
sysusers
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_1(){
|
||||||
|
install -m0664 -o root -g utmp /dev/null /run/utmp
|
||||||
|
if [ ! -e /var/log/wtmp ]; then
|
||||||
|
install -m0664 -o root -g utmp /dev/null /var/log/wtmp
|
||||||
|
fi
|
||||||
|
if [ ! -e /var/log/btmp ]; then
|
||||||
|
install -m0600 -o root -g utmp /dev/null /var/log/btmp
|
||||||
|
fi
|
||||||
|
rm -rf /tmp
|
||||||
|
install -dm1777 /tmp /tmp/.X11-unix /tmp/.ICE-unix
|
||||||
|
rm -f /etc/nologin #/forcefsck /forcequotacheck /fastboot
|
||||||
|
}
|
||||||
|
|
||||||
|
###############################
|
||||||
|
# Custom hooks in initscripts #
|
||||||
|
###############################
|
||||||
|
# Hooks can be used to include custom code in various places in the rc.* scripts
|
||||||
|
#
|
||||||
|
# Define a hook function in a functions.d file using:
|
||||||
|
# function_name() {
|
||||||
|
# ...
|
||||||
|
# }
|
||||||
|
# add_hook hook_name function_name
|
||||||
|
# It is allowed to register several hook functions for the same hook
|
||||||
|
# Is is also allowed to register the same hook function for several hooks
|
||||||
|
#
|
||||||
|
# Currently, the following hooks exist:
|
||||||
|
# sysinit_start: at the beginning of rc.sysinit
|
||||||
|
# shutdown_start: at the beginning of rc.shutdown
|
||||||
|
# sysinit_end: at the end of rc.sysinit
|
||||||
|
# sysinit_udevlaunched: after udev has been launched in rc.sysinit
|
||||||
|
# sysinit_udevsettled: after uevents have settled in rc.sysinit
|
||||||
|
# sysinit_premount: before local filesystems are mounted, but after root is mounted read-write in rc.sysinit
|
||||||
|
# sysinit_postmount: after local filesystems are mounted
|
||||||
|
# shutdown_prekillall: before all processes are being killed in rc.shutdown
|
||||||
|
# shutdown_postkillall: after all processes have been killed in rc.shutdown
|
||||||
|
# shutdown_preumount: after last filesystem write, but before filesystems are unmounted
|
||||||
|
# shutdown_postumount: after filesystems are unmounted
|
||||||
|
# shutdown_poweroff: directly before powering off in rc.shutdown
|
||||||
|
#
|
||||||
|
# Declare add_hook and run_hook as read-only to prevent overwriting them.
|
||||||
|
# Too bad we cannot do the same thing with hook_funcs
|
||||||
|
|
||||||
|
if (( RC_FUNCTIONS_HOOK_FUNCS_DEFINED != 1 )); then
|
||||||
|
declare -A hook_funcs
|
||||||
|
|
||||||
|
add_hook() {
|
||||||
|
[[ $1 && $2 ]] || return 1
|
||||||
|
hook_funcs[$1]+=" $2"
|
||||||
|
}
|
||||||
|
|
||||||
|
run_hook() {
|
||||||
|
[[ $1 ]] || return 1
|
||||||
|
local func
|
||||||
|
for func in ${hook_funcs["$1"]}; do
|
||||||
|
"${func}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
declare -fr add_hook run_hook
|
||||||
|
declare -r RC_FUNCTIONS_HOOK_FUNCS_DEFINED=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# set colors
|
||||||
|
if [[ $USECOLOR != [nN][oO] ]]; then
|
||||||
|
if tput setaf 0 &>/dev/null; then
|
||||||
|
C_CLEAR=$(tput sgr0) # clear text
|
||||||
|
C_MAIN=${C_CLEAR}$(tput bold) # main text
|
||||||
|
C_OTHER=${C_MAIN}$(tput setaf 4) # prefix & brackets
|
||||||
|
C_SEPARATOR=${C_MAIN}$(tput setaf 0) # separator
|
||||||
|
C_BUSY=${C_CLEAR}$(tput setaf 6) # busy
|
||||||
|
C_FAIL=${C_MAIN}$(tput setaf 1) # failed
|
||||||
|
C_DONE=${C_MAIN} # completed
|
||||||
|
C_BKGD=${C_MAIN}$(tput setaf 5) # backgrounded
|
||||||
|
C_H1=${C_MAIN} # highlight text 1
|
||||||
|
C_H2=${C_MAIN}$(tput setaf 6) # highlight text 2
|
||||||
|
else
|
||||||
|
C_CLEAR="\e[m" # clear text
|
||||||
|
C_MAIN="\e[;1m" # main text
|
||||||
|
C_OTHER="\e[1;34m" # prefix & brackets
|
||||||
|
C_SEPARATOR="\e[1;30m" # separator
|
||||||
|
C_BUSY="\e[;36m" # busy
|
||||||
|
C_FAIL="\e[1;31m" # failed
|
||||||
|
C_DONE=${C_MAIN} # completed
|
||||||
|
C_BKGD="\e[1;35m" # backgrounded
|
||||||
|
C_H1=${C_MAIN} # highlight text 1
|
||||||
|
C_H2="\e[1;36m" # highlight text 2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# prefixes:
|
||||||
|
|
||||||
|
PREFIX_REG="::"
|
||||||
|
PREFIX_HL=" >"
|
||||||
|
|
||||||
|
# Source additional functions at the end to allow overrides
|
||||||
|
# for f in @RCDIR@/functions.d/*; do
|
||||||
|
# [[ -e $f ]] && . "$f"
|
||||||
|
# done
|
||||||
|
|
67
rc/halt.8
Normal file
67
rc/halt.8
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
.Dd July 29, 2014
|
||||||
|
.Dt HALT 8
|
||||||
|
.Os Linux
|
||||||
|
.Sh NAME
|
||||||
|
.Nm halt ,
|
||||||
|
.Nm reboot ,
|
||||||
|
.Nm poweroff
|
||||||
|
.Nd stop the system
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.Nm halt
|
||||||
|
.Op Fl n
|
||||||
|
.Op Fl f
|
||||||
|
.Nm reboot
|
||||||
|
.Op Fl n
|
||||||
|
.Op Fl f
|
||||||
|
.Nm poweroff
|
||||||
|
.Op Fl n
|
||||||
|
.Op Fl f
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
.Nm halt
|
||||||
|
/
|
||||||
|
.Nm reboot
|
||||||
|
/
|
||||||
|
.Nm poweroff
|
||||||
|
tells
|
||||||
|
.Xr init 8
|
||||||
|
to bring down, reboot, or power off the system.
|
||||||
|
Without
|
||||||
|
.Fl f ,
|
||||||
|
it is a shortcut for
|
||||||
|
.Nm init 0
|
||||||
|
/
|
||||||
|
.Nm init 6 .
|
||||||
|
.Bl -tag -width indent
|
||||||
|
.It Fl n
|
||||||
|
Don't sync before reboot or halt.
|
||||||
|
Note that the kernel and storage drivers may still sync.
|
||||||
|
.It Fl f
|
||||||
|
Force halt or reboot, don't call
|
||||||
|
.Xr init 8 .
|
||||||
|
This is
|
||||||
|
.Sy dangerous !
|
||||||
|
.El
|
||||||
|
.Sh UNSUPPORTED OPTIONS
|
||||||
|
This version of
|
||||||
|
.Nm
|
||||||
|
is based on
|
||||||
|
.Xr runit 8 ,
|
||||||
|
the following features are
|
||||||
|
.Sy not
|
||||||
|
supported and silently ignored:
|
||||||
|
.Bl -tag -width indent
|
||||||
|
.It Fl w
|
||||||
|
to just write the wtmp record.
|
||||||
|
.It Fl d
|
||||||
|
to not write the wtmp record.
|
||||||
|
.It Fl h
|
||||||
|
to put hard drives in standby mode.
|
||||||
|
.It Fl i
|
||||||
|
to shut down network interfaces.
|
||||||
|
.El
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr init 8 ,
|
||||||
|
.Xr shutdown 8
|
||||||
|
.Sh AUTHOR
|
||||||
|
.An Leah Neukirchen ,
|
||||||
|
.Mt leah@vuxu.org .
|
77
rc/halt.c
Normal file
77
rc/halt.c
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <err.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/reboot.h>
|
||||||
|
|
||||||
|
extern char *__progname;
|
||||||
|
|
||||||
|
typedef enum {NOOP, HALT, REBOOT, POWEROFF} action_type;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
int do_sync = 1;
|
||||||
|
int do_force = 0;
|
||||||
|
int opt;
|
||||||
|
action_type action = NOOP;
|
||||||
|
|
||||||
|
if (strcmp(__progname, "halt") == 0)
|
||||||
|
action = HALT;
|
||||||
|
else if (strcmp(__progname, "reboot") == 0)
|
||||||
|
action = REBOOT;
|
||||||
|
else if (strcmp(__progname, "poweroff") == 0)
|
||||||
|
action = POWEROFF;
|
||||||
|
else
|
||||||
|
warnx("no default behavior, needs to be called as halt/reboot/poweroff.");
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "dfhinw")) != -1)
|
||||||
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
do_sync = 0;
|
||||||
|
break;
|
||||||
|
case 'w':
|
||||||
|
action = NOOP;
|
||||||
|
do_sync = 0;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
case 'h':
|
||||||
|
case 'i':
|
||||||
|
/* silently ignored. */
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
do_force = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
errx(1, "Usage: %s [-n] [-f]", __progname);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (do_sync)
|
||||||
|
sync();
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
case HALT:
|
||||||
|
if (do_force)
|
||||||
|
reboot(RB_HALT_SYSTEM);
|
||||||
|
else
|
||||||
|
execl("/bin/runit-init", "init", "0", (char*)0);
|
||||||
|
err(1, "halt failed");
|
||||||
|
break;
|
||||||
|
case POWEROFF:
|
||||||
|
if (do_force)
|
||||||
|
reboot(RB_POWER_OFF);
|
||||||
|
else
|
||||||
|
execl("/bin/runit-init", "init", "0", (char*)0);
|
||||||
|
err(1, "poweroff failed");
|
||||||
|
break;
|
||||||
|
case REBOOT:
|
||||||
|
if (do_force)
|
||||||
|
reboot(RB_AUTOBOOT);
|
||||||
|
else
|
||||||
|
execl("/bin/runit-init", "init", "6", (char*)0);
|
||||||
|
err(1, "reboot failed");
|
||||||
|
break;
|
||||||
|
case NOOP:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
13
rc/rc.conf.in
Normal file
13
rc/rc.conf.in
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# @RCDIR@/rc.conf - system configuration
|
||||||
|
|
||||||
|
# Storage
|
||||||
|
#
|
||||||
|
# USEDMRAID="no"
|
||||||
|
# USELVM="no"
|
||||||
|
|
||||||
|
# Network
|
||||||
|
#
|
||||||
|
# interface=
|
||||||
|
# address=
|
||||||
|
# netmask=
|
||||||
|
# gateway=
|
4
rc/rc.local.in
Normal file
4
rc/rc.local.in
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Default rc.local; add your custom commands here.
|
||||||
|
#
|
||||||
|
# This is run by runit in stage 2 before the services are executed
|
||||||
|
# (see /etc/runit/2).
|
90
rc/shutdown.8
Normal file
90
rc/shutdown.8
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
.Dd July 29, 2014
|
||||||
|
.Dt SHUTDOWN 8
|
||||||
|
.Os Linux
|
||||||
|
.Sh NAME
|
||||||
|
.Nm shutdown
|
||||||
|
.Nd bring down the system
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.Nm shutdown
|
||||||
|
.Op Fl rhP
|
||||||
|
.Op Fl fF
|
||||||
|
.Op Cm now | Cm + Ns Ar mins
|
||||||
|
.Op Ar message ...
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
.Nm
|
||||||
|
brings the system down in a secure way.
|
||||||
|
All logged-in users
|
||||||
|
are notified that the system is going down, and
|
||||||
|
.Xr login 1
|
||||||
|
is blocked.
|
||||||
|
.Pp
|
||||||
|
By default,
|
||||||
|
.Nm
|
||||||
|
puts the system into single user mode.
|
||||||
|
Rebooting and halting the system can be done using the following options:
|
||||||
|
.Bl -tag -width indent
|
||||||
|
.It Fl c
|
||||||
|
Cancel an ongoing shutdown.
|
||||||
|
.It Fl f
|
||||||
|
Enable fast booting; skip
|
||||||
|
.Xr fsck 8
|
||||||
|
on next boot.
|
||||||
|
.It Fl F
|
||||||
|
Force run of
|
||||||
|
.Xr fsck 8
|
||||||
|
on next boot.
|
||||||
|
.It Fl h
|
||||||
|
Halt the system.
|
||||||
|
.It Fl k
|
||||||
|
Don't really shutdown; only send the warning messages to everybody.
|
||||||
|
.It Fl P
|
||||||
|
Poweroff the system.
|
||||||
|
.It Fl r
|
||||||
|
Reboot the system.
|
||||||
|
.It Cm now
|
||||||
|
Shutdown without further waiting.
|
||||||
|
.It Cm + Ns Ar mins
|
||||||
|
Wait
|
||||||
|
.Ar mins
|
||||||
|
minutes before shutting down.
|
||||||
|
.It Ar message
|
||||||
|
Message displayed to all users, defaults to "system is going down".
|
||||||
|
.El
|
||||||
|
.Sh UNSUPPORTED OPTIONS
|
||||||
|
This version of
|
||||||
|
.Nm
|
||||||
|
is based on
|
||||||
|
.Xr runit 8 ,
|
||||||
|
the following features are
|
||||||
|
.Sy not
|
||||||
|
supported:
|
||||||
|
.Bl -tag -width indent
|
||||||
|
.It Fl t Ar secs
|
||||||
|
to wait
|
||||||
|
.Ar secs
|
||||||
|
seconds between SIGKILL and SIGTERM on shutdown is silently ignored.
|
||||||
|
.It Fl a
|
||||||
|
Use
|
||||||
|
.Pa /etc/shutdown.allow .
|
||||||
|
.It Fl H
|
||||||
|
Drop into boot monitor.
|
||||||
|
.It Fl n
|
||||||
|
Don't call
|
||||||
|
.Xr init 8 .
|
||||||
|
.It Ar hh Ns : Ns Ar mm
|
||||||
|
Absolute time specification is not implemented.
|
||||||
|
.El
|
||||||
|
.Sh EXAMPLES
|
||||||
|
Turn off the system:
|
||||||
|
.Dl # shutdown -h now
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr fsck 8 ,
|
||||||
|
.Xr halt 8 ,
|
||||||
|
.Xr init 8 ,
|
||||||
|
.Xr poweroff 8 ,
|
||||||
|
.Xr reboot 8 ,
|
||||||
|
.Xr runit 8 ,
|
||||||
|
.Xr runsvchdir 8
|
||||||
|
.Sh AUTHOR
|
||||||
|
.An Leah Neukirchen ,
|
||||||
|
.Mt leah@vuxu.org .
|
1
rc/shutdown.d/01-random-seed.sh
Normal file
1
rc/shutdown.d/01-random-seed.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
status 'Saving random seed' save_random_seed
|
1
rc/shutdown.d/02-timezone.sh
Normal file
1
rc/shutdown.d/02-timezone.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[[ $TIMEZONE ]] && status "Configuring time zone" set_timezone "$TIMEZONE"
|
2
rc/shutdown.d/03-wtmp.sh
Normal file
2
rc/shutdown.d/03-wtmp.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Write to wtmp file before unmounting
|
||||||
|
halt -w
|
3
rc/shutdown.d/04-lvm2-monitoring.sh
Normal file
3
rc/shutdown.d/04-lvm2-monitoring.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# stop monitoring of LVM2 groups before unmounting filesystems
|
||||||
|
[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) ]] &&
|
||||||
|
status "Deactivating monitoring of LVM2 groups" vgchange --monitor n
|
2
rc/shutdown.d/05-udev.sh
Normal file
2
rc/shutdown.d/05-udev.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# any future uevents can and should be ignored
|
||||||
|
status "Shutting down udev" udevadm control --exit
|
3
rc/shutdown.d/06-kill-all.sh
Normal file
3
rc/shutdown.d/06-kill-all.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
run_hook shutdown_prekillall
|
||||||
|
kill_all
|
||||||
|
run_hook shutdown_postkillall
|
3
rc/shutdown.d/08-swap.sh
Normal file
3
rc/shutdown.d/08-swap.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# almost everything is dead now, so the swap should hopefully be relatively
|
||||||
|
# empty, and quick to switch off
|
||||||
|
status "Deactivating swap" swapoff -a
|
3
rc/shutdown.d/09-umount-api-fs.sh
Normal file
3
rc/shutdown.d/09-umount-api-fs.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
run_hook shutdown_preumount
|
||||||
|
status "Unmounting non-API filesystems" umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
|
||||||
|
run_hook shutdown_postumount
|
7
rc/shutdown.d/10-cryptsetup.sh
Normal file
7
rc/shutdown.d/10-cryptsetup.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Kill non-root encrypted partition mappings
|
||||||
|
if [[ -f /etc/crypttab ]] && type -p cryptsetup >/dev/null; then
|
||||||
|
# Maybe someone has LVM on an encrypted block device
|
||||||
|
# executing an extra vgchange is errorless
|
||||||
|
[[ $USELVM = [Yy][Ee][Ss] ]] && vgchange --sysinit -a n &>/dev/null
|
||||||
|
deactivate_crypt
|
||||||
|
fi
|
2
rc/shutdown.d/11-lvm2.sh
Normal file
2
rc/shutdown.d/11-lvm2.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) ]] &&
|
||||||
|
status "Deactivating LVM2 groups" vgchange --sysinit -a n &>/dev/null
|
2
rc/shutdown.d/12-remount-rootfs-ro.sh
Normal file
2
rc/shutdown.d/12-remount-rootfs-ro.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
status "Remounting root filesystem read-only" \
|
||||||
|
mount -o remount,ro /
|
@@ -37,7 +37,7 @@ time=$1; shift
|
|||||||
message="${*:-system is going down}"
|
message="${*:-system is going down}"
|
||||||
|
|
||||||
if [ "$action" = "cancel" ]; then
|
if [ "$action" = "cancel" ]; then
|
||||||
kill "$(cat /run/runit/shutdown.pid)"
|
kill "$(cat @RUNDIR@/shutdown.pid)"
|
||||||
if [ -e /etc/nologin ] && ! [ -s /etc/nologin ]; then
|
if [ -e /etc/nologin ] && ! [ -s /etc/nologin ]; then
|
||||||
rm /etc/nologin
|
rm /etc/nologin
|
||||||
fi
|
fi
|
||||||
@@ -45,8 +45,8 @@ if [ "$action" = "cancel" ]; then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
touch /run/runit/shutdown.pid 2>/dev/null || abort "Not enough permissions to execute ${0#*/}"
|
touch @RUNDIR@/shutdown.pid 2>/dev/null || abort "Not enough permissions to execute ${0#*/}"
|
||||||
echo $$ >/run/runit/shutdown.pid
|
echo $$ >@RUNDIR@/shutdown.pid
|
||||||
|
|
||||||
case "$time" in
|
case "$time" in
|
||||||
now) time=0;;
|
now) time=0;;
|
16
rc/sysinit.d/01-mount-api-fs.sh
Normal file
16
rc/sysinit.d/01-mount-api-fs.sh
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# mount the API filesystems
|
||||||
|
# /proc, /sys, /run, /dev, /run/lock, /dev/pts, /dev/shm
|
||||||
|
mountpoint -q /proc || mount -t proc proc /proc -o nosuid,noexec,nodev
|
||||||
|
mountpoint -q /sys || mount -t sysfs sys /sys -o nosuid,noexec,nodev
|
||||||
|
mountpoint -q /run || mount -t tmpfs run /run -o mode=0755,nosuid,nodev
|
||||||
|
mountpoint -q /dev || mount -t devtmpfs dev /dev -o mode=0755,nosuid
|
||||||
|
mkdir -p /dev/{pts,shm}
|
||||||
|
mountpoint -q /dev/pts || mount -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec
|
||||||
|
mountpoint -q /dev/shm || mount -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev
|
||||||
|
mountpoint -q /sys/kernel/security || mount -n -t securityfs securityfs /sys/kernel/security
|
||||||
|
mountpoint -q /sys/firmware/efi/efivars || mount -n -t efivarfs -o ro efivarfs /sys/firmware/efi/efivars
|
||||||
|
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
|
||||||
|
|
||||||
|
findmnt / --options ro &>/dev/null || status "Mounting root read-only" mount -o remount,ro /
|
10
rc/sysinit.d/02-hostname.sh
Normal file
10
rc/sysinit.d/02-hostname.sh
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
unset HOSTNAME
|
||||||
|
|
||||||
|
if [[ -s /etc/hostname ]]; then
|
||||||
|
HOSTNAME=$(< /etc/hostname)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $HOSTNAME ]]; then
|
||||||
|
stat_busy "Setting hostname: $HOSTNAME"
|
||||||
|
echo "$HOSTNAME" >| /proc/sys/kernel/hostname && stat_done || stat_fail
|
||||||
|
fi
|
34
rc/sysinit.d/03-hwclock.sh
Normal file
34
rc/sysinit.d/03-hwclock.sh
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
HWCLOCK_PARAMS="--systz"
|
||||||
|
|
||||||
|
if [[ $HARDWARECLOCK ]]; then
|
||||||
|
|
||||||
|
[[ -f /etc/adjtime ]] && { read ; read ; read ADJTIME; } < /etc/adjtime
|
||||||
|
|
||||||
|
if [[ $ADJTIME == 'LOCAL' ]]; then
|
||||||
|
if [[ $HARDWARECLOCK == 'UTC' ]]; then
|
||||||
|
printf "${C_FAIL}@RCDIR@/rc.conf says the RTC is in UTC, but /etc/adjtime says it is in localtime.\n${C_OTHER}."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [[ $HARDWARECLOCK == 'LOCALTIME' ]]; then
|
||||||
|
printf "${C_FAIL}@RCDIR@/rc.conf says the RTC is in localtime, but hwclock (/etc/adjtime) thinks it is in UTC.\n${C_OTHER}."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $HARDWARECLOCK in
|
||||||
|
UTC) HWCLOCK_PARAMS+=" --utc --noadjfile";;
|
||||||
|
localtime) HWCLOCK_PARAMS+=" --localtime --noadjfile";;
|
||||||
|
*) HWCLOCK_PARAMS="";;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $HWCLOCK_PARAMS ]]; then
|
||||||
|
stat_busy "Adjusting system time and setting kernel time zone"
|
||||||
|
|
||||||
|
# Adjust the system time for time zone offset if rtc is not in UTC, as
|
||||||
|
# filesystem checks can depend on system time. This also sets the kernel
|
||||||
|
# time zone, used by e.g. vfat.
|
||||||
|
|
||||||
|
hwclock $HWCLOCK_PARAMS && stat_done || stat_fail
|
||||||
|
|
||||||
|
unset TZ
|
||||||
|
fi
|
1
rc/sysinit.d/04-kmod-static-nodes.sh
Normal file
1
rc/sysinit.d/04-kmod-static-nodes.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
status "Creating list of required static device nodes" mk_kmod_static_nodes
|
1
rc/sysinit.d/05-tmpfiles-dev.sh
Normal file
1
rc/sysinit.d/05-tmpfiles-dev.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
status "Setting up tmpfiles.d entries for /dev" mk_tmpfiles_dev
|
2
rc/sysinit.d/06-udev-modprobe.sh
Normal file
2
rc/sysinit.d/06-udev-modprobe.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Start/trigger udev, load MODULES, and settle udev
|
||||||
|
udevd_modprobe sysinit
|
2
rc/sysinit.d/07-console-setup.sh
Normal file
2
rc/sysinit.d/07-console-setup.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# this must be done after udev has loaded the KMS modules
|
||||||
|
status 'Configuring virtual consoles' console_setup
|
2
rc/sysinit.d/08-net-lo.sh
Normal file
2
rc/sysinit.d/08-net-lo.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# bring up the loopback interface
|
||||||
|
[[ -d /sys/class/net/lo ]] && status "Bringing up loopback interface" ip link set up dev lo
|
3
rc/sysinit.d/09-dmraid.sh
Normal file
3
rc/sysinit.d/09-dmraid.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# FakeRAID devices detection
|
||||||
|
[[ $USEDMRAID = [Yy][Ee][Ss] && -x $(type -P dmraid) ]] &&
|
||||||
|
status "Activating FakeRAID arrays" dmraid -i -ay
|
2
rc/sysinit.d/10-lvm2.sh
Normal file
2
rc/sysinit.d/10-lvm2.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Activate LVM2 groups, if any
|
||||||
|
activate_vgs
|
6
rc/sysinit.d/11-cryptsetup.sh
Normal file
6
rc/sysinit.d/11-cryptsetup.sh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Set up non-root encrypted partition mappings
|
||||||
|
if [[ -f /etc/crypttab ]] && type -p cryptsetup >/dev/null; then
|
||||||
|
status "Activating encrypted devices" awk -f /etc/rc/crypt.awk /etc/crypttab
|
||||||
|
# Maybe someone has LVM on an encrypted block device
|
||||||
|
activate_vgs
|
||||||
|
fi
|
13
rc/sysinit.d/12-fsck.sh
Normal file
13
rc/sysinit.d/12-fsck.sh
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
run_hook sysinit_prefsck
|
||||||
|
if [[ -x $(type -P fsck) ]]; then
|
||||||
|
stat_busy "Checking filesystems"
|
||||||
|
fsck_all >|"${FSCK_OUT:-/dev/stdout}" 2>|"${FSCK_ERR:-/dev/stdout}"
|
||||||
|
declare -r fsckret=$?
|
||||||
|
(( fsckret <= 1 )) && stat_done || stat_fail
|
||||||
|
else
|
||||||
|
declare -r fsckret=0
|
||||||
|
fi
|
||||||
|
# Single-user login and/or automatic reboot if needed
|
||||||
|
run_hook sysinit_postfsck
|
||||||
|
|
||||||
|
fsck_reboot $fsckret
|
2
rc/sysinit.d/13-remount-api-fs.sh
Normal file
2
rc/sysinit.d/13-remount-api-fs.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
status "Remounting root and API filesystems" \
|
||||||
|
mount -o remount,rw /
|
4
rc/sysinit.d/14-mount-local-fs.sh
Normal file
4
rc/sysinit.d/14-mount-local-fs.sh
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
run_hook sysinit_premount
|
||||||
|
status "Mounting local filesystems" \
|
||||||
|
mount_all
|
||||||
|
run_hook sysinit_postmount
|
4
rc/sysinit.d/15-lvm2-monitoring.sh
Normal file
4
rc/sysinit.d/15-lvm2-monitoring.sh
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Enable monitoring of LVM2 groups, now that the filesystems are mounted rw
|
||||||
|
[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] &&
|
||||||
|
status "Activating monitoring of LVM2 groups" \
|
||||||
|
vgchange --monitor y >/dev/null
|
1
rc/sysinit.d/16-swap.sh
Normal file
1
rc/sysinit.d/16-swap.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
status "Activating swap" swapon -a
|
1
rc/sysinit.d/17-timezone.sh
Normal file
1
rc/sysinit.d/17-timezone.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[[ $TIMEZONE ]] && status "Configuring time zone" set_timezone "$TIMEZONE"
|
1
rc/sysinit.d/18-random-seed.sh
Normal file
1
rc/sysinit.d/18-random-seed.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
status 'Initializing random seed' init_random_seed
|
1
rc/sysinit.d/19-tmpfiles-setup.sh
Normal file
1
rc/sysinit.d/19-tmpfiles-setup.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
status "Setting up tmpfiles.d entries" mk_tmpfiles_setup
|
1
rc/sysinit.d/20-sysusers.sh
Normal file
1
rc/sysinit.d/20-sysusers.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
status "Setting up sysusers.d entries" mk_sysusers
|
8
rc/sysinit.d/21-dmesg-log.sh
Normal file
8
rc/sysinit.d/21-dmesg-log.sh
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
stat_busy "Saving dmesg log"
|
||||||
|
if [[ -e /proc/sys/kernel/dmesg_restrict ]] &&
|
||||||
|
(( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then
|
||||||
|
install -Tm 0600 <( dmesg ) /var/log/dmesg.log
|
||||||
|
else
|
||||||
|
install -Tm 0644 <( dmesg ) /var/log/dmesg.log
|
||||||
|
fi
|
||||||
|
(( $? == 0 )) && stat_done || stat_fail
|
73
shutdown.in
Executable file
73
shutdown.in
Executable file
@@ -0,0 +1,73 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# shutdown - shutdown(8) lookalike for runit
|
||||||
|
|
||||||
|
single() {
|
||||||
|
runsvchdir single
|
||||||
|
}
|
||||||
|
|
||||||
|
abort() {
|
||||||
|
printf '%s\n' "$1" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
abort "Usage: ${0##*/} [-fF] [-kchPr] time [warning message]"
|
||||||
|
}
|
||||||
|
|
||||||
|
action=single
|
||||||
|
|
||||||
|
while getopts akrhPHfFnct: opt; do
|
||||||
|
case "$opt" in
|
||||||
|
a|n|H) abort "'-$opt' is not implemented";;
|
||||||
|
t) ;;
|
||||||
|
f) touch /fastboot;;
|
||||||
|
F) touch /forcefsck;;
|
||||||
|
k) action=true;;
|
||||||
|
c) action=cancel;;
|
||||||
|
h|P) action=halt;;
|
||||||
|
r) action=reboot;;
|
||||||
|
[?]) usage;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
|
[ $# -eq 0 ] && usage
|
||||||
|
|
||||||
|
time=$1; shift
|
||||||
|
message="${*:-system is going down}"
|
||||||
|
|
||||||
|
if [ "$action" = "cancel" ]; then
|
||||||
|
kill "$(cat @RUNDIR@/shutdown.pid)"
|
||||||
|
if [ -e /etc/nologin ] && ! [ -s /etc/nologin ]; then
|
||||||
|
rm /etc/nologin
|
||||||
|
fi
|
||||||
|
echo "${*:-shutdown cancelled}" | wall
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
touch @RUNDIR@/shutdown.pid 2>/dev/null || abort "Not enough permissions to execute ${0#*/}"
|
||||||
|
echo $$ >@RUNDIR@/shutdown.pid
|
||||||
|
|
||||||
|
case "$time" in
|
||||||
|
now) time=0;;
|
||||||
|
+*) time=${time#+};;
|
||||||
|
*:*) abort "absolute time is not implemented";;
|
||||||
|
*) abort "invalid time";;
|
||||||
|
esac
|
||||||
|
|
||||||
|
for break in 5 0; do
|
||||||
|
[ "$time" -gt "$break" ] || continue
|
||||||
|
[ "$break" = 0 ] && touch /etc/nologin
|
||||||
|
|
||||||
|
printf '%s in %s minutes\n' "$message" "$time" | wall
|
||||||
|
printf 'shutdown: sleeping for %s minutes... ' "$(( time - break ))"
|
||||||
|
sleep $(( (time - break) * 60 ))
|
||||||
|
time="$break"
|
||||||
|
printf '\n'
|
||||||
|
|
||||||
|
[ "$break" = 0 ] && rm /etc/nologin
|
||||||
|
done
|
||||||
|
|
||||||
|
printf '%s NOW\n' "$message" | wall
|
||||||
|
|
||||||
|
$action
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user