14 Commits

Author SHA1 Message Date
nikolar
e0c4e306e4 Add binfmt.d from artix-cgroups 2024-04-30 16:33:05 +02:00
nikolar
69fa6e4394 Migrate to artix-cgroups 2024-04-30 16:32:55 +02:00
Nikola
2530c4aadd Change default for cgroups to unified (cgroups2). 2024-04-15 11:46:36 +02:00
Qontinuum
5d00408a16 Edit procfs.in
Make procfs respect options in fstab
Remove nosuid,noexec,nodev mount options since they are not support by
procfs anyway
2023-11-01 14:08:58 +01:00
Qontinuum
26fa40633d Move to new Artix sysusers/tmpfiles binary names 2023-08-18 18:51:47 +02:00
fab1c43983 add /tmp cleanup 2021-05-14 11:48:42 +07:00
9f6718f5de hwclock: read from rc.conf 2021-01-22 08:46:50 +07:00
c0c2ab41a8 devfs: add symlinks and needed files if not exist yet 2020-09-15 11:01:24 +07:00
4be15079e2 binfmt: add an option to run it once without adding it to running daemons 2020-08-25 07:55:32 +07:00
Martin Castillo
2314c2630f udev.in: stop: only try to stop udevd when it's running
Since udevd is now started again in stage 2 and stopped by
runsvdir on shutdown, we only try to stop it with udevadm,
if there is an instance running.  This might be the case if
something went wrong and stage 2 couldn't start udevd for some
reason, so the instance from stage 1 wasn't terminated.

When starting udevd in stage 1, runsvdir isn't running yet, so
there is no need to check for already running instances.
2020-04-04 14:50:39 +07:00
Martin Castillo
38c52b18dc binfmt.in: fix grep invocation
If any directory has more than one file, grep prefixes matching lines with
the filenames. -h suppresses that.
2020-03-09 07:56:55 +07:00
cbbed45ce3 fix hwclock command 2019-11-06 19:46:41 +07:00
667dee6b9c fix hwclock 2019-11-06 09:18:56 +07:00
dudemanguy
451fe75e69 use "-T linux" if $TERM is dumb or empty 2019-09-13 11:50:13 +07:00
69 changed files with 1268 additions and 1203 deletions

189
Makefile
View File

@@ -6,45 +6,86 @@ LIBDIR = $(PREFIX)/lib
RCDIR = $(SYSCONFDIR)/rc
RCLIBDIR = $(LIBDIR)/rc
RCSVDIR = /usr/share/rc/sv.d
RCENABLEDDIR = /etc/rc/sv.d
RCSVDIR = $(RCLIBDIR)/sv.d
RCRUNDIR = /run/sv.d
RUNITDIR = /etc/runit
RUNITRUNDIR = /run/runit
RCBIN = \
script/modules-load \
script/service
script/rc-sysinit \
script/rc-shutdown \
script/rc-sv \
script/modules-load
RCSTAGE1 = \
stage1/00-pseudofs \
stage1/01-cgroups \
stage1/01-static-devnodes \
stage1/02-modules \
stage1/02-udev \
stage1/03-console-setup \
stage1/03-hwclock \
stage1/04-rootfs \
stage1/05-btrfs \
stage1/06-fsck \
stage1/07-mountfs \
stage1/08-misc \
stage1/11-sysctl \
stage1/99-cleanup
RCSVD = \
sv.d/root \
sv.d/binfmt \
sv.d/binfmt.d \
sv.d/bootlogd \
sv.d/cleanup \
sv.d/console-setup \
sv.d/dmesg \
sv.d/hostname \
sv.d/hwclock \
sv.d/kmod-static-nodes \
sv.d/misc \
sv.d/mount-all \
sv.d/net-lo \
sv.d/random-seed \
sv.d/remount-root \
sv.d/swap \
sv.d/sysctl \
sv.d/sysusers \
sv.d/tmpfiles-dev \
sv.d/tmpfiles-setup \
sv.d/udev \
sv.d/udev-trigger \
sv.d/udev-settle \
sv.d/modules \
sv.d/sysfs \
sv.d/devfs \
sv.d/procfs \
sv.d/cgroups
RCLVM1 = stage1/05-lvm
# SYSINIT = \
# 01-sysfs \
# 02-procfs \
# 03-devfs \
# 04-cgroups \
# 05-root \
# 10-hostname \
# 15-hwclock \
# 20-kmod-static-nodes \
# 25-tmpfiles-dev \
# 30-udev \
# 31-udev-trigger \
# 32-modules \
# 33-udev-settle \
# 40-console-setup \
# 45-net-lo \
# 50-misc \
# 55-remount-root \
# 60-mount-all \
# 65-swap \
# 70-random-seed \
# 75-tmpfiles-setup \
# 80-sysusers \
# 85-dmesg \
# 90-sysctl \
# 95-binfmt \
# 99-cleanup
#
# SHUTDWON = \
# 10-random-seed \
# 20-cleanup \
# 30-udev \
# 40-misc \
# 50-swap \
# 60-root \
# 70-remount-root
RCLVM3 = stage3/40-lvm
RCCRYPT1 = stage1/06-cryptsetup
RCCRYPT3 = stage3/50-cryptsetup
RCSTAGE3 = \
stage3/10-misc \
stage3/30-killall \
stage3/40-filesystem \
stage3/99-remount-root
# sv.d/timezone \
# sv.d/lvm-monitoring \
# sv.d/lvm \
# sv.d/cryptsetup
CONF = script/rc.conf
@@ -61,10 +102,7 @@ EDIT = sed \
-e "s|@RCDIR[@]|$(RCDIR)|g" \
-e "s|@RCLIBDIR[@]|$(RCLIBDIR)|g" \
-e "s|@RCSVDIR[@]|$(RCSVDIR)|g" \
-e "s|@RUNITDIR[@]|$(RUNITDIR)|g" \
-e "s|@RUNITRUNDIR[@]|$(RUNITRUNDIR)|g" \
-e "s|@RCRUNDIR[@]|$(RCRUNDIR)|g" \
-e "s|@RCENABLEDDIR[@]|$(RCENABLEDDIR)|g"
-e "s|@RCRUNDIR[@]|$(RCRUNDIR)|g"
%: %.in Makefile
@echo "GEN $@"
@@ -75,7 +113,7 @@ EDIT = sed \
all: all-rc
all-rc: $(RCBIN) $(RCSTAGE1) $(RCSTAGE3) $(RCCRYPT1) $(RCCRYPT3) $(RCLVM1) $(RCLVM3) $(RCFUNC) $(CONF)
all-rc: $(RCBIN) $(RCSVD) $(RCFUNC) $(CONF)
install-rc:
@@ -91,48 +129,55 @@ install-rc:
install -d $(DESTDIR)$(RCSVDIR)
install -m755 $(RCSVD) $(DESTDIR)$(RCSVDIR)
install -d $(DESTDIR)$(RCENABLEDDIR)
install -d $(DESTDIR)$(RCDIR)/sysinit
install -d $(DESTDIR)$(RCLIBDIR)/stage1
install -m755 $(RCSTAGE1) $(DESTDIR)$(RCLIBDIR)/stage1/
$(LN) $(RCSVDIR)/sysfs $(DESTDIR)$(RCDIR)/sysinit/01-sysfs
$(LN) $(RCSVDIR)/procfs $(DESTDIR)$(RCDIR)/sysinit/02-procfs
$(LN) $(RCSVDIR)/devfs $(DESTDIR)$(RCDIR)/sysinit/03-devfs
$(LN) $(RCSVDIR)/cgroups $(DESTDIR)$(RCDIR)/sysinit/04-cgroups
$(LN) $(RCSVDIR)/root $(DESTDIR)$(RCDIR)/sysinit/05-root
$(LN) $(RCSVDIR)/hostname $(DESTDIR)$(RCDIR)/sysinit/10-hostname
$(LN) $(RCSVDIR)/hwclock $(DESTDIR)$(RCDIR)/sysinit/15-hwclock
$(LN) $(RCSVDIR)/kmod-static-nodes $(DESTDIR)$(RCDIR)/sysinit/20-kmod-static-nodes
$(LN) $(RCSVDIR)/tmpfiles-dev $(DESTDIR)$(RCDIR)/sysinit/25-tmpfiles-dev
$(LN) $(RCSVDIR)/udev $(DESTDIR)$(RCDIR)/sysinit/30-udev
$(LN) $(RCSVDIR)/udev-trigger $(DESTDIR)$(RCDIR)/sysinit/31-udev-trigger
$(LN) $(RCSVDIR)/modules $(DESTDIR)$(RCDIR)/sysinit/32-modules
$(LN) $(RCSVDIR)/udev-settle $(DESTDIR)$(RCDIR)/sysinit/33-udev-settle
$(LN) $(RCSVDIR)/console-setup $(DESTDIR)$(RCDIR)/sysinit/40-console-setup
$(LN) $(RCSVDIR)/net-lo $(DESTDIR)$(RCDIR)/sysinit/45-net-lo
$(LN) $(RCSVDIR)/misc $(DESTDIR)$(RCDIR)/sysinit/50-misc
$(LN) $(RCSVDIR)/remount-root $(DESTDIR)$(RCDIR)/sysinit/55-remount-root
$(LN) $(RCSVDIR)/mount-all $(DESTDIR)$(RCDIR)/sysinit/60-mount-all
$(LN) $(RCSVDIR)/swap $(DESTDIR)$(RCDIR)/sysinit/65-swap
$(LN) $(RCSVDIR)/random-seed $(DESTDIR)$(RCDIR)/sysinit/70-random-seed
$(LN) $(RCSVDIR)/tmpfiles-setup $(DESTDIR)$(RCDIR)/sysinit/75-tmpfiles-setup
$(LN) $(RCSVDIR)/sysusers $(DESTDIR)$(RCDIR)/sysinit/80-sysusers
$(LN) $(RCSVDIR)/dmesg $(DESTDIR)$(RCDIR)/sysinit/85-dmesg
$(LN) $(RCSVDIR)/sysctl $(DESTDIR)$(RCDIR)/sysinit/90-sysctl
$(LN) $(RCSVDIR)/binfmt $(DESTDIR)$(RCDIR)/sysinit/95-binfmt
$(LN) $(RCSVDIR)/binfmt.d $(DESTDIR)$(RCDIR)/sysinit/97-binfmt.d
$(LN) $(RCSVDIR)/cleanup $(DESTDIR)$(RCDIR)/sysinit/99-cleanup
install -d $(DESTDIR)$(RCLIBDIR)/stage3/
install -m755 $(RCSTAGE3) $(DESTDIR)$(RCLIBDIR)/stage3/
install -d $(DESTDIR)$(RCDIR)/shutdown
$(LN) $(RCSVDIR)/random-seed $(DESTDIR)$(RCDIR)/shutdown/10-random-seed
$(LN) $(RCSVDIR)/cleanup $(DESTDIR)$(RCDIR)/shutdown/20-cleanup
$(LN) $(RCSVDIR)/udev $(DESTDIR)$(RCDIR)/shutdown/30-udev
$(LN) $(RCSVDIR)/hwclock $(DESTDIR)$(RCDIR)/shutdown/35-hwclock
$(LN) $(RCSVDIR)/misc $(DESTDIR)$(RCDIR)/shutdown/40-misc
$(LN) $(RCSVDIR)/swap $(DESTDIR)$(RCDIR)/shutdown/50-swap
$(LN) $(RCSVDIR)/root $(DESTDIR)$(RCDIR)/shutdown/60-root
$(LN) $(RCSVDIR)/remount-root $(DESTDIR)$(RCDIR)/shutdown/70-remount-root
install -d $(DESTDIR)$(MANDIR)/man8
install -m644 man/modules-load.8 $(DESTDIR)$(MANDIR)/man8
install -m644 man/service.8 $(DESTDIR)$(MANDIR)/man8
install-lvm:
install -d $(DESTDIR)$(RCLIBDIR)/stage1
install -m755 $(RCCRYPT1) $(DESTDIR)$(RCLIBDIR)/stage1/
install -d $(DESTDIR)$(RCLIBDIR)/stage3/
install -m755 $(RCCRYPT3) $(DESTDIR)$(RCLIBDIR)/stage3/
install-crypt:
install -d $(DESTDIR)$(RCLIBDIR)/stage1
install -m755 $(RCCRYPT1) $(DESTDIR)$(RCLIBDIR)/stage1/
install -d $(DESTDIR)$(RCLIBDIR)/stage3/
install -m755 $(RCCRYPT3) $(DESTDIR)$(RCLIBDIR)/stage3/
install-services:
install -d $(DESTDIR)$(RCSVDIR)/binfmt
install -m755 sv.d/binfmt/up $(DESTDIR)$(RCSVDIR)/binfmt
install -m755 sv.d/binfmt/down $(DESTDIR)$(RCSVDIR)/binfmt
install -d $(DESTDIR)$(RCSVDIR)/netmount
install -m755 sv.d/netmount/up $(DESTDIR)$(RCSVDIR)/netmount
install -m755 sv.d/netmount/down $(DESTDIR)$(RCSVDIR)/netmount
install -d $(DESTDIR)$(RCSVDIR)/staticnet
install -m755 sv.d/staticnet/up $(DESTDIR)$(RCSVDIR)/staticnet
install -m755 sv.d/staticnet/down $(DESTDIR)$(RCSVDIR)/staticnet
install -m644 script/modules-load.8 $(DESTDIR)$(MANDIR)/man8
install: install-rc
clean-rc:
-$(RM) $(RCBIN) $(RCSVD) $(RCSTAGE1) $(RCSTAGE3) $(RCCRYPT1) $(RCCRYPT3) $(RCLVM1) $(RCLVM3) $(RCFUNC) $(CONF)
-$(RM) $(RCBIN) $(RCSVD) $(RCFUNC) $(CONF)
clean: clean-rc
.PHONY: all install clean install-rc clean-rc all-rc install-lvm install-crypt
.PHONY: all install clean install-rc clean-rc all-rc

