summary refs log tree commit diff
path: root/core-services
diff options
context:
space:
mode:
authorJuan RP <xtraeme@gmail.com>2014-08-07 17:22:57 +0200
committerJuan RP <xtraeme@gmail.com>2014-08-07 17:22:57 +0200
commit53a09fa9d57bad1b074d0f72a302ffc4517d4b0f (patch)
tree0fbaaa59a8e1eb3669bb4ad6bd7925aa493f5253 /core-services
parent18ae61d8157af26fb58041bdfcf8cc405f1a2157 (diff)
downloadrunit-void-53a09fa9d57bad1b074d0f72a302ffc4517d4b0f.tar.gz
runit-void-53a09fa9d57bad1b074d0f72a302ffc4517d4b0f.tar.xz
runit-void-53a09fa9d57bad1b074d0f72a302ffc4517d4b0f.zip
Added "core" services that are run from scripts on stage 1.
- /etc/runit/functions: contains common functions to be used in core-services.
- /etc/runit/core-services: directory containing one-time tasks run in stage 1.
- Added LXC container detection to disable some core services.

This accidentally also fixes the issue of unicode not working in the active
TTY from stage 1.
Diffstat (limited to 'core-services')
-rwxr-xr-xcore-services/00-pseudofs.sh17
-rwxr-xr-xcore-services/02-udev.sh23
-rwxr-xr-xcore-services/03-filesystems.sh49
-rwxr-xr-xcore-services/04-swap.sh10
-rwxr-xr-xcore-services/05-misc.sh25
-rwxr-xr-xcore-services/06-console-setup.sh22
-rwxr-xr-xcore-services/07-kmods.sh11
-rwxr-xr-xcore-services/08-sysctl.sh10
-rwxr-xr-xcore-services/99-cleanup.sh9
9 files changed, 176 insertions, 0 deletions
diff --git a/core-services/00-pseudofs.sh b/core-services/00-pseudofs.sh
new file mode 100755
index 0000000..f0da22f
--- /dev/null
+++ b/core-services/00-pseudofs.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+PATH=/usr/bin:/usr/sbin
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+msg "Mounting pseudo-filesystems...\n"
+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 -m0755 /run/runit /run/lvm /run/user /dev/pts /dev/shm
+mountpoint -q /dev/pts || mount -n -t devpts devpts /dev/pts -o mode=0620,gid=5,nosuid,noexec
+mountpoint -q /dev/shm || mount -n -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev
+mountpoint -q /sys/fs/cgroup || mount -t tmpfs cgroup /sys/fs/cgroup -o mode=0755
+awk '$4==1 { system("mountpoint -q /sys/fs/cgroup/" $1 " || mount -t cgroup -o " $1 ",x-mount.mkdir cgroup /sys/fs/cgroup/" $1) }' /proc/cgroups
diff --git a/core-services/02-udev.sh b/core-services/02-udev.sh
new file mode 100755
index 0000000..1375209
--- /dev/null
+++ b/core-services/02-udev.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+[ -n "$VIRTUALIZATION" ] && return 0
+
+if [ -x /usr/lib/systemd/systemd-udevd ]; then
+    _udevd=/usr/lib/systemd/systemd-udevd
+elif [ -x /usr/sbin/udevd ]; then
+    _udevd=/usr/sbin/udevd
+else
+    msg_warn "cannot find udevd!\n"
+fi
+
+if [ -n "${_udevd}" ]; then
+    msg "Starting udev and waiting for devices to settle...\n"
+    ${_udevd} --daemon
+    udevadm trigger --action=add --type=subsystems
+    udevadm trigger --action=add --type=devices
+    udevadm settle
+fi
diff --git a/core-services/03-filesystems.sh b/core-services/03-filesystems.sh
new file mode 100755
index 0000000..02df01a
--- /dev/null
+++ b/core-services/03-filesystems.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+[ -n "$VIRTUALIZATION" ] && return 0
+
+msg "Remounting rootfs read-only...\n"
+mount -o remount,ro / || emergency_shell
+
+if [ -x /sbin/dmraid ]; then
+    msg "Activating dmraid devices...\n"
+    dmraid -i -ay || emergency_shell
+fi
+
+if [ -x /bin/btrfs ]; then
+    msg "Activating btrfs devices...\n"
+    btrfs device scan || emergency_shell
+fi
+
+if [ -x /sbin/vgchange ]; then
+    msg "Activating LVM devices...\n"
+    vgchange --sysinit -a y || emergency_shell
+fi
+
+if [ -e /etc/crypttab ]; then
+    msg "Activating encrypted devices...\n"
+    awk '/^#/ || /^$/ { next }
+         NF>2 { print "unsupported crypttab: " $0 >"/dev/stderr"; next }
+         { system("cryptsetup luksOpen " $2 " " $1) }' /etc/crypttab
+
+    if [ -x /sbin/vgchange ]; then
+        msg "Activating LVM devices for dm-crypt...\n"
+        vgchange --sysinit -a y || emergency_shell
+    fi
+fi
+
+msg "Checking filesystems:\n"
+fsck -A -T -a -t noopts=_netdev
+if [ $? -gt 1 ]; then
+    emergency_shell
+fi
+
+msg "Mounting rootfs read-write...\n"
+mount -o remount,rw / || emergency_shell
+
+msg "Mounting all non-network filesystems...\n"
+mount -a -t "nosysfs,nonfs,nonfs4,nosmbfs,nocifs" -O no_netdev || emergency_shell
diff --git a/core-services/04-swap.sh b/core-services/04-swap.sh
new file mode 100755
index 0000000..f1db240
--- /dev/null
+++ b/core-services/04-swap.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+[ -n "$VIRTUALIZATION" ] && return 0
+
+msg "Initializing swap...\n"
+swapon -a || emergency_shell
diff --git a/core-services/05-misc.sh b/core-services/05-misc.sh
new file mode 100755
index 0000000..fba6d2a
--- /dev/null
+++ b/core-services/05-misc.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+msg "Setting up loopback interface...\n"
+ip link set up dev lo
+
+if [ -n "$HOSTNAME" ]; then
+    echo "$HOSTNAME" > /proc/sys/kernel/hostname
+elif [ -r /etc/hostname ]; then
+    HOSTNAME=$(cat /etc/hostname)
+    echo "$HOSTNAME" > /proc/sys/kernel/hostname
+fi
+msg "Setting up hostname to '${HOSTNAME}'...\n"
+
+if [ -n "$TIMEZONE" ]; then
+    msg "Setting up timezone to '${TIMEZONE}'...\n"
+    ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
+fi
+
+msg "Initializing random seed...\n"
+cp /var/lib/random-seed /dev/urandom >/dev/null 2>&1 || true
+( umask 077; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 >/dev/null 2>&1 )
diff --git a/core-services/06-console-setup.sh b/core-services/06-console-setup.sh
new file mode 100755
index 0000000..63fea25
--- /dev/null
+++ b/core-services/06-console-setup.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+[ -n "$VIRTUALIZATION" ] && return 0
+
+msg "Setting up TTYs to unicode mode...\n"
+for i in /dev/tty[0-6]; do
+    unicode_start < $i
+done
+
+if [ -n "$FONT" ]; then
+    msg "Setting up TTYs font to '${FONT}'...\n"
+    for i in /dev/tty[0-6]; do
+        setfont ${FONT_MAP:+-m $FONT_MAP} ${FONT_UNIMAP:+-u $FONT_UNIMAP} $FONT -C $i
+    done
+fi
+
+msg "Setting up keymap to '${KEYMAP:-us}'...\n"
+loadkeys -q -u ${KEYMAP:-us}
diff --git a/core-services/07-kmods.sh b/core-services/07-kmods.sh
new file mode 100755
index 0000000..07a5310
--- /dev/null
+++ b/core-services/07-kmods.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+[ -n "$VIRTUALIZATION" ] && return 0
+
+msg "Loading kernel modules...\n"
+modules-load -v ${MODULES} | tr '\n' ' ' | sed 's:insmod [^ ]*/::g; s:\.ko\(\.gz\)\? ::g'
+echo
diff --git a/core-services/08-sysctl.sh b/core-services/08-sysctl.sh
new file mode 100755
index 0000000..febe7bb
--- /dev/null
+++ b/core-services/08-sysctl.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+if [ -x /sbin/sysctl ]; then
+    msg "Loading sysctl(8) settings...\n"
+    sysctl --system
+fi
diff --git a/core-services/99-cleanup.sh b/core-services/99-cleanup.sh
new file mode 100755
index 0000000..8030b4f
--- /dev/null
+++ b/core-services/99-cleanup.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# vim: set ts=4 sw=4 et:
+
+. /etc/runit/functions
+[ -r /etc/rc.conf ] && . /etc/rc.conf
+
+install -m0664 -o root -g utmp /dev/null /run/utmp
+install -dm1777 /tmp/.X11-unix /tmp/.ICE-unix
+rm -f /etc/nologin /forcefsck /forcequotacheck /fastboot