50 Commits

Author SHA1 Message Date
1aeedd0019 Remove /forcefsck and others during cleanup 2018-05-07 10:36:52 +07:00
0db3224e90 Add binfmt support 2018-05-06 20:25:53 +07:00
9527ccc8d0 Only read /etc/vconsole.conf if file exists 2018-05-06 19:46:18 +07:00
fb122c1beb Read from /etc/vconsole.conf for console_setup 2018-05-06 18:31:26 +07:00
8b47e238b9 Enable btrfs support 2018-05-06 18:27:45 +07:00
c9126a652a Make cleanup.sh the very last script to run by stage1 2018-05-06 11:13:45 +07:00
udeved
89b99e475d tmpfiles --clean is not implemented in opentmpfiles; remove the call 2018-05-06 01:14:01 +00:00
udeved
9befe99ed5 merge master 2018-05-05 23:27:57 +00:00
udeved
d36f9e6952 make clean up a sysinit module
rm unused
2018-05-05 23:24:56 +00:00
7852ea0ee3 sysctl: use sysctl --system 2018-05-06 06:12:39 +07:00
cf1c3912e7 Remove /forcefsck and others after boot
After testing, this file wasn't removed after boot, so I had to remove
it manually.
2018-05-06 06:03:29 +07:00
udeved
9cd7ec066b 1: move cleanup in rc 2018-05-05 21:57:53 +00:00
udeved
0df2f865bb rc: don't attempt to remove /tmp, consider /tmp to be mounted tmpfs
give the boot log file a*.log file extension
2018-05-05 21:57:17 +00:00
b3c76e6a59 Mount efivarfs only if EFI is detected 2018-05-05 21:08:11 +07:00
8847aa38b4 Force processes to be killed anyway 2018-05-05 21:06:05 +07:00
161c96b8fa Add license 2018-05-05 20:04:03 +07:00
990661bfd9 Split up getty-runit to its own make 2018-05-05 17:55:05 +07:00
bf732c4905 Move stages to rc, remove HASSYSV flag 2018-05-05 17:38:23 +07:00
24306e68c1 log console messages with bootlogd 2018-05-05 17:23:30 +07:00
9ae595db4f Move sysctl to functions 2018-05-05 17:14:50 +07:00
1eaaac7428 Add sysctl init to stage1 initscript 2018-05-05 17:03:47 +07:00
c9e84492fb Make stage 2 init-agnostic 2018-05-05 17:02:59 +07:00
9e4fd67db6 Add cleanup sysinit to stage1 2018-05-05 17:01:43 +07:00
d47df45f50 Remount RO before deactivating cryptsetup and LVM2 2018-05-05 15:26:25 +07:00
0665f7630b Remove Void shutdown binaries (now handled by artix-sysvcompat) 2018-05-05 13:48:48 +07:00
9a9003b255 sync immediately after remount ro 2018-05-05 13:45:08 +07:00
udeved
a67af1e82b fix bootlogd 2018-05-05 03:49:12 +00:00
udeved
b0238301c9 makefile: add HASSYSV param 2018-05-05 02:09:16 +02:00
udeved
c28ea35b41 merge makefiles 2018-05-05 02:01:09 +02:00
7f0feca5b2 Merge branch 'rc-modules' 2018-05-05 06:05:23 +07:00
a47df21b08 Remove unmount tmpfs
runit needs to read /run during shutdown
2018-05-05 06:00:40 +07:00
989a323867 Fix unmount command 2018-05-05 05:55:19 +07:00
3139aa4609 Fix cryptsetup lock on shutdown 2018-05-05 05:30:11 +07:00
7cad901c86 Fix issues with command not found 2018-05-05 05:24:51 +07:00
d145dce79a Integrate some hooks into initscripts 2018-05-05 05:06:54 +07:00
fd63fdca89 Add back securityfs and efivarfs 2018-05-05 04:48:11 +07:00
7d09c40c88 Add sysinit.d and shutdown.d to makefile 2018-05-05 04:30:42 +07:00
d3a6d855ca Integrate rc.sysinit and rc.shutdown in stage1 and 3 2018-05-05 04:21:17 +07:00
5c42be6143 Use crypt.awk instead 2018-05-05 03:45:20 +07:00
90b1e1c301 typo 2018-05-05 03:22:53 +07:00
udeved
65768e39ea wip 2018-05-04 21:55:50 +02:00
ed2bb8edd7 Add efivarfs 2018-05-05 02:52:00 +07:00
a44aab979b Merge old Arch rc functions to runit-artix 2018-05-04 13:55:32 +07:00
udeved
1e6537cb5c makefile: sed RCDIR 2018-05-03 18:49:47 +02:00
udeved
1250ac8e8f provide rc makefile 2018-05-03 18:41:33 +02:00
udeved
9aed8d1e97 split out rc 2018-05-03 16:18:00 +02:00
udeved
46604a1cb9 rename services->sv 2018-05-03 12:25:19 +02:00
udeved
d8dfa64afc create /var/log/boot 2018-05-03 12:20:22 +02:00
udeved
0b464e9da9 runit.conf: fix sed target 2018-05-03 12:01:51 +02:00
udeved
4dcecb7d45 integrate rc scripts in runit stages 2018-05-03 11:53:22 +02:00
123 changed files with 1017 additions and 793 deletions

34
1
View File

@@ -1,34 +0,0 @@
#!/bin/sh
# vim: set ts=4 sw=4 et:
PATH=/usr/bin:/usr/sbin
. /etc/runit/functions
[ -r /etc/runit/rc.conf ] && . /etc/runit/rc.conf
msg "Welcome to Artix Linux!"
if [ -x /usr/bin/openrc ] && [ "$SVMANAGER" = "openrc" ]; then
# Start core services: we'll use OpenRC for this.
msg "Initializing runlevel sysinit with OpenRC..."
openrc sysinit || msg_error "Failed to start sysinit runlevel"
else
# Start core services: one-time system tasks.
detect_virt
for f in /etc/runit/core-services/*.sh; do
[ -r $f ] && . $f
done
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..."

23
1.in Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
PATH=/usr/bin:/usr/sbin
. @RCDIR@/rc.conf
. @RCDIR@/functions
# Prints distro name and URL
print_welcome
run_hook sysinit_start
for sysinit in @RCDIR@/sysinit.d/*; do
. $sysinit
done
run_hook sysinit_end
install -m100 /dev/null @RUNDIR@/stopit
status "Initialization complete"
bootlogd_stop

28
2
View File

@@ -1,28 +0,0 @@
#!/bin/sh
# vim: set ts=4 sw=4 et:
PATH=/usr/bin:/usr/sbin
runlevel=default
for arg in $(cat /proc/cmdline); do
if [ -d /etc/runit/runsvdir/"$arg" ]; then
echo "Runlevel detected: '$arg' (via kernel cmdline)"
runlevel="$arg"
fi
done
[ -x /etc/runit/rc.local ] && /etc/runit/rc.local
# The reason that boot is not in stage 1 is because if something hangs
# we can still listen for signals, however stage 1 does NOT accept signals
if [ -x /usr/bin/openrc ] && [ "$SVMANAGER" = "openrc" ]; then
openrc boot
openrc default
fi
runsvchdir "${runlevel}"
mkdir -p /run/runit/runsvdir
ln -s /etc/runit/runsvdir/current /run/runit/service
exec env - PATH=$PATH \
runsvdir -P /run/runit/service 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'

20
2.in Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
PATH=/usr/bin:/usr/sbin
[ -x @RCDIR@/rc.local ] && . @RCDIR@/rc.local
runlevel=default
for arg in $(cat /proc/cmdline); do
if [ -d @RUNITDIR@/runsvdir/"$arg" ]; then
echo "Runlevel detected: '$arg' (via kernel cmdline)"
runlevel="$arg"
fi
done
runsvchdir "${runlevel}"
# mkdir -p @RUNDIR@/runsvdir
ln -s @RUNSVDIR@/current @SERVICEDIR@
exec env - PATH=$PATH \
runsvdir -P @SERVICEDIR@ 'log: ...........................................................................................................................................................................................................................................................................................................................................................................................................'

20
3
View File

@@ -1,20 +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
[ -x /etc/runit/rc.shutdown ] && /etc/runit/rc.shutdown
for f in /etc/runit/shutdown-services/*.sh; do
[ -r $f ] && . $f
done
msg "Stage 3 completed."

35
3.in Executable file
View 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."

24
COPYING Normal file
View File

@@ -0,0 +1,24 @@
Copyright (C) 2018 Muhammad Herdiansyah
Copyright (C) 2018 Artix Linux Developers
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

165
Makefile
View File

@@ -1,55 +1,122 @@
PREFIX ?= /usr
SCRIPTS= 1 2 3 ctrlaltdel
SYSCONFDIR = /etc
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
RCDIR = $(SYSCONFDIR)/rc
all:
$(CC) $(CFLAGS) halt.c -o halt $(LDFLAGS)
$(CC) $(CFLAGS) pause.c -o pause $(LDFLAGS)
TMPFILES = tmpfile.conf
install:
install -d ${DESTDIR}${PREFIX}/bin
install -d ${DESTDIR}${PREFIX}/lib/runit-artix/bin
install -m755 pause ${DESTDIR}${PREFIX}/bin/pause
install -m755 modules-load ${DESTDIR}${PREFIX}/bin/modules-load
install -m755 zzz ${DESTDIR}${PREFIX}/bin/zzz
install -m755 halt ${DESTDIR}${PREFIX}/lib/runit-artix/bin/halt
install -m755 shutdown ${DESTDIR}${PREFIX}/lib/runit-artix/bin/shutdown
ln -sf halt ${DESTDIR}${PREFIX}/lib/runit-artix/bin/poweroff
ln -sf halt ${DESTDIR}${PREFIX}/lib/runit-artix/bin/reboot
install -d ${DESTDIR}${PREFIX}/share/man/man1
install -m644 pause.1 ${DESTDIR}${PREFIX}/share/man/man1
install -d ${DESTDIR}${PREFIX}/share/man/man8
install -m644 zzz.8 ${DESTDIR}${PREFIX}/share/man/man8/zzz.8
install -m644 modules-load.8 ${DESTDIR}${PREFIX}/share/man/man8
install -d ${DESTDIR}/etc/runit/sv
install -d ${DESTDIR}/etc/runit/runsvdir
install -d ${DESTDIR}/etc/runit/core-services
install -d ${DESTDIR}/etc/runit/shutdown-services
install -m644 core-services/*.sh ${DESTDIR}/etc/runit/core-services
install -m644 shutdown-services/*.sh ${DESTDIR}/etc/runit/shutdown-services
install -m755 ${SCRIPTS} ${DESTDIR}/etc/runit
install -m644 functions $(DESTDIR)/etc/runit
install -m644 crypt.awk ${DESTDIR}/etc/runit
install -m644 rc.conf ${DESTDIR}/etc/runit
install -m755 rc.local ${DESTDIR}/etc/runit
install -m755 rc.shutdown ${DESTDIR}/etc/runit
ln -sf /run/runit/reboot ${DESTDIR}/etc/runit/
ln -sf /run/runit/stopit ${DESTDIR}/etc/runit/
cp -R --no-dereference --preserve=mode,links -v runsvdir/* ${DESTDIR}/etc/runit/runsvdir/
cp -R --no-dereference --preserve=mode,links -v services/* ${DESTDIR}/etc/runit/sv/
BIN = zzz pause modules-load
install_sysv:
install -d ${DESTDIR}${PREFIX}/bin
ln -sf runit-init ${DESTDIR}${PREFIX}/bin/init
ln -sf ${PREFIX}/lib/runit-artix/bin/halt ${DESTDIR}${PREFIX}/bin/halt
ln -sf ${PREFIX}/lib/runit-artix/bin/shutdown ${DESTDIR}${PREFIX}/bin/shutdown
ln -sf halt ${DESTDIR}${PREFIX}/bin/poweroff
ln -sf halt ${DESTDIR}${PREFIX}/bin/reboot
install -m644 shutdown.8 ${DESTDIR}${PREFIX}/share/man/man8/shutdown.8
install -m644 halt.8 ${DESTDIR}${PREFIX}/share/man/man8/halt.8
ln -sf halt.8 ${DESTDIR}${PREFIX}/share/man/man8/poweroff.8
ln -sf halt.8 ${DESTDIR}${PREFIX}/share/man/man8/reboot.8
STAGES = 1 2 3 ctrlaltdel
RC = rc/rc.local rc/rc.shutdown rc/functions rc/rc.conf
LN = ln -sf
CP = cp -R --no-dereference --preserve=mode,links -v
RM = rm -f
RMD = rm -fr --one-file-system
M4 = m4 -P
CHMODAW = chmod a-w
CHMODX = chmod +x
HASRC = yes
EDIT = sed \
-e "s|@RUNITDIR[@]|$(RUNITDIR)|g" \
-e "s|@SERVICEDIR[@]|$(SERVICEDIR)|g" \
-e "s|@RUNSVDIR[@]|$(RUNSVDIR)|g" \
-e "s|@RUNDIR[@]|$(RUNDIR)|g" \
-e "s|@RCDIR[@]|$(RCDIR)|g"
%: %.in Makefile
@echo "GEN $@"
@$(RM) "$@"
@$(M4) $@.in | $(EDIT) >$@
@$(CHMODAW) "$@"
@$(CHMODX) "$@"
all: all-runit
ifeq ($(HASRC),yes)
all: all-rc
endif
all-runit:
$(CC) $(CFLAGS) pause.c -o pause $(LDFLAGS)
all-rc: $(RC) $(STAGES)
install-runit:
install -d $(DESTDIR)$(RUNITDIR)
install -d $(DESTDIR)$(RUNSVDIR)
install -d $(DESTDIR)$(RUNSVDIR)/default
install -d $(DESTDIR)$(SVDIR)/sulogin
$(LN) $(RUNSVDIR)/default $(DESTDIR)$(RUNSVDIR)/current
$(CP) sv/sulogin $(DESTDIR)$(SVDIR)/
$(CP) runsvdir/single $(DESTDIR)$(RUNSVDIR)/
$(LN) $(RUNDIR)/reboot $(DESTDIR)$(RUNITDIR)/
$(LN) $(RUNDIR)/stopit $(DESTDIR)$(RUNITDIR)/
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:
install -d $(DESTDIR)$(RUNITDIR)
install -m755 $(STAGES) $(DESTDIR)$(RUNITDIR)
install -d $(DESTDIR)$(RCDIR)
install -d $(DESTDIR)$(RCDIR)/sysinit.d
install -d $(DESTDIR)$(RCDIR)/shutdown.d
install -m755 $(RC) $(DESTDIR)$(RCDIR)
install -m644 rc/sysinit.d/* $(DESTDIR)$(RCDIR)/sysinit.d
install -m644 rc/shutdown.d/* $(DESTDIR)$(RCDIR)/shutdown.d
install -m644 rc/crypt.awk $(DESTDIR)$(RCDIR)
install -d $(DESTDIR)$(RUNITDIR)
install -m755 $(STAGES) $(DESTDIR)$(RUNITDIR)
install-getty:
install -d $(DESTDIR)$(SVDIR)
$(CP) sv/agetty-* $(DESTDIR)$(SVDIR)/
install -d $(DESTDIR)$(RUNSVDIR)/default
$(CP) runsvdir/default $(DESTDIR)$(RUNSVDIR)/
install: install-runit
ifeq ($(HASRC),yes)
install: install-rc
endif
clean-runit:
-rm -f pause
clean-rc:
-rm -f $(RC)
-rm -f $(STAGES)
clean: clean-runit
ifeq ($(HASRC),yes)
clean: clean-rc
endif
clean:
-rm -f halt pause
.PHONY: all install install_sysv clean
.PHONY: all install clean install-runit install-rc install-getty clean-runit clean-rc all-runit all-rc

View File

@@ -3,16 +3,12 @@
This repository contains the runit init scripts for the Artix Linux
distribution.
This work is based on Void Linux's
[void-runit](https://github.com/voidlinux/void-runit). Patches to Void
Linux's repo will also be applied here.
## Dependencies
- GNU coreutils
- A POSIX shell
- GNU bash
- A POSIX awk
- procps-ng (needs pkill -s0,1)
- procps-ng
- runit
- opentmpfiles
- opensysusers
@@ -43,9 +39,7 @@ Feel free to send patches and contribute with improvements!
## Copyright
runit-artix is in the public domain.
Some codes are based on void-runit, which is licensed under CC0-1.0
To the extent possible under law, the creator of this work has waived
all copyright and related or neighboring rights to this work.
http://creativecommons.org/publicdomain/zero/1.0/
The rest of runit-artix is licensed under the terms as described in the
COPYING file.

View File

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

View File

@@ -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 -bq $f 2>/dev/null
done

View File

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

View File

@@ -1,24 +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 [ -x /usr/bin/tmpfiles ]; then
msg "Setting up tmpfiles.d entries for /dev..."
tmpfiles --prefix=/dev --create --boot
fi
if [ -n "${_udevd}" ]; then
msg "Starting udev and waiting for devices to settle..."
${_udevd} --daemon
udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices
udevadm settle
fi

View File

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

View File

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

View File

@@ -1,6 +0,0 @@
# vim: set ts=4 sw=4 et:
[ -n "$VIRTUALIZATION" ] && return 0
msg "Initializing swap..."
swapon -a || emergency_shell

View File

@@ -1,31 +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
msg "Setting up sysusers.d entries..."
if [ -x /usr/bin/sysusers ]; then
sysusers
fi
msg "Setting up tmpfiles.d entries..."
if [ -x /usr/bin/tmpfiles ]; then
tmpfiles --exclude-prefix=/dev --create --remove --boot
fi

View File

@@ -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 \
/usr/local/lib/sysctl.d/*.conf \
/usr/lib/sysctl.d/*.conf \
/etc/sysctl.conf \
/etc/sysctl.d/*.conf; do
if [ -e "$i" ]; then
printf '* Applying %s ...\n' "$i"
sysctl -p "$i"
fi
done
fi

View File

@@ -1,12 +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
rm -rf /tmp
install -dm1777 /tmp /tmp/.X11-unix /tmp/.ICE-unix
rm -f /etc/nologin /forcefsck /forcequotacheck /fastboot

View File

@@ -4,7 +4,7 @@ PATH=/usr/bin:/usr/sbin
MSG="System is going down..."
# We check for this file in stage3 to halt or reboot
touch /run/runit/reboot
touch @RUNDIR@/reboot
# Proceed with shutdown process
echo "$MSG" | wall

View File

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

67
halt.8
View File

@@ -1,67 +0,0 @@
.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
halt.c
View File

@@ -1,77 +0,0 @@
#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;
}

32
rc.conf
View File

@@ -1,32 +0,0 @@
# /etc/runit/rc.conf - system configuration
# Set the service manager (available options: "runit" or "openrc")
#SVMANAGER="runit"
# Set the host name.
#
# NOTE: it's preferred to declare the hostname in /etc/hostname instead:
# - 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

524
rc/functions.in Normal file
View File

@@ -0,0 +1,524 @@
#!/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
# 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() {
status "Sending TERM signal to processes" pkill --inverse -s0,1 -TERM
sleep 1
status "Sending KILL signal to processes" pkill --inverse -s0,1 -KILL
}
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
}
run_binfmt() {
mountpoint -q /proc/sys/fs/binfmt_misc || \
mount -t binfmt_misc binfmt /proc/sys/fs/binfmt_misc
for path in /usr/lib/binfmt.d /etc/binfmt.d /run/binfmt.d; do
[[ ! -d $path ]] && continue;
for file in $(ls -1 $path); do
grep "^:" $file | \
while read -r line; do
printf "%s" "$line" > /proc/sys/fs/binfmt_misc/register
done
done
done
}
# 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
}
bootlogd_stop() {
[[ -f /run/bootlogd.pid ]] || return 0
touch /var/log/boot.log
kill $(< /run/bootlogd.pid)
rm -f /run/bootlogd.pid
}
bootlogd_start(){
bootlogd -p /run/bootlogd.pid -l /var/log/boot.log
}
console_setup(){
[ -r /etc/vconsole.conf ] && . /etc/vconsole.conf
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
}
remove_leftover() {
status 'Removing leftover files' tmpfiles --create --remove --clean
}
mk_sysusers(){
if [ -x /usr/bin/sysusers ]; then
sysusers
fi
}
###############################
# 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

12
rc/rc.conf.in Normal file
View File

@@ -0,0 +1,12 @@
# @RCDIR@/rc.conf - system configuration
# Storage
#
# Enable dmraid support (yes/no)
# USEDMRAID="no"
# Enable LVM2 support (yes/no)
# USELVM="no"
# Enable btrfs support (yes/no)
# USEBTRFS="no"

View File

@@ -0,0 +1 @@
status 'Saving random seed' save_random_seed

View File

@@ -0,0 +1 @@
[[ $TIMEZONE ]] && status "Configuring time zone" set_timezone "$TIMEZONE"

2
rc/shutdown.d/03-wtmp.sh Normal file
View File

@@ -0,0 +1,2 @@
# Write to wtmp file before unmounting
halt -w

View 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
View File

@@ -0,0 +1,2 @@
# any future uevents can and should be ignored
status "Shutting down udev" udevadm control --exit

View File

@@ -0,0 +1,3 @@
run_hook shutdown_prekillall
kill_all
run_hook shutdown_postkillall

3
rc/shutdown.d/08-swap.sh Normal file
View 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

View 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

View File

@@ -0,0 +1,3 @@
status "Remounting root filesystem read-only" \
mount -o remount,ro /
sync

View 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/13-lvm2.sh Normal file
View File

@@ -0,0 +1,2 @@
[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) ]] &&
status "Deactivating LVM2 groups" vgchange --sysinit -an &>/dev/null

View File

@@ -0,0 +1,18 @@
# 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
[ -d /sys/firmware/efi ] && (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 /
bootlogd_start

View 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

View 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

View File

@@ -0,0 +1 @@
status "Creating list of required static device nodes" mk_kmod_static_nodes

View File

@@ -0,0 +1 @@
status "Setting up tmpfiles.d entries for /dev" mk_tmpfiles_dev

View File

@@ -0,0 +1,2 @@
# Start/trigger udev, load MODULES, and settle udev
udevd_modprobe sysinit

View File

@@ -0,0 +1,2 @@
# this must be done after udev has loaded the KMS modules
status 'Configuring virtual consoles' console_setup

View 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

View 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
View File

@@ -0,0 +1,2 @@
# Activate LVM2 groups, if any
activate_vgs

1
rc/sysinit.d/11-btrfs.sh Normal file
View File

@@ -0,0 +1 @@
status "Activating btrfs devices" btrfs device scan

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

View File

@@ -0,0 +1,2 @@
status "Remounting root and API filesystems" \
mount -o remount,rw /

View File

@@ -0,0 +1,4 @@
run_hook sysinit_premount
status "Mounting local filesystems" \
mount_all
run_hook sysinit_postmount

View 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
View File

@@ -0,0 +1 @@
status "Activating swap" swapon -a

View File

@@ -0,0 +1 @@
[[ $TIMEZONE ]] && status "Configuring time zone" set_timezone "$TIMEZONE"

View File

@@ -0,0 +1 @@
status 'Initializing random seed' init_random_seed

View File

@@ -0,0 +1 @@
status "Setting up tmpfiles.d entries" mk_tmpfiles_setup

View File

@@ -0,0 +1 @@
status "Setting up sysusers.d entries" mk_sysusers

View 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

View File

@@ -0,0 +1 @@
status "Loading sysctl(8) settings" sysctl --system

View File

@@ -0,0 +1 @@
status "Running binfmt" run_binfmt

View File

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

View File

@@ -1,73 +0,0 @@
#!/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 /run/runit/shutdown.pid)"
if [ -e /etc/nologin ] && ! [ -s /etc/nologin ]; then
rm /etc/nologin
fi
echo "${*:-shutdown cancelled}" | wall
exit
fi
touch /run/runit/shutdown.pid 2>/dev/null || abort "Not enough permissions to execute ${0#*/}"
echo $$ >/run/runit/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

View File

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

View File

@@ -1,2 +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 )

View File

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

View File

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

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

View File

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

View File

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

Some files were not shown because too many files have changed in this diff Show More