View File

@@ -1,9 +1,2 @@
# runit-rc
Artix Linux's implementation of stage 1, stage 3, and one-shot service
handling.
Contains 3 folders:
1. stage1: only executed during system startup by /etc/runit/1, should only contain essential files for startup
2. stage3: only executed during system shutdown by /etc/runit/3, should only contain essential files during shutdown
3. sv.d: executed during stage 2, user-modifiable. static network, netfs mount, binfmt, etc. can be put here, all new one-shot services will also be put here
Artix system initialization and shutdown for runit

View File

@@ -1,103 +0,0 @@
.TH "SERVICE" "8" "April 2019" "Artix Linux" "service"
.
.SH "NAME"
\fBservice\fR \- control and manages services in Artix
.
.SH "SYNOPSIS"
\fBservice <command> \.\.\.\fR
.
.SH "DESCRIPTION"
The \fBservice\fR program reports the current status and control the state of runsv(8) services and one\-shot services\.
.
.P
\fBcommand\fR is one of up, down, status, once, pause, cont, hup, alarm, interrupt, 1, 2, term, kill, or exit, or start, stop, restart, shutdown, force\-stop, force\-reload, force\-restart, force\-sutdown\.
.
.SH "COMMANDS"
.
.TP
\fBlist [runit|rc]\fR
List all runit and rc services\.
.
.TP
\fBenable [servicename]\fR
Immediately start the runit or oneshot service, and start them on boot\.
.
.TP
\fBdisable [servicename]\fR
Immediately stop the runit or oneshot service, and don\'t start them on boot\.
.
.P
Commands below are restricted to runit(8) services only:
.
.TP
\fBstatus\fR
Report the current status of the service, and the appendant log service if available, to standard output\.
.
.TP
\fBup\fR
If the service is not running, start it\. If the service stops, restart it\.
.
.TP
\fBdown\fR
If the service is running, send it the TERM signal, and the CONT signal\. If \./run exits, start \./finish if it exists\. After it stops, do not restart service\.
.
.TP
\fBonce\fR
If the service is not runing, start it\. Do not restart it if it stops\.
.
.TP
\fBexit\fR
If the service is running, send it the TERM signal, and the CONT signal\. Do not restart the service\. If the service is down, and no log service exists, runsv(8) exits\.
.
.P
Commands below apply to both runit(8) services and rc oneshot services:
.
.TP
\fBstatus\fR
Same as above\.
.
.TP
\fBstart\fR
Same as \fBup\fR, but wait up to 7 seconds for the command to take effect\. Then report the status or timeout\. If the script \fB\./check\fR exists in the directory, \fBservice\fR runs this script to check whether the service is up and available; it is considered to be available if \fB\./check\fR exits with 0\. For rc oneshot services, commands in \fBstart()\fR (and it\'s pre\- and post\- commands) will be executed immediately\.
.
.TP
\fBstop\fR
Same as \fBdown\fR, but wait up to 7 seconds for the command to take effect\. Then report the status or timeout\. For rc oneshot services, commands in \fBstop()\fR (and it\'s pre\- and post\- commands) will be executed immediately\.
.
.TP
\fBreload\fR
Same as \fBhup\fR, and additionally report the status afterwards\. For rc oneshot services, the service will be stopped and started\.
.
.P
Commands below are restricted to runit(8) services only:
.
.TP
\fBrestart\fR
Send the commands \fBterm\fR, \fBcont\fR, and \fBup\fR to the service, and wait up to 7 seconds for the service to restart\. Then report the status or timeout\. If the script \fB\./check\fR exists in the directory, \fBservice\fR runs this script to check whether the service is up and available again; it is considered to be available if \fB\./check\fR exits with 0\.
.
.TP
\fBshutdown\fR
Same as \fBexit\fR, but wait up to 7 seconds for the runsv(8) process to terminate\. Then report the status or timeout\.
.
.TP
\fBforce\-stop\fR
Same as \fBdown\fR, but wait up to 7 seconds for the service to become down\. Then report the status, and on timeout send the service the \fBkill\fR command\.
.
.TP
\fBforce\-reload\fR
Send the service the \fBterm\fR and \fBcont\fR commands, and wait up to 7 seconds for the service to restart\. Then report the status, and on timeout send the service the \fBkill\fR command\.
.
.TP
\fBforce\-restart\fR
Send the service the \fBterm\fR, \fBcont\fR and \fBup\fR commands, and wait up to 7 seconds for the service to restart\. Then report the status, and on timeout send the service the \fBkill\fR command\. If the script \fB\./check\fR exists in the service directory, \fBservice\fR runs this script to check whether the service is up and available again; its considered to be available if \fB\./check\fR exits with 0\.
.
.TP
\fBforce\-shutdown\fR
Same as \fBexit\fR, but wait up to 7 seconds for the runsv(8) process to terminate\. Then report the status, and on timeout send the service the \fBkill\fR command\.
.
.TP
\fBtry\-restart\fR
if the service is running, send it the \fBterm\fR and \fBcont\fR commands, and wait up to 7 seconds for the service to restart\. Then report the status or timeout\.
.
.SH "SEE ALSO"
sv(8), runsv(8), runit(8)

View File

@@ -1,18 +1,18 @@
#!/bin/bash
# This is run by the kernel after the last task is removed from a
# control group in the openrc hierarchy.
# control group in the artix hierarchy.
# Copyright (c) 2007-2015 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
# https://github.com/OpenRC/artix/blob/master/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
# distribution and at https://github.com/OpenRC/artix/blob/master/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
cgroup=/sys/fs/cgroup/openrc
cgroup=/sys/fs/cgroup/artix
PATH=/bin:/usr/bin:/sbin:/usr/sbin
if [ -d ${cgroup}/"$1" ]; then
rmdir ${cgroup}/"$1"

View File

@@ -41,444 +41,6 @@ calc_columns () {
fi
}
runit_sv_available()
{
[[ -d @RUNITDIR@/sv/$1 ]]
}
runit_sv_enabled()
{
[[ -h @RUNITRUNDIR@/service/"$1" ]]
}
rc_sv_available()
{
[[ -x @RCSVDIR@/"$1" ]]
}
rc_sv_enabled()
{
[[ -h @RCENABLEDDIR@/"$1" ]]
}
rc_sv_up()
{
[[ -f @RCRUNDIR@/active/$1 ]]
}
ck_service()
{
if runit_sv_enabled "$1"; then
runit_sv_up "$1"
else
rc_sv_up "$1"
fi
}
ck_status()
{
if runit_sv_enabled "$1"; then
if runit_sv_up "$1"; then
msg_ok "$1: up, pid: $(cat @RUNITRUNDIR@/service/$1/supervise/pid)"
else
msg_error "$1: down"
fi
elif rc_sv_enabled "$1"; then
if rc_sv_up "$1"; then
msg_ok "$1: rc service up"
else
msg_ok "$1: rc service down"
fi
elif runit_sv_available "$1"; then
msg_error "$1: runit service is not enabled"
elif rc_sv_available "$1"; then
msg_error "$1: rc service is not enabled"
else
msg_error "$1 is not an existing runit or rc service"
fi
}
service_status()
{
if ck_service "$1"; then
STATUS="${C_DONE} up "
else
STATUS="${C_FAIL}down"
fi
if runit_sv_enabled "$1"; then
ENABLED_STATUS="${C_MAIN}*"
elif rc_sv_enabled "$1"; then
ENABLED_STATUS="${C_MAIN}*"
else
ENABLED_STATUS=" "
fi
printf "${C_OTHER}[$STATUS${C_OTHER}]${C_CLEAR} ${C_OTHER}[$ENABLED_STATUS${C_OTHER}]${C_CLEAR} $1 \n"
}
runit_sv_up()
{
runit_sv_enabled "$1" && [[ "$(cat @RUNITRUNDIR@/service/$1/supervise/stat 2>/dev/null)" == "run" ]] && [[ -s @RUNITRUNDIR@/service/$1/supervise/pid ]]
}
enable_runit_sv()
{
ln -sf @RUNITDIR@/sv/"$1" @RUNITRUNDIR@/service/
# this will make sure the service is enabled if ./down exists
runit_send_signal "u" "$1"
ck_status "$1"
}
disable_runit_sv()
{
rm -f @RUNITRUNDIR@/service/"$1"
msg_ok "$1: disabled"
}
enable_rc_sv()
{
ln -sf @RCSVDIR@/"$1" @RCENABLEDDIR@/
@RCENABLEDDIR@/"$1"/up
[[ $? == 0 ]] && add_daemon "$1"
}
disable_rc_sv()
{
[ -x @RCENABLEDDIR@/"$1"/down ] && @RCENABLEDDIR@/"$1"/down
rm -f @RCENABLEDDIR@/"$1"
[[ $? == 0 ]] && rm_daemon "$1"
}
list_rc_services() {
echo "rc services: "
cd @RCSVDIR@ || msg_error "error!"
for d in *; do
have_service "$d" && daemons+=("$d")
service_status "$d"
done
}
list_runit_services() {
echo "runit services: "
cd @RUNITDIR@/sv || return
for daemon in *; do
service_status "$daemon"
done
}
runit_send_signal() {
if runit_sv_enabled "$2"; then
for i in {1..7}; do
sleep 0.1
if [[ -e @RUNITRUNDIR@/service/$2/supervise/control ]]; then
printf "%s" "$1" > "@RUNITRUNDIR@/service/$2/supervise/control"
break
else
sleep 1
fi
done
else
ck_status "$2"
return 100
fi
}
have_service()
{
[[ -x @RCSVDIR@/$1 ]]
}
### Long functions to be run in stages
# 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
emergency_shell
fi
echo "Automatic reboot in progress..."
umount -a
mount -o remount,ro /
reboot -f
exit 0
}
do_fsck(){
if [[ -x $(type -P fsck) ]]; then
fsck_all >|"${FSCK_OUT:-/dev/stdout}" 2>|"${FSCK_ERR:-/dev/stdout}"
declare -r fsckret=$?
else
declare -r fsckret=0
fi
fsck_reboot $fsckret
}
CGROUP_OPTS=nodev,noexec,nosuid
HAVE_CONTROLLER1_GROUPS=${HAVE_CONTROLLER1_GROUPS:-true}
CGROUP_MODE=${CGROUP_MODE:-hybrid}
CGROUP_CONTROLLERS=""
cgroup2_find_path(){
if grep -qw cgroup2 /proc/filesystems; then
case "${CGROUP_MODE}" in
hybrid) printf "/sys/fs/cgroup/unified" ;;
unified) printf "/sys/fs/cgroup" ;;
esac
fi
return 0
}
cgroup1_base(){
grep -qw cgroup /proc/filesystems || return 0
if ! mountpoint -q /sys/fs/cgroup; then
local opts="${CGROUP_OPTS},mode=755,size=${rc_cgroupsize:-10m}"
mount -n -t tmpfs -o "${opts}" cgroup_root /sys/fs/cgroup
fi
if ! mountpoint -q /sys/fs/cgroup/openrc; then
local agent="@RCLIBDIR@/cgroup-release-agent"
mkdir /sys/fs/cgroup/openrc
mount -n -t cgroup -o none,${CGROUP_OPTS},name=openrc,release_agent="$agent" openrc /sys/fs/cgroup/openrc
printf 1 > /sys/fs/cgroup/openrc/notify_on_release
fi
return 0
}
cgroup1_controllers(){
${HAVE_CONTROLLER1_GROUPS} && [ -e /proc/cgroups ] && grep -qw cgroup /proc/filesystems || return 0
while read -r name _ _ enabled _; do
case "${enabled}" in
1) if mountpoint -q "/sys/fs/cgroup/${name}";then continue;fi
local x
for x in $CGROUP_CONTROLLERS; do
[ "${name}" = "blkio" ] && [ "${x}" = "io" ] &&
continue 2
[ "${name}" = "${x}" ] &&
continue 2
done
mkdir "/sys/fs/cgroup/${name}"
mount -n -t cgroup -o "${CGROUP_OPTS},${name}" "${name}" "/sys/fs/cgroup/${name}"
;;
esac
done < /proc/cgroups
return 0
}
cgroup2_base(){
grep -qw cgroup2 /proc/filesystems || return 0
local base
base="$(cgroup2_find_path)"
mkdir -p "${base}"
mount -t cgroup2 none -o "${CGROUP_OPTS},nsdelegate" "${base}" 2> /dev/null ||
mount -t cgroup2 none -o "${CGROUP_OPTS}" "${base}"
return 0
}
cgroup2_controllers(){
grep -qw cgroup2 /proc/filesystems || return 0
local active cgroup_path x y
cgroup_path="$(cgroup2_find_path)"
[ -z "${cgroup_path}" ] && return 0
[ -e "${cgroup_path}/cgroup.controllers" ] && read -r active < "${cgroup_path}/cgroup.controllers"
for x in ${CGROUP_CONTROLLERS}; do
for y in ${active}; do
[ "$x" = "$y" ] && [ -e "${cgroup_path}/cgroup.subtree_control" ] &&
echo "+${x}" > "${cgroup_path}/cgroup.subtree_control"
done
done
return 0
}
cgroups_hybrid(){
cgroup1_base
cgroup2_base
cgroup2_controllers
cgroup1_controllers
return 0
}
cgroups_legacy(){
cgroup1_base
cgroup1_controllers
return 0
}
cgroups_unified(){
cgroup2_base
cgroup2_controllers
return 0
}
mount_cgroups(){
case "${CGROUP_MODE}" in
hybrid) cgroups_hybrid ;;
legacy) cgroups_legacy ;;
unified) cgroups_unified ;;
esac
return 0
}
mount_cgs(){
if [ -d /sys/fs/cgroup ]; then
mount_cgroups
return 0
fi
}
do_unlock_device() {
# $1 = requested name
# $2 = source device
# $3 = password
# $4 = options
local open=create a=$1 b=$2 failed=0 opts
# 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
else
printhl "Non-LUKS partitions are not supported at the moment."
continue
fi
if [[ $4 ]]; then
for i in ${4//,/ }; do
case $i in
"discard") opts+="--allow-discard" ;;
"readonly"|"read-only") opts+="--readonly" ;;
"tries"*) opts+="-T ${i##*=}" ;;
"keyfile-size"*) opts+="-l ${i##*=}" ;;
"keyfile-offset"*) opts+="--keyfile-offset ${i##*=}" ;;
"key-slot"*) opts+="-S ${i##*=}" ;;
"luks") ;;
*)
printhl "The option is not currently supported at the moment."
printhl "Please add an issue to https://github.com/artix-linux/runit-rc"
continue
;;
esac
done
fi
case $3 in
/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} $opts $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" $opts $open "$a" "$b" >/dev/null;;
"none" | "")
cryptsetup $opts $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_device "$name" "$device" "$password" "$options"
return $?
fi
do_unlock_device "$name" "$device" "$password" "$options"
failed=$?
if (( $failed )); then
printf "${C_FAIL}Unlocking of $1 failed.${C_CLEAR}\n"
fi
return $?
}
do_lock() {
#status "Detaching encrypted device ${1}"
cryptsetup luksClose "$1" >/dev/null
}
read_crypttab() {
# $1 = function to call with the split out line from the crypttab
local line nspo failed=0
while read line <&3; do
[[ $line && $line != '#'* ]] || continue
eval nspo=("${line%#*}")
if $1 "${nspo[0]}" "${nspo[1]}" "${nspo[2]}" "${nspo[*]:3}"; then
crypto_unlocked=1
else
failed=1
fi
done 3< /etc/crypttab
return $failed
}
### End
run_rc_command()
{
eval "$1"
}
emergency_shell()
{
msg_error "Cannot continue due to errors above, starting emergency shell."
msg "When ready, type exit or Control+D to continue booting."
sulogin -p
}
deltext() {
printf "${DEL_TEXT}"
}
@@ -491,29 +53,93 @@ printsep() {
printf "\n${C_SEPARATOR} ------------------------------\n"
}
msg() {
printf "${C_OTHER}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR}\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} "
}
msg_ok() {
printf "${C_DONE}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR}\n"
ck_daemon() {
[[ ! -f @RCRUNDIR@/started/$1 ]]
}
msg_warn() {
printf "${C_WARN}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR}\n"
}
msg_error() {
printf "${C_FAIL}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR}\n"
ck_failed() {
[[ ! -f @RCRUNDIR@/failed/$1 ]]
}
add_daemon() {
[[ -d @RCRUNDIR@/active ]] || mkdir -p @RCRUNDIR@/active
touch @RCRUNDIR@/active/"$1"
[[ -d @RCRUNDIR@/started ]] || mkdir -p @RCRUNDIR@/started
>| @RCRUNDIR@/started/"$1"
}
rm_daemon() {
rm -f @RCRUNDIR@/active/"$1"
rm -f @RCRUNDIR@/started/"$1"
}
add_failed() {
[[ -d @RCRUNDIR@/failed ]] || mkdir -p @RCRUNDIR@/failed
>| @RCRUNDIR@/failed/"$1"
}
rm_failed() {
rm -f @RCRUNDIR@/failed/"$1"
}
ck_status() {
if ! ck_daemon "$1"; then
stat_started
else
if ! ck_failed "$1"; then
stat_failed
else
stat_stopped
fi
fi
}
stat_done() {
if ! ck_failed "$1"; then
rm_failed "$1"
fi
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"
}
stat_die() {
if ck_failed "$1"; then
add_failed "$1"
fi
stat_fail
exit ${2:-1}
}
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 )
@@ -542,7 +168,7 @@ print_leave(){
# avoid staircase effect
stty onlcr
echo " "
printhl "Shutting down\n"
printhl "Initiating shutdown\n"
echo " "
}
@@ -551,45 +177,35 @@ run_sysinit(){
print_welcome
calc_columns
for stage1 in @RCLIBDIR@/stage1/*; do
[[ -x $stage1 && -r $stage1 ]] && . $stage1
for service in ${RC_SYSINIT[@]};do
@RCSVDIR@/"${service#*-}" start
done
}
run_shutdown(){
print_leave
for stage3 in @RCLIBDIR@/stage3/*; do
[[ -x $stage3 && -r $stage3 ]] && . $stage3
done
}
run_oneshot_services()
{
for files in @RCENABLEDDIR@/*; do
$files/up
done
}
stop_oneshot_services()
{
for files in @RCENABLEDDIR@/*; do
$files/down
for service in ${RC_SHUTDOWN[@]};do
@RCSVDIR@/"${service#*-}" stop
done
}
# if [[ $1 == "start" ]]; then
# if [[ $STARTING ]]; then
# echo "A daemon is starting another daemon; this is unlikely to work as intended."
# else
# export STARTING=1
# fi
# if [[ $STARTING ]]; then
# echo "A daemon is starting another daemon; this is unlikely to work as intended."
# else
# export STARTING=1
# fi
# fi
calc_columns
# disable colors on broken terminals
TERM_COLORS=$(tput colors 2>/dev/null)
if [[ -z "$TERM" || "$TERM" = "dumb" ]]; then
TERM_COLORS=$(tput colors -T linux 2>/dev/null)
else
TERM_COLORS=$(tput colors 2>/dev/null)
fi
if (( $? != 3 )); then
case $TERM_COLORS in
*[!0-9]*) USECOLOR="";;
@@ -612,10 +228,10 @@ if [[ $USECOLOR != [nN][oO] ]]; then
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_WARN=${C_MAIN}$(tput setaf 3) # warning
C_DONE=${C_MAIN}$(tput setaf 2) # completed
C_START=${C_MAIN}$(tput setaf 2) # started
C_FAIL=${C_MAIN}$(tput setaf 5) # failed
C_DONE=${C_MAIN} # completed
C_STOP=${C_MAIN}$(tput setaf 1) # backgrounded
C_START=${C_MAIN}$(tput setaf 2) # started
C_H1=${C_MAIN} # highlight text 1
C_H2=${C_MAIN}$(tput setaf 6) # highlight text 2
else
@@ -637,3 +253,6 @@ fi
PREFIX_REG="::"
PREFIX_HL=" >"
RC_SYSINIT=$(ls @RCDIR@/sysinit)
RC_SHUTDOWN=$(ls @RCDIR@/shutdown)

0
script/modules-load.in Normal file → Executable file
View File

View File

@@ -13,7 +13,7 @@
# "hybrid" mounts cgroups version 2 on /sys/fs/cgroup/unified and
# cgroups version 1 on /sys/fs/cgroup
# CGROUP_MODE="hybrid"
# CGROUP_MODE="unified"
# This is a list of controllers which should be enabled for cgroups version 2.
# If hybrid mode is being used, controllers listed here will not be
@@ -26,3 +26,9 @@
# /sys/fs/cgroup in hybrid or legacy mode
# HAVE_CONTROLLER1_GROUPS="true"
# This switch controls whether or not /tmp will be cleaned.
# /tmp will only be cleaned if it is set to "y". Generally it is recommended to
# mount /tmp as tmpfs.
# CLEANTMP="n"

View File

@@ -1,276 +0,0 @@
#!/bin/bash
# shellcheck disable=1091
. @RCLIBDIR@/functions
if [ $EUID != 0 ]; then
msg_error "You must run this program as root!"
exit 1
fi
case "$1" in
"list")
case "$2" in
"rc") list_rc_services ;;
"runit") list_runit_services ;;
"") list_rc_services; list_runit_services ;;
*) msg_error "$1: unknown parameters" ;;
esac
;;
"up") runit_send_signal "u" "$2" ;;
"down") runit_send_signal "d" "$2" ;;
"once") runit_send_signal "o" "$2" ;;
"exit") runit_send_signal "x" "$2" ;;
"pause") runit_send_signal "p" "$2" ;;
"cont") runit_send_signal "c" "$2" ;;
"hup") runit_send_signal "h" "$2" ;;
"alarm") runit_send_signal "a" "$2" ;;
"interrupt") runit_send_signal "i" "$2" ;;
"quit") runit_send_signal "q" "$2" ;;
"1") runit_send_signal "1" "$2" ;;
"2") runit_send_signal "2" "$2" ;;
"term") runit_send_signal "t" "$2" ;;
"kill") runit_send_signal "k" "$2" ;;
"status") ck_status "$2" ;;
"start")
if runit_sv_enabled "$2"; then
runit_send_signal "u" "$2"
for i in {1..7}; do
sleep 0.1
if runit_sv_up "$2"; then
if [[ -x @RUNITRUNDIR@/service/$2/check ]]; then
@RUNITRUNDIR@/service/"$2"/check
ret=$?
if (( ret == 0 )); then check_fail=0; break; else msg_warn "$2: timeout in $((8-i))"; sleep 1; check_fail=1; fi
else
break
fi
else
msg_warn "$2: timeout in $((8-i))"
sleep 1
fi
done
((check_fail > 0)) && msg_warn "$2: check failed!"
ck_status "$2"
((i == 7)) && exit 1 || exit 0
elif rc_sv_enabled "$2"; then
@RCENABLEDDIR@/"$2"/up
ret=$?
(( ret == 0 )) && add_daemon "$2"
fi
ck_status "$2"
;;
"stop")
if runit_sv_enabled "$2"; then
runit_send_signal "d" "$2"
for i in {1..7}; do
sleep 0.1
if ! runit_sv_up "$2"; then
break
else
msg_warn "$2: timeout in $((8-i))"
sleep 1
fi
done
ck_status "$2"
((i == 7)) && exit 1 || exit 0
elif rc_sv_enabled "$2"; then
[ -x @RCENABLEDDIR@/"$2"/down ] && @RCENABLEDDIR@/"$2"/down
(( ret == 0 )) && rm_daemon "$2"
fi
ck_status "$2"
;;
"reload")
if runit_sv_enabled "$2"; then
runit_send_signal "h" "$2"
elif rc_sv_enabled "$2"; then
[ -x @RCENABLEDDIR@/"$2"/down ] && @RCENABLEDDIR@/"$2"/down
sleep 1
@RCENABLEDDIR@/"$2"/up
fi
ck_status "$2"
;;
"restart")
if runit_sv_enabled "$2"; then
runit_send_signal "t" "$2"
runit_send_signal "c" "$2"
runit_send_signal "u" "$2"
for i in {1..7}; do
sleep 0.1
if runit_sv_up "$2"; then
if [[ -x @RUNITRUNDIR@/$2/check ]]; then
@RUNITRUNDIR@/"$2"/check
ret=$?
if (( ret == 0 )); then check_fail=0; break; else msg_warn "$2: timeout in $((8-i))"; sleep 1; check_fail=1; fi
else
break
fi
else
msg_warn "Timeout in $((8-i))"
sleep 1
fi
done
((check_fail > 0)) && msg_warn "$2: check failed!"
ck_status "$2"
((i == 7)) && exit 1 || exit 0
fi
ck_status "$2"
;;
"shutdown")
if runit_sv_enabled "$2"; then
runit_send_signal "x" "$2"
for i in {1..7}; do
sleep 0.1
if ! runit_sv_up "$2"; then
break
else
msg_warn "$2: timeout in $((8-i))"
sleep 1
fi
done
ck_status "$2"
((i == 7)) && exit 1 || exit 0
fi
ck_status "$2"
;;
"force-stop")
if runit_sv_enabled "$2"; then
runit_send_signal "d" "$2"
for i in {1..7}; do
sleep 0.1
if ! runit_sv_up "$2"; then
break
else
msg_warn "$2: timeout in $((8-i))"
sleep 1
fi
done
ck_status "$2"
((i == 7)) && runit_send_signal "k" "$2" || exit 0
fi
ck_status "$2"
;;
"force-reload")
if runit_sv_enabled "$2"; then
runit_send_signal "t" "$2"
runit_send_signal "c" "$2"
for i in {1..7}; do
sleep 0.1
if runit_sv_up "$2"; then
break
else
msg_warn "$2: timeout in $((8-i))"
sleep 1
fi
done
ck_status "$2"
((i == 7)) && runit_send_signal "k" "$2" || exit 0
fi
ck_status "$2"
;;
"force-restart")
if runit_sv_enabled "$2"; then
runit_send_signal "t" "$2"
runit_send_signal "c" "$2"
runit_send_signal "u" "$2"
for i in {1..7}; do
sleep 0.1
if runit_sv_up "$2"; then
if [[ -x @RUNITRUNDIR@/$2/check ]]; then
@RUNITRUNDIR@/"$2"/check
ret=$?
if (( ret == 0 )); then check_fail=0; break; else msg_warn "$2: timeout in $((8-i))"; sleep 1; check_fail=1; fi
else
break
fi
else
msg_warn "$2: timeout in $((8-i))"
sleep 1
fi
done
((check_fail > 0)) && msg_warn "$2: check failed!"
ck_status "$2"
((i == 7)) && runit_send_signal "k" "$2" || exit 0
fi
ck_status "$2"
;;
"force-shutdown")
if runit_sv_enabled "$2"; then
runit_send_signal "x" "$2"
for i in {1..7}; do
sleep 0.1
if ! runit_sv_up "$2"; then
break
else
msg_warn "$2: timeout in $((8-i))"
sleep 1
fi
done
ck_status "$2"
((i == 7)) && runit_send_signal "k" "$2" || exit 0
fi
ck_status "$2"
;;
"try-restart")
if runit_sv_enabled "$2"; then
runit_send_signal "t" "$2"
runit_send_signal "c" "$2"
for i in {1..7}; do
sleep 0.1
if runit_sv_up "$2"; then
break
else
msg_warn "Timeout in $((8-i))"
sleep 1
fi
done
ck_status "$2"
((i == 7)) && exit 1 || exit 0
fi
ck_status "$2"
;;
"enable")
if runit_sv_enabled "$2" || rc_sv_enabled "$2"; then
msg_error "$2: service is already enabled"
elif runit_sv_available "$2"; then
enable_runit_sv "$2"
elif rc_sv_available "$2"; then
enable_rc_sv "$2"
fi
ck_status "$2"
;;
"disable")
if runit_sv_enabled "$2"; then
disable_runit_sv "$2"
elif rc_sv_enabled "$2"; then
disable_rc_sv "$2"
elif runit_sv_available "$2" || rc_sv_available "$2"; then
msg_error "$2: runit/rc service is already disabled"
fi
ck_status "$2"
;;
"")
msg_error "usage: service command ..."
msg_error " for details, please type \"man service\""
exit 1
;;
*)
msg_error "$1: unrecognized command"
exit 1
;;
esac

View File

@@ -1,12 +0,0 @@
msg "Mounting /proc"
mountpoint -q /proc || mount -t proc proc /proc -o nosuid,noexec,nodev
msg "Mounting /sys"
mountpoint -q /sys || mount -t sysfs sys /sys -o nosuid,noexec,nodev
mountpoint -q /sys/kernel/security || mount -n -t securityfs securityfs /sys/kernel/security
[ -d /sys/firmware/efi ] && (mountpoint -q /sys/firmware/efi/efivars || mount -n -t efivarfs -o ro efivarfs /sys/firmware/efi/efivars)
msg "Mounting /dev"
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 /run || mount -t tmpfs run /run -o mode=0755,nosuid,nodev

View File

@@ -1,7 +0,0 @@
CGROUP_OPTS=nodev,noexec,nosuid
HAVE_CONTROLLER1_GROUPS=${HAVE_CONTROLLER1_GROUPS:-true}
CGROUP_MODE=${CGROUP_MODE:-hybrid}
CGROUP_CONTROLLERS=""
msg "Mounting cgroups"
mount_cgs

View File

@@ -1,4 +0,0 @@
# The generated file will be run by the next script
[[ -d /run/tmpfiles.d ]] || mkdir /run/tmpfiles.d
kmod static-nodes --format=tmpfiles --output=/run/tmpfiles.d/kmod.conf
tmpfiles --prefix=/dev --create --boot || emergency_shell

View File

@@ -1,6 +0,0 @@
# In the off-chance someone compiled their own Linux kernel without
# modules support
[[ ! -e /proc/modules ]] && return 0
msg "Loading user-specified modules"
modules-load

View File

@@ -1,6 +0,0 @@
msg "Starting udev"
udevd --daemon
udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices
msg "Waiting for udev uevents to be processed"
udevadm settle

View File

@@ -1,17 +0,0 @@
[ -r /etc/vconsole.conf ] && . /etc/vconsole.conf
TTYS=${TTYS:-6}
_index=0
[ -n "$FONT" ] && msg "Setting up TTY font to ${FONT}"
while [ ${_index} -le "$TTYS" ]; do
if [ -n "$FONT" ]; then
setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} \
"$FONT" -C "/dev/tty${_index}"
fi
printf "\033%s" "%G" >/dev/tty${_index}
_index=$((_index + 1))
done
if [ -n "$KEYMAP" ]; then
msg "Setting up keymap to ${KEYMAP}"
loadkeys -q -u "${KEYMAP}"
fi

View File

@@ -1,10 +0,0 @@
HWCLOCK_PARAMS="--systz"
HARDWARECLOCK=${HARDWARECLOCK:-UTC}
case $HARDWARECLOCK in
UTC) HWCLOCK_PARAMS+=" --utc --noadjfile" ;;
localtime) HWCLOCK_PARAMS+=" --localtime --noadjfile" ;;
*) HWCLOCK_PARAMS="" ;;
esac
hwclock $HWCLOCK_PARAMS || emergency_shell

View File

@@ -1,2 +0,0 @@
msg "Remounting rootfs read-only"
mount -o remount,ro / || emergency_shell

View File

@@ -1,2 +0,0 @@
msg "Activating btrfs devices"
btrfs device scan || emergency_shell

View File

@@ -1,2 +0,0 @@
msg "Activating LVM devices"
vgchange --sysinit -a y || emergency_shell

View File

@@ -1,8 +0,0 @@
if [[ -r /etc/crypttab ]]; then
msg "Unlocking encrypted devices"
read_crypttab do_unlock
if [[ -x /usr/bin/vgchange && -x @RCLIBDIR@/stage1/05-lvm ]]; then
msg "Activating LVM for encrypted devices"
vgchange --sysinit -a y >/dev/null || emergency_shell
fi
fi

View File

@@ -1,14 +0,0 @@
[ -f /forcefsck ] && FORCEFSCK="-f"
[ -f /fastboot ] && return 0
for arg in $(< /proc/cmdline); do
case $arg in
fastboot) return 0 ;;
forcefsck) FORCEFSCK="-f" ;;
esac
done
msg "Checking filesystems"
fsck -A -T -a -t no${NET_FS//,/,no},noopts=_netdev $FORCEFSCK
fsckret=$?
fsck_reboot $fsckret

View File

@@ -1,8 +0,0 @@
msg "Remounting root read-write"
mount -o remount,rw / || emergency_shell
msg "Mounting filesystems"
mount -a -t "no${NETFS//,/,no}" -O no_netdev || emergency_shell
msg "Mounting swap"
swapon -a || emergency_shell

View File

@@ -1,25 +0,0 @@
#!/bin/sh
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 ] && [ -s /etc/hostname ] && read -r HOSTNAME < /etc/hostname
if [ -n "$HOSTNAME" ]; then
msg "Setting hostname to ${HOSTNAME}"
printf "%s" "$HOSTNAME" >| /proc/sys/kernel/hostname
else
msg_warn "/etc/hostname is empty, hostname set to artixlinux"
fi
if [ -x /usr/bin/tmpfiles ]; then
msg "Setting up tmpfiles"
tmpfiles --exclude-prefix=/dev --create --remove --boot
fi
if [ -x /usr/bin/sysusers ]; then
msg "Setting up sysusers"
sysusers
fi

View File

@@ -1,2 +0,0 @@
msg "Loading sysctl settings"
sysctl --system

View File

@@ -1,17 +0,0 @@
msg "Cleaning up"
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 -m0664 -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
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

View File

@@ -1,7 +0,0 @@
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)
halt -w # utmp
msg "Stopping udev"
udevadm control --exit

View File

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

@@ -1,32 +0,0 @@
msg "Deactivating swap"
swapoff -a
msg "Unmounting filesystems"
#umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
findmnt -mrunRo TARGET,FSTYPE,OPTIONS / | {
while read -r target fstype options; do
# interpret the ascii chars, such as \x20 (space)
printf -v target '%b' "$target"
# match only targeted fstypes
if [[ $1 && $1 != "$fstype" ]]; then
continue
fi
# do not unmount API filesystems
if [[ $target = /@(proc|sys|run|dev|dev/pts) ]]; then
continue
fi
# avoid networked devices
IFS=, read -ra opts <<< "$options"
if in_array _netdev "${opts[@]}"; then
continue
fi
mounts=("$target" "${mounts[@]}")
done
if (( ${#mounts[*]} )); then
umount -r "${mounts[@]}" || return 1
fi
}

View File

@@ -1,7 +0,0 @@
msg "Deactivating LVM volumes"
if [[ -x /usr/bin/vgchange ]]; then
vgs="$(vgs | wc -l)"
if [[ $vgs -gt 0 ]]; then
vgchange -a n
fi
fi

View File

@@ -1,9 +0,0 @@
msg "Deactivating encrypted devices"
read_crypttab do_lock
if [[ -x /usr/bin/vgchange && -x @RCLIBDIR@/stage3/40-lvm ]]; then
msg "Deactivating LVM volumes for encrypted devices"
vgs="$(vgs | wc -l)"
if [[ $vgs -gt 0 ]]; then
vgchange -a n
fi
fi

View File

@@ -1,4 +0,0 @@
msg "Remounting rootfs read-only"
mount -o remount,ro /
sync

17
sv.d/binfmt.d.in Normal file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Running binfmt.d"
/usr/lib/artix/binfmt.sh || stat_die binfmt.d
add_daemon binfmt.d
stat_done binfmt.d
;;
*)
echo "usage: $0 {start|once}"
exit 1
;;
esac

45
sv.d/binfmt.in Normal file
View File

@@ -0,0 +1,45 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
mount_binfmt(){
mountpoint -q /proc/sys/fs/binfmt_misc || \
mount -t binfmt_misc binfmt /proc/sys/fs/binfmt_misc || return 1
for files in /proc/sys/fs/binfmt_misc/*; do
[ "$files" = /proc/sys/fs/binfmt_misc/register ] && continue
[ "$files" = /proc/sys/fs/binfmt_misc/status ] && continue
echo -1 > "$files"
done
for path in /usr/lib/binfmt.d /etc/binfmt.d /run/binfmt.d; do
[[ ! -d $path ]] && continue
[[ -z "$(ls $path)" ]] && continue
grep -h "^:" $path/* | \
while read -r line; do
printf "%s" "$line" > /proc/sys/fs/binfmt_misc/register || return 1
done
done
return 0
}
case "$1" in
start)
stat_busy "Running binfmt"
mount_binfmt || stat_die binfmt
add_daemon binfmt
stat_done binfmt
;;
once)
stat_busy "Running binfmt"
mount_binfmt || stat_die binfmt
stat_done
;;
*)
echo "usage: $0 {start|once}"
exit 1
;;
esac

View File

@@ -1,16 +0,0 @@
#!/bin/sh
mountpoint -q /proc/sys/fs/binfmt_misc || \
mount -t binfmt_misc binfmt /proc/sys/fs/binfmt_misc
ret=$?
if [ $ret -gt 0 ]; then
msg_error "Cannot mount binfmt!"
return 1
fi
for path in /usr/lib/binfmt.d /usr/local/binfmt.d /run/binfmt.d /etc/binfmt.d; do
[[ ! -d $path ]] && continue
[[ -z "$(ls $path)" ]] && continue
grep "^:" $path/* | \
while read -r line; do
printf "%s" "$line" > /proc/sys/fs/binfmt_misc/register || return 1
done
done

34
sv.d/bootlogd.in Normal file
View File

@@ -0,0 +1,34 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
start_bootlogd(){
bootlogd -p /run/bootlogd.pid -l /var/log/boot.log || return 1
}
stop_bootlogd(){
[[ -f /run/bootlogd.pid ]] || return 0
touch /var/log/boot.log
kill $(< /run/bootlogd.pid)
rm -f /run/bootlogd.pid
}
case "$1" in
start)
stat_busy "Starting bootlogd"
start_bootlogd || stat_die bootlogd
add_daemon bootlogd
stat_done bootlogd
;;
stop)
stat_busy "Stopping bootlogd"
stop_bootlogd || stat_die bootlogd
rm_daemon bootlogd
stat_done bootlogd
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac

17
sv.d/cgroups.in Normal file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Mounting cgroups filesystem"
/usr/lib/artix/mount-cgroups.sh|| stat_die cgroups
add_daemon cgroups
stat_done cgroups
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

38
sv.d/cleanup.in Normal file
View File

@@ -0,0 +1,38 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
. @RCDIR@/rc.conf
cleaning(){
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 -f /etc/nologin /forcefsck /forcequotacheck /fastboot
[ "$CLEANTMP" = y ] && rm -rf /tmp/*
}
case "$1" in
start)
stat_busy "Starting cleanup"
cleaning
add_daemon cleanup
stat_done
;;
stop)
stat_busy "Stopping cleanup"
halt -w || stat_die
rm_daemon cleanup
stat_done
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac

34
sv.d/console-setup.in Normal file
View File

@@ -0,0 +1,34 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
config(){
[ -r /etc/vconsole.conf ] && . /etc/vconsole.conf
TTYS=${TTYS:-6}
_index=0
while [ ${_index} -le $TTYS ]; do
if [ -n "$FONT" ]; then
setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} \
$FONT -C "/dev/tty${_index}"
fi
printf "\033%s" "%G" >/dev/tty${_index}
_index=$((_index + 1))
done
if [ -n "$KEYMAP" ]; then
loadkeys -q -u ${KEYMAP}
fi
}
case "$1" in
start)
stat_busy "Starting console-setup"
config
add_daemon console-setup
stat_done
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

134
sv.d/cryptsetup.in Normal file
View File

@@ -0,0 +1,134 @@
#!/bin/bash
. @RCLIBDIR@/functions
do_unlock_device() {
# $1 = requested name
# $2 = source device
# $3 = password
# $4 = options
local open=create a=$1 b=$2 failed=0 opts
# 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
else
printhl "Non-LUKS partitions are not supported at the moment."
continue
fi
if [[ $4 ]]; then
for i in ${4//,/ }; do
case $i in
"discard") opts+="--allow-discard" ;;
"readonly"|"read-only") opts+="--readonly" ;;
"tries"*) opts+="-T ${i##*=}" ;;
"keyfile-size"*) opts+="-l ${i##*=}" ;;
"keyfile-offset"*) opts+="--keyfile-offset ${i##*=}" ;;
"key-slot"*) opts+="-S ${i##*=}" ;;
*)
printhl "The option is not currently supported at the moment."
printhl "Please add an issue to https://github.com/artix-linux/runit-rc"
continue
;;
esac
done
fi
case $3 in
/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} $opts $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" $opts $open "$a" "$b" >/dev/null;;
"none" | "")
cryptsetup $opts $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_device "$name" "$device" "$password" "$options"
return $?
fi
do_unlock_device "$name" "$device" "$password" "$options"
esac
failed=$?
if (( $failed )); then
printf "${C_FAIL}Unlocking of $1 failed.${C_CLEAR}\n"
fi
return $?
}
do_lock() {
#status "Detaching encrypted device ${1}"
cryptsetup luksClose "$1" >/dev/null
}
read_crypttab() {
# $1 = function to call with the split out line from the crypttab
local line nspo failed=0
while read line <&3; do
[[ $line && $line != '#'* ]] || continue
eval nspo=("${line%#*}")
if $1 "${nspo[0]}" "${nspo[1]}" "${nspo[2]}" "${nspo[*]:3}"; then
crypto_unlocked=1
else
failed=1
fi
done 3< /etc/crypttab
return $failed
}
case "$1" in
start)
stat_busy "Starting encrypted devices"
read_crypttab do_unlock
rc=$?
vgchange --sysinit -a y >/dev/null
(( rc || $? )) && stat_die
add_daemon cryptsetup
stat_done
;;
stop)
stat_busy "Stopping encrypted devices"
vgchange --sysinit -a n &>/dev/null
rc=$?
read_crypttab do_lock
(( rc || $? )) && stat_die
rm_daemon cryptsetup
stat_done
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac

49
sv.d/devfs.in Normal file
View File

@@ -0,0 +1,49 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
mount_devfs(){
mountpoint -q /dev || mount -t devtmpfs dev /dev -o mode=0755,nosuid
# seed /dev with some things that might be needed (for example,
# xudev doesn't do this compared to eudev), code from OpenRC
# creating /dev/console, /dev/tty and /dev/tty1 to be able to write
# to $CONSOLE with/without bootsplash before udevd creates it
[ -c /dev/console ] || mknod -m 600 /dev/console c 5 1
[ -c /dev/tty1 ] || mknod -m 620 /dev/tty1 c 4 1
[ -c /dev/tty ] || mknod -m 666 /dev/tty c 5 0
# udevd will dup its stdin/stdout/stderr to /dev/null
# and we do not want a file which gets buffered in ram
[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
# so udev can add its start-message to dmesg
[ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11
# extra symbolic links not provided by default
[ -e /dev/fd ] || ln -snf /proc/self/fd /dev/fd
[ -e /dev/stdin ] || ln -snf /proc/self/fd/0 /dev/stdin
[ -e /dev/stdout ] || ln -snf /proc/self/fd/1 /dev/stdout
[ -e /dev/stderr ] || ln -snf /proc/self/fd/2 /dev/stderr
[ -e /proc/kcore ] && ln -snf /proc/kcore /dev/core
mkdir -p /dev/pts /dev/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 /run || mount -t tmpfs run /run -o mode=0755,nosuid,nodev
}
case "$1" in
start)
stat_busy "Mounting dev filesystem"
mount_devfs
add_daemon devfs
stat_done
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

26
sv.d/dmesg.in Normal file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
config(){
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
}
case "$1" in
start)
stat_busy "Saving dmesg log"
config
add_daemon dmesg
stat_done
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac

29
sv.d/hostname.in Normal file
View File

@@ -0,0 +1,29 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
config(){
unset HOSTNAME
if [[ -s /etc/hostname ]]; then
HOSTNAME=$(< /etc/hostname)
fi
if [[ $HOSTNAME ]]; then
echo "$HOSTNAME" >| /proc/sys/kernel/hostname
fi
}
case "$1" in
start)
stat_busy "Starting hostname"
config
add_daemon hostname
stat_done
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

36
sv.d/hwclock.in Normal file
View File

@@ -0,0 +1,36 @@
#!/bin/bash
. @RCLIBDIR@/functions
. @RCDIR@/rc.conf
HARDWARECLOCK=${HARDWARECLOCK:-UTC}
case $HARDWARECLOCK in
UTC) HWCLOCK_PARAMS+=" --utc" ;;
localtime) HWCLOCK_PARAMS+=" --localtime" ;;
*) HWCLOCK_PARAMS="";;
esac
case "$1" in
start)
stat_busy "Adjusting hwclock"
hwclock --systz $HWCLOCK_PARAMS --noadjfile || stat_die
add_daemon hwclock
stat_done
;;
stop)
stat_busy "Adjusting hwclock"
hwclock --systohc $HWCLOCK_PARAMS || stat_die
rm_daemon hwclock
stat_done
;;
restart)
$0 stop
sleep 2
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
;;
esac

22
sv.d/kmod-static-nodes.in Normal file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
conig(){
[[ -d /run/tmpfiles.d ]] || mkdir /run/tmpfiles.d
kmod static-nodes --format=tmpfiles --output=/run/tmpfiles.d/kmod.conf
}
case "$1" in
start)
stat_busy "Starting kmod-static-nodes"
conig
add_daemon kmod-static-nodes
stat_done
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

22
sv.d/lvm-monitoring.in Normal file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Starting monitoring of LVM2 groups"
vgchange --monitor y >/dev/null || stat_die
add_daemon lvm-monitoring
stat_done
;;
stop)
stat_busy "Stopping monitoring of LVM2 groups"
vgchange --monitor n || stat_die
rm_daemon lvm-monitoring
stat_done
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac

22
sv.d/lvm.in Normal file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Starting LVM2 groups"
vgchange --sysinit -a y >/dev/null || stat_die
add_daemon lvm
stat_done
;;
stop)
stat_busy "Stopping LVM2 groups"
vgchange --sysinit -a n &>/dev/null || stat_die
rm_daemon lvm
stat_done
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac

87
sv.d/misc.in Normal file
View File

@@ -0,0 +1,87 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
# 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 -M -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
}
do_fsck(){
if [[ -x $(type -P fsck) ]]; then
fsck_all >|"${FSCK_OUT:-/dev/stdout}" 2>|"${FSCK_ERR:-/dev/stdout}"
declare -r fsckret=$?
else
declare -r fsckret=0
fi
fsck_reboot $fsckret
}
kill_all(){
pkill --inverse -s0,1 -TERM
sleep 1
pkill --inverse -s0,1 -KILL
}
case "$1" in
start)
stat_busy "Checking filesystems"
do_fsck
add_daemon misc
stat_done
;;
stop)
stat_busy "Running kill-all"
kill_all
rm_daemon misc
stat_done
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac

27
sv.d/modules.in Normal file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
load_modules() {
local rc=0
/usr/bin/modules-load
(( rc+=$? ))
return $rc
}
case "$1" in
start)
stat_busy "Loading user-specified modules"
load_modules || stat_die modules
add_daemon modules
stat_done modules
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

17
sv.d/mount-all.in Normal file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Starting mount-all"
mount -a -t "no${NETFS//,/,no}" -O no_netdev || stat_die mount-all
add_daemon mount-all
stat_done mount-all
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

17
sv.d/net-lo.in Normal file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Starting net-lo"
ip link set up dev lo || stat_die
add_daemon net-lo
stat_done
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

View File

@@ -1,8 +0,0 @@
#!/bin/sh
umount -a -f -t "$NETFS"
ret=$?
[ $ret != 0 ] && umount -a -f -l -t "$NETFS"
umount -a -f -O _netdev
ret=$?
[ $ret != 0 ] && umount -a -f -l -O _netdev

View File

@@ -1,3 +0,0 @@
#!/bin/sh
mount -a -t "$NETFS" || return 1
mount -a -O _netdev || return 1

32
sv.d/procfs.in Normal file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
mount_procfs(){
grep -v '^#' /etc/fstab | grep /proc | {
read -r spec file vfstype mntopts x
if ! mountpoint -q /proc; then
if [ "$spec" -a "$file" -a "$vfstype" -a "$mntopts" ]; then
mount -t "$vfstype" "$spec" "$file" -o "$mntopts"
else
mount -t proc proc /proc
fi
elif [ "$spec" -a "$file" -a "$vfstype" -a "$mntopts" ] && mountpoint -q /proc; then
mount -t "$vfstype" "$spec" "$file" -o "remount,$mntopts"
fi
}
}
case "$1" in
start)
stat_busy "Mounting proc filesystem"
mount_procfs
add_daemon procfs
stat_done
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

32
sv.d/random-seed.in Normal file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
load_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_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 )
}
case "$1" in
start)
stat_busy "Starting random-seed"
load_seed
add_daemon random-seed
stat_done
;;
stop)
stat_busy "Stopping random-seed"
save_seed
rm_daemon random-seed
stat_done
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac

24
sv.d/remount-root.in Normal file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Remounting root filesystem rw"
mount -o remount,rw / || stat_die remount-root
add_daemon remount-root
stat_done remount-root
;;
stop)
stat_busy "Remounting root filesystem ro"
mount -o remount,ro / || stat_die remount-root
sync
rm_daemon remount-root
stat_done remount-root
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac

63
sv.d/root.in Normal file
View File

@@ -0,0 +1,63 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
mount_fs(){
findmnt / --options ro &>/dev/null || mount -o remount,ro / || return 1
return 0
}
# umount_fs(){
# umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
# }
umount_fs() {
findmnt -mrunRo TARGET,FSTYPE,OPTIONS / | {
while read -r target fstype options; do
# interpret the ascii chars, such as \x20 (space)
printf -v target '%b' "$target"
# match only targeted fstypes
if [[ $1 && $1 != "$fstype" ]]; then
continue
fi
# do not unmount API filesystems
if [[ $target = /@(proc|sys|run|dev|dev/pts) ]]; then
continue
fi
# avoid networked devices
IFS=, read -ra opts <<< "$options"
if in_array _netdev "${opts[@]}"; then
continue
fi
mounts=("$target" "${mounts[@]}")
done
if (( ${#mounts[*]} )); then
umount -r "${mounts[@]}" || return 1
fi
return 0
}
}
case "$1" in
start)
stat_busy "Mounting filesystems"
mount_fs || stat_die root
add_daemon root
stat_done root
;;
stop)
stat_busy "Unounting filesystems"
umount_fs || stat_die root
rm_daemon root
stat_done root
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac

View File

@@ -1,11 +0,0 @@
# The interface to be used
#INTERFACE="enp3s0"
# The IP address, in CIDR notation
#IPADDR="192.168.1.2/24"
# The broadcast address, leave it commented to determine it automatically
#BROADCAST="192.168.1.255"
# IP routing gateway
#ROUTE="default via 192.168.1.1"

View File

@@ -1,4 +0,0 @@
#!/bin/sh
[ -r conf ] && . ./conf
ip addr del "${IPADDR}" dev "${INTERFACE}"
ip route del "${ROUTE}" dev "${INTERFACE}"

View File

@@ -1,11 +0,0 @@
#!/bin/sh
[ -r conf ] && . ./conf
if [ -z "${INTERFACE}" ]; then
msg_error "Interface has not been set! See ./conf for more details"; return 1
elif [ -z "${IPADDR}" ]; then
msg_error "IP address has not been set! See /etc/rc/sv.d/staticnet/conf for more details"; return 1
elif [ -z "${ROUTE}" ]; then
msg_error "IP route has not been set! See /etc/rc/sv.d/staticnet/conf for more details"; return 1
fi
ip addr add "${IPADDR}" broadcast "${BROADCAST:=+}" dev "${INTERFACE}"
ip route add "${ROUTE}" dev "${INTERFACE}"

23
sv.d/swap.in Normal file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Activating swap"
swapon -a || stat_die swap
add_daemon swap
stat_done swap
;;
stop)
stat_busy "Deactivating swap"
swapoff -a || stat_die swap
rm_daemon swap
stat_done swap
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac

17
sv.d/sysctl.in Normal file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Loading sysctl settings"
sysctl --system || stat_die sysctl
add_daemon sysctl
stat_done sysctl
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

23
sv.d/sysfs.in Normal file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
mount_sysfs(){
mountpoint -q /sys || mount -t sysfs sys /sys -o nosuid,noexec,nodev
mountpoint -q /sys/kernel/security || mount -n -t securityfs securityfs /sys/kernel/security
[ -d /sys/firmware/efi ] && (mountpoint -q /sys/firmware/efi/efivars || mount -n -t efivarfs -o ro efivarfs /sys/firmware/efi/efivars)
}
case "$1" in
start)
stat_busy "Mounting sys filesystem"
mount_sysfs
add_daemon sysfs
stat_done
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

17
sv.d/sysusers.in Normal file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Starting sysusers"
esysusers
add_daemon sysusers
stat_done
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

35
sv.d/timezone.in Normal file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Setting timezone"
zonefile=/usr/share/zoneinfo/$TIMEZONE
# [[ $TIMEZONE ]] || return 1
if [[ ! -L /etc/localtime && /etc/localtime -ef $zonefile ]]; then
ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
fi
add_daemon timezone
stat_done
;;
stop)
stat_busy "Setting timezone"
zonefile=/usr/share/zoneinfo/$TIMEZONE
# [[ $TIMEZONE ]] || return 1
if [[ ! -L /etc/localtime && /etc/localtime -ef $zonefile ]]; then
ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
fi
rm_daemon timezone
stat_done
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac

17
sv.d/tmpfiles-dev.in Normal file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Starting tmpfiles-dev"
etmpfiles --prefix=/dev --create --boot || stat_die tmpfiles-dev
add_daemon tmpfiles-dev
stat_done tmpfiles-dev
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

17
sv.d/tmpfiles-setup.in Normal file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Starting tmpfiles-setup"
etmpfiles --exclude-prefix=/dev --create --remove --boot || stat_die tmpfiles-setup
add_daemon tmpfiles-setup
stat_done tmpfiles-setup
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

19
sv.d/udev-settle.in Normal file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Waiting for udev uevents to be processed"
udevadm settle || stat_die udev-settle
calc_columns
add_daemon udev-settle
stat_done udev-settle
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

21
sv.d/udev-trigger.in Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Triggering udev uevents"
udevadm trigger --action=add --type=subsystems
ret=$?
udevadm trigger --action=add --type=devices
(( ret || $? )) && stat_die udev-trigger
add_daemon udev-trigger
stat_done udev-trigger
;;
*)
echo "usage: $0 {start}"
exit 1
;;
esac

27
sv.d/udev.in Normal file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. @RCLIBDIR@/functions
case "$1" in
start)
stat_busy "Starting udev daemon"
udevd --daemon || stat_die udev
# Note: This is only needed for initialization, udev will
# be controlled by runit on stage 2.
add_daemon udev
stat_done udev
;;
stop)
stat_busy "Stopping udev"
# check whether udevd might still be running.
! pgrep -f "udevd" >/dev/null 2>&1 || udevadm control --exit || stat_die udev
rm_daemon udev
stat_done udev
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac