diff --git a/._cfg0002_rc.conf b/._cfg0002_rc.conf new file mode 100644 index 0000000..5cef074 --- /dev/null +++ b/._cfg0002_rc.conf @@ -0,0 +1,227 @@ +# Global OpenRC configuration settings + +# Set to "YES" if you want the rc system to try and start services +# in parallel for a slight speed improvement. When running in parallel we +# prefix the service output with its name as the output will get +# jumbled up. +# WARNING: whilst we have improved parallel, it can still potentially lock +# the boot process. Don't file bugs about this unless you can supply +# patches that fix it without breaking other things! +#rc_parallel="NO" + +# Set rc_interactive to "YES" and you'll be able to press the I key during +# boot so you can choose to start specific services. Set to "NO" to disable +# this feature. This feature is automatically disabled if rc_parallel is +# set to YES. +#rc_interactive="YES" + +# If we need to drop to a shell, you can specify it here. +# If not specified we use $SHELL, otherwise the one specified in /etc/passwd, +# otherwise /bin/sh +# Linux users could specify /sbin/sulogin +rc_shell=/sbin/sulogin + +# Do we allow any started service in the runlevel to satisfy the dependency +# or do we want all of them regardless of state? For example, if net.eth0 +# and net.eth1 are in the default runlevel then with rc_depend_strict="NO" +# both will be started, but services that depend on 'net' will work if either +# one comes up. With rc_depend_strict="YES" we would require them both to +# come up. +#rc_depend_strict="YES" + +# rc_hotplug is a list of services that we allow to be hotplugged. +# By default we do not allow hotplugging. +# A hotplugged service is one started by a dynamic dev manager when a matching +# hardware device is found. +# This service is intrinsically included in the boot runlevel. +# To disable services, prefix with a ! +# Example - rc_hotplug="net.wlan !net.*" +# This allows net.wlan and any service not matching net.* to be plugged. +# Example - rc_hotplug="*" +# This allows all services to be hotplugged +#rc_hotplug="*" + +# rc_logger launches a logging daemon to log the entire rc process to +# /var/log/rc.log +# NOTE: Linux systems require the devfs service to be started before +# logging can take place and as such cannot log the sysinit runlevel. +#rc_logger="YES" + +# Through rc_log_path you can specify a custom log file. +# The default value is: /var/log/rc.log +#rc_log_path="/var/log/rc.log" + +# If you want verbose output for OpenRC, set this to yes. If you want +# verbose output for service foo only, set it to yes in /etc/conf.d/foo. +#rc_verbose=no + +# By default we filter the environment for our running scripts. To allow other +# variables through, add them here. Use a * to allow all variables through. +#rc_env_allow="VAR1 VAR2" + +# By default we assume that all daemons will start correctly. +# However, some do not - a classic example is that they fork and return 0 AND +# then child barfs on a configuration error. Or the daemon has a bug and the +# child crashes. You can set the number of milliseconds start-stop-daemon +# waits to check that the daemon is still running after starting here. +# The default is 0 - no checking. +#rc_start_wait=100 + +# rc_nostop is a list of services which will not stop when changing runlevels. +# This still allows the service itself to be stopped when called directly. +#rc_nostop="" + +# rc will attempt to start crashed services by default. +# However, it will not stop them by default as that could bring down other +# critical services. +#rc_crashed_stop=NO +#rc_crashed_start=YES + +# Set rc_nocolor to yes if you do not want colors displayed in OpenRC +# output. +#rc_nocolor=NO + +############################################################################## +# MISC CONFIGURATION VARIABLES +# There variables are shared between many init scripts + +# Set unicode to YES to turn on unicode support for keyboards and screens. +unicode="YES" + +# This is how long fuser should wait for a remote server to respond. The +# default is 60 seconds, but it can be adjusted here. +#rc_fuser_timeout=60 + +# Below is the default list of network fstypes. +# +# afs ceph cifs coda davfs fuse fuse.sshfs gfs glusterfs lustre ncpfs +# nfs nfs4 ocfs2 shfs smbfs +# +# If you would like to add to this list, you can do so by adding your +# own fstypes to the following variable. +#extra_net_fs_list="" + +############################################################################## +# SERVICE CONFIGURATION VARIABLES +# These variables are documented here, but should be configured in +# /etc/conf.d/foo for service foo and NOT enabled here unless you +# really want them to work on a global basis. +# If your service has characters in its name which are not legal in +# shell variable names and you configure the variables for it in this +# file, those characters should be replaced with underscores in the +# variable names as shown below. + +# Some daemons are started and stopped via start-stop-daemon. +# We can set some things on a per service basis, like the nicelevel. +#SSD_NICELEVEL="-19" + +# Pass ulimit parameters +# If you are using bash in POSIX mode for your shell, note that the +# ulimit command uses a block size of 512 bytes for the -c and -f +# options +#rc_ulimit="-u 30" + +# It's possible to define extra dependencies for services like so +#rc_config="/etc/foo" +#rc_need="openvpn" +#rc_use="net.eth0" +#rc_after="clock" +#rc_before="local" +#rc_provide="!net" + +# You can also enable the above commands here for each service. Below is an +# example for service foo. +#rc_foo_config="/etc/foo" +#rc_foo_need="openvpn" +#rc_foo_after="clock" + +# Below is an example for service foo-bar. Note that the '-' is illegal +# in a shell variable name, so we convert it to an underscore. +# example for service foo-bar. +#rc_foo_bar_config="/etc/foo-bar" +#rc_foo_bar_need="openvpn" +#rc_foo_bar_after="clock" + +# You can also remove dependencies. +# This is mainly used for saying which servies do NOT provide net. +#rc_net_tap0_provide="!net" + +############################################################################## +# LINUX SPECIFIC OPTIONS + +# This is the subsystem type. Valid options on Linux: +# "" - nothing special +# "lxc" - Linux Containers +# "openvz" - Linux OpenVZ +# "prefix" - Prefix +# "uml" - Usermode Linux +# "vserver" - Linux vserver +# "systemd-nspawn" - Container created by the systemd-nspawn utility +# "xen0" - Xen0 Domain +# "xenU" - XenU Domain +# If this is commented out, automatic detection will be used. +# +# This should be set to the value representing the environment this file is +# PRESENTLY in, not the virtualization the environment is capable of. +#rc_sys="" + +# This is the number of tty's used in most of the rc-scripts (like +# consolefont, numlock, etc ...) +rc_tty_number=12 + +############################################################################## +# CGROUPS RESOURCE MANAGEMENT + +# If you have cgroups turned on in your kernel, this switch controls +# whether or not a group for each controller is mounted under +# /sys/fs/cgroup. +# None of the other options in this section work if this is set to "NO". +#rc_controller_cgroups="YES" + +# The following settings allow you to set up values for the cgroup +# controllers for your services. +# They can be set in this file;, however, if you do this, the settings +# will apply to all of your services. +# If you want different settings for each service, place the settings in +# /etc/conf.d/foo for service foo. +# The format is to specify the names of the settings followed by their +# values. Each variable can hold multiple settings. +# For example, you would use this to set the cpu.shares setting in the +# cpu controller to 512 for your service. +# rc_cgroup_cpu=" +# cpu.shares 512 +# " +# +#For more information about the adjustments that can be made with +#cgroups, see Documentation/cgroups/* in the linux kernel source tree. + +# Set the blkio controller settings for this service. +#rc_cgroup_blkio="" + +# Set the cpu controller settings for this service. +#rc_cgroup_cpu="" + +# Add this service to the cpuacct controller (any value means yes). +#rc_cgroup_cpuacct="" + +# Set the cpuset controller settings for this service. +#rc_cgroup_cpuset="" + +# Set the devices controller settings for this service. +#rc_cgroup_devices="" + +# Set the memory controller settings for this service. +#rc_cgroup_memory="" + +# Set the net_prio controller settings for this service. +#rc_cgroup_net_prio="" + +# Set this to YES if yu want all of the processes in a service's cgroup +# killed when the service is stopped or restarted. +# This should not be set globally because it kills all of the service's +# child processes, and most of the time this is undesirable. Please set +# it in /etc/conf.d/. +# To perform this cleanup manually for a stopped service, you can +# execute cgroup_cleanup with /etc/init.d/ cgroup_cleanup or +# rc-service cgroup_cleanup. +# rc_cgroup_cleanup="NO" diff --git a/init.d/._cfg0000_consolefont b/init.d/._cfg0000_consolefont new file mode 100755 index 0000000..5b175a6 --- /dev/null +++ b/init.d/._cfg0000_consolefont @@ -0,0 +1,63 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Sets a font for the consoles." + +depend() +{ + need localmount termencoding + after hotplug bootmisc + keyword -openvz -prefix -systemd-nspawn -uml -vserver -xenu -lxc +} + +start() +{ + ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}} + consolefont=${consolefont:-${CONSOLEFONT}} + unicodemap=${unicodemap:-${UNICODEMAP}} + consoletranslation=${consoletranslation:-${CONSOLETRANSLATION}} + + if [ -z "$consolefont" ]; then + ebegin "Using the default console font" + eend 0 + return 0 + fi + + if [ "$ttyn" = 0 ]; then + ebegin "Skipping font setup (rc_tty_number == 0)" + eend 0 + return 0 + fi + + local x= param= sf_param= retval=0 ttydev=/dev/tty + + # Get additional parameters + if [ -n "$consoletranslation" ]; then + param="$param -m $consoletranslation" + fi + if [ -n "${unicodemap}" ]; then + param="$param -u $unicodemap" + fi + + # Set the console font + ebegin "Setting console font [$consolefont]" + [ -d /dev/vc ] && ttydev=/dev/vc/ + x=1 + while [ $x -le $ttyn ]; do + if ! setfont $consolefont $param -C $ttydev$x >/dev/null; then + retval=1 + break + fi + : $(( x += 1 )) + done + eend $retval + + # Store the font so we can use it ASAP on boot + if [ $retval -eq 0 ] && checkpath -W "$RC_LIBEXECDIR"; then + mkdir -p "$RC_LIBEXECDIR"/console + setfont -O "$RC_LIBEXECDIR"/console/font + fi + + return $retval +} diff --git a/init.d/._cfg0000_dmesg b/init.d/._cfg0000_dmesg new file mode 100755 index 0000000..be6f774 --- /dev/null +++ b/init.d/._cfg0000_dmesg @@ -0,0 +1,18 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2008 Roy Marples +# Released under the 2-clause BSD license. + +description="Set the dmesg level for a cleaner boot" + +depend() +{ + before dev modules + keyword -lxc -prefix -systemd-nspawn -vserver +} + +start() +{ + if [ -n "$dmesg_level" ]; then + dmesg -n$dmesg_level + fi +} diff --git a/init.d/._cfg0000_fsck b/init.d/._cfg0000_fsck new file mode 100755 index 0000000..8f43607 --- /dev/null +++ b/init.d/._cfg0000_fsck @@ -0,0 +1,123 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Check and repair filesystems according to /etc/fstab" +_IFS=" +" + +depend() +{ + use dev clock modules + keyword -jail -openvz -prefix -systemd-nspawn -timeout -vserver -lxc -uml +} + +_abort() { + rc-abort + return 1 +} + +# We should only reboot when first booting +_reboot() { + if [ "$RC_RUNLEVEL" = "$RC_BOOTLEVEL" ]; then + reboot "$@" + _abort || return 1 + fi +} + +_forcefsck() +{ + [ -e /forcefsck ] || get_bootparam forcefsck +} + +start() +{ + local fsck_opts= p= check_extra= + + if [ -e /fastboot ]; then + ewarn "Skipping fsck due to /fastboot" + return 0 + fi + if _forcefsck; then + fsck_opts="$fsck_opts -f" + check_extra="(check forced)" + elif ! yesno ${fsck_on_battery:-YES} && ! on_ac_power; then + ewarn "Skipping fsck due to not being on AC power" + return 0 + fi + + if [ -n "$fsck_passno" ]; then + check_extra="[passno $fsck_passno] $check_extra" + if [ -n "$fsck_mnt" ]; then + eerror "Only 1 of fsck_passno and fsck_mnt must be set!" + return 1 + fi + fi + ebegin "Checking local filesystems $check_extra" + # Append passno mounts + for p in $fsck_passno; do + local IFS="$_IFS" + case "$p" in + [0-9]*) p="=$p";; + esac + set -- "$@" $(fstabinfo --passno "$p") + unset IFS + done + # Append custom mounts + for m in $fsck_mnt ; do + local IFS="$_IFS" + set -- "$@" "$m" + unset IFS + done + + if [ "$RC_UNAME" = Linux ]; then + local skiptypes + skiptypes=$(printf 'no%s,' ${net_fs_list} ${extra_net_fs_list}) + [ "${skiptypes}" = "no," ] && skiptypes="" + fsck_opts="$fsck_opts -C0 -T -t ${skiptypes}noopts=_netdev" + if [ -z "$fsck_passno" -a -z "$fsck_mnt" ]; then + fsck_args=${fsck_args:--A -p} + if echo 2>/dev/null >/.test.$$; then + rm -f /.test.$$ + fsck_opts="$fsck_opts -R" + fi + fi + fi + + trap : INT QUIT + fsck ${fsck_args:--p} $fsck_opts "$@" + case $? in + 0) eend 0; return 0;; + 1) ewend 1 "Filesystems repaired"; return 0;; + 2|3) if [ "$RC_UNAME" = Linux ]; then + ewend 1 "Filesystems repaired, but reboot needed" + _reboot -f + else + ewend 1 "Filesystems still have errors;" \ + "manual fsck required" + _abort + fi;; + 4) if [ "$RC_UNAME" = Linux ]; then + ewend 1 "Fileystem errors left uncorrected, aborting" + _abort + else + ewend 1 "Filesystems repaired, but reboot needed" + _reboot + fi;; + 8) ewend 1 "Operational error"; return 0;; + 12) ewend 1 "fsck interrupted";; + *) eend 2 "Filesystems couldn't be fixed";; + esac + _abort || return 1 +} + +stop() +{ + # Fake function so we always shutdown correctly. + _abort() { return 0; } + _reboot() { return 0; } + _forcefsck() { return 1; } + + yesno $fsck_shutdown && start + return 0 +} diff --git a/init.d/._cfg0000_hostname b/init.d/._cfg0000_hostname new file mode 100755 index 0000000..b6f87b7 --- /dev/null +++ b/init.d/._cfg0000_hostname @@ -0,0 +1,19 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Sets the hostname of the machine." + +depend() { + keyword -prefix -systemd-nspawn -lxc +} + +start() +{ + # HOSTNAME variable used to be defined in caps in conf.d/hostname. + # It is also a magic variable in bash. + hostname=${hostname-${HOSTNAME-localhost}} # checkbashisms: false positive + ebegin "Setting hostname to $hostname" + hostname "$hostname" + eend $? "Failed to set the hostname" +} diff --git a/init.d/._cfg0000_keymaps b/init.d/._cfg0000_keymaps new file mode 100755 index 0000000..3ab4556 --- /dev/null +++ b/init.d/._cfg0000_keymaps @@ -0,0 +1,70 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2008 Roy Marples +# Released under the 2-clause BSD license. + +description="Applies a keymap for the consoles." + +depend() +{ + need localmount termencoding + after bootmisc + keyword -openvz -prefix -systemd-nspawn -uml -vserver -xenu -lxc +} + +start() +{ + ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}} + : ${unicode:=$UNICODE} + : ${keymap:=$KEYMAP} + : ${extended_keymaps:=$EXTENDED_KEYMAPS} + : ${windowkeys:=$SET_WINDOWSKEYS} + : ${fix_euro:=$FIX_EURO} + : ${dumpkeys_charset:=${DUMPKEYS_CHARSET}} + + if [ -z "$keymap" ]; then + eerror "You need to setup keymap in /etc/conf.d/keymaps first" + return 1 + fi + + local ttydev=/dev/tty n= + [ -d /dev/vc ] && ttydev=/dev/vc/ + + # Force linux keycodes for PPC. + if [ -f /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes ]; then + echo 1 > /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes + fi + + local wkeys= kmode="-a" msg="ASCII" + if yesno $unicode; then + kmode="-u" + msg="UTF-8" + fi + yesno $windowkeys && wkeys="windowkeys" + + # Set terminal encoding to either ASCII or UNICODE. + # See utf-8(7) for more information. + ebegin "Setting keyboard mode [$msg]" + n=1 + while [ $n -le $ttyn ]; do + kbd_mode $kmode -C $ttydev$n + : $(( n += 1 )) + done + eend 0 + + ebegin "Loading key mappings [$keymap]" + loadkeys -q $wkeys $keymap $extended_keymaps + eend $? "Error loading key mappings" || return $? + + if yesno $fix_euro; then + ebegin "Fixing font for euro symbol" + # Fix some fonts displaying the Euro, #173528. + echo "altgr keycode 18 = U+20AC" | loadkeys -q - + eend $? + fi + + # Save the keymapping for use immediately at boot + if checkpath -W "$RC_LIBEXECDIR"; then + mkdir -p "$RC_LIBEXECDIR"/console + dumpkeys >"$RC_LIBEXECDIR"/console/keymap + fi +} diff --git a/init.d/._cfg0000_modules b/init.d/._cfg0000_modules new file mode 100755 index 0000000..e959236 --- /dev/null +++ b/init.d/._cfg0000_modules @@ -0,0 +1,63 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Loads a user defined list of kernel modules." + +depend() +{ + use isapnp + keyword -openvz -prefix -systemd-nspawn -vserver -lxc +} + +start() +{ + # Should not fail if kernel do not have module + # support compiled in ... + [ ! -f /proc/modules ] && return 0 + + local KV x y kv_variant_list + KV=$(uname -r) + # full $KV + kv_variant_list="${KV}" + # remove any KV_EXTRA options to just get the full version + x=${KV%%-*} + # now slowly strip them + while [ -n "$x" ] && [ "$x" != "$y" ]; do + kv_variant_list="${kv_variant_list} $x" + y=$x + x=${x%.*} + done + + local list= x= xx= y= args= mpargs= cnt=0 a= + for x in $kv_variant_list ; do + eval list=\$modules_$(shell_var "$x") + [ -n "$list" ] && break + done + [ -z "$list" ] && list=$modules + + for x in $list; do + a=${x#*:} + if [ "$a" = "$x" ]; then + unset mpargs + ebegin "Loading module $x" + else + x=${x%%:*} + mpargs="-o $a" + ebegin "Loading module $x as $a" + fi + aa=$(shell_var "$a") + xx=$(shell_var "$x") + for y in $kv_variant_list ; do + eval args=\$module_${aa}_args_$(shell_var "$y") + [ -n "${args}" ] && break + eval args=\$module_${xx}_args_$(shell_var "$y") + [ -n "${args}" ] && break + done + [ -z "$args" ] && eval args=\$module_${aa}_args + [ -z "$args" ] && eval args=\$module_${xx}_args + eval modprobe -q "$mpargs" "$x" "$args" + eend $? "Failed to load $x" && : $(( cnt += 1 )) + done + einfo "Autoloaded $cnt module(s)" +} diff --git a/init.d/._cfg0000_numlock b/init.d/._cfg0000_numlock new file mode 100755 index 0000000..2cd61aa --- /dev/null +++ b/init.d/._cfg0000_numlock @@ -0,0 +1,42 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Turns numlock on for the consoles." + +ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}} + +depend() +{ + need localmount + keyword -openvz -prefix -systemd-nspawn -vserver -lxc +} + +_setleds() +{ + [ -z "$1" ] && return 1 + + local dev=/dev/tty t= i=1 retval=0 + [ -d /dev/vc ] && dev=/dev/vc/ + + while [ $i -le $ttyn ]; do + setleds -D "$1"num < $dev$i || retval=1 + : $(( i += 1 )) + done + + return $retval +} + +start() +{ + ebegin "Enabling numlock on ttys" + _setleds + + eend $? "Failed to enable numlock" +} + +stop() +{ + ebegin "Disabling numlock on ttys" + _setleds - + eend $? "Failed to disable numlock" +} diff --git a/init.d/._cfg0000_root b/init.d/._cfg0000_root new file mode 100755 index 0000000..550bcf9 --- /dev/null +++ b/init.d/._cfg0000_root @@ -0,0 +1,53 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Mount the root fs read/write" + +depend() +{ + need fsck + keyword -jail -openvz -prefix -systemd-nspawn -vserver -lxc +} + +start() +{ + case ",$(fstabinfo -o /)," in + *,ro,*) + ;; + *) + # Check if the rootfs isn't already writable. + if checkpath -W /; then + rm -f /fastboot /forcefsck + else + ebegin "Remounting root filesystem read/write" + case "$RC_UNAME" in + Linux) + mount -n -o remount,rw / + ;; + *) + mount -u -o rw / + ;; + esac + eend $? "Root filesystem could not be mounted read/write" + if [ $? -eq 0 ]; then + rm -f /fastboot /forcefsck + fi + fi + ;; + esac + + ebegin "Remounting filesystems" + local mountpoint + for mountpoint in $(fstabinfo); do + case "${mountpoint}" in + /) + ;; + /*) + mountinfo -q "${mountpoint}" && \ + fstabinfo --remount "${mountpoint}" + ;; + esac + done + eend 0 +} diff --git a/init.d/._cfg0000_swap b/init.d/._cfg0000_swap new file mode 100755 index 0000000..bae812b --- /dev/null +++ b/init.d/._cfg0000_swap @@ -0,0 +1,36 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +depend() +{ + before localmount + keyword -jail -openvz -prefix -systemd-nspawn -vserver -lxc +} + +start() +{ + ebegin "Activating swap devices" + case "$RC_UNAME" in + Linux) swapon -a -e >/dev/null;; + NetBSD|OpenBSD) swapctl -A -t noblk >/dev/null;; + *) swapon -a >/dev/null;; + esac + eend 0 # If swapon has nothing todo it errors, so always return 0 +} + +stop() +{ + ebegin "Deactivating swap devices" + + # Try to unmount all tmpfs filesystems not in use, else a deadlock may + # occur. As $RC_SVCDIR may also be tmpfs we cd to it to lock it + cd "$RC_SVCDIR" + umount -a -t tmpfs 2>/dev/null + + case "$RC_UNAME" in + NetBSD|OpenBSD) swapctl -U -t noblk >/dev/null;; + *) swapoff -a >/dev/null;; + esac + eend 0 +} diff --git a/init.d/._cfg0000_swapfiles b/init.d/._cfg0000_swapfiles new file mode 100755 index 0000000..5ab4b36 --- /dev/null +++ b/init.d/._cfg0000_swapfiles @@ -0,0 +1,39 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +depend() +{ + need localmount + keyword -jail -openvz -prefix -systemd-nspawn -vserver -lxc +} + +start() +{ + ebegin "Activating additional swap space" + case "$RC_UNAME" in + NetBSD|OpenBSD) swapctl -A -t noblk >/dev/null;; + *) swapon -a >/dev/null;; + esac + eend 0 # If swapon has nothing todo it errors, so always return 0 +} + +stop() +{ + ebegin "Deactivating additional swap space" + case "$RC_UNAME" in + Linux) + if [ -e /proc/swaps ]; then + while read filename type rest; do + case "$type" in + file) swapoff $filename >/dev/null;; + esac + case "$filename" in + /dev/loop*) swapoff $filename >/dev/null;; + esac + done < /proc/swaps + fi + ;; + esac + eend 0 +} diff --git a/init.d/._cfg0000_termencoding b/init.d/._cfg0000_termencoding new file mode 100755 index 0000000..85f9df3 --- /dev/null +++ b/init.d/._cfg0000_termencoding @@ -0,0 +1,48 @@ +#!/sbin/openrc-run +# Copyright (c) 2008-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Configures terminal encoding." + +ttyn=${rc_tty_number:-${RC_TTY_NUMBER:-12}} +: ${unicode:=${UNICODE}} + +depend() +{ + keyword -lxc -openvz -prefix -systemd-nspawn -uml -vserver -xenu + use root + after bootmisc +} + +start() +{ + local ttydev=/dev/tty n= + [ -d /dev/vc ] && ttydev=/dev/vc/ + + # Set terminal encoding to either ASCII or UNICODE. + # See utf-8(7) for more information. + local termencoding="%@" termmsg="ASCII" + if yesno ${unicode}; then + termencoding="%G" + termmsg="UTF-8" + fi + + ebegin "Setting terminal encoding [$termmsg]" + n=1 + while [ ${n} -le "$ttyn" ]; do + printf "\033%s" "$termencoding" >$ttydev$n + : $(( n += 1 )) + done + + # Save the encoding for use immediately at boot + if checkpath -W "$RC_LIBEXECDIR"; then + mkdir -p "$RC_LIBEXECDIR"/console + if yesno ${unicode:-${UNICODE}}; then + echo "" > "$RC_LIBEXECDIR"/console/unicode + else + rm -f "$RC_LIBEXECDIR"/console/unicode + fi + fi + + eend 0 +} diff --git a/init.d/._cfg0000_urandom b/init.d/._cfg0000_urandom new file mode 100755 index 0000000..d6bb1dd --- /dev/null +++ b/init.d/._cfg0000_urandom @@ -0,0 +1,45 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +: ${urandom_seed:=${URANDOM_SEED:-/var/lib/misc/random-seed}} +description="Initializes the random number generator." + +depend() +{ + need localmount + keyword -jail -lxc -openvz -prefix -systemd-nspawn +} + +save_seed() +{ + local psz=1 + + if [ -e /proc/sys/kernel/random/poolsize ]; then + : $(( psz = $(cat /proc/sys/kernel/random/poolsize) / 4096 )) + fi + + ( # sub shell to prevent umask pollution + umask 077 + dd if=/dev/urandom of="$urandom_seed" count=${psz} 2>/dev/null + ) +} + +start() +{ + [ -c /dev/urandom ] || return + if [ -f "$urandom_seed" ]; then + ebegin "Initializing random number generator" + cat "$urandom_seed" > /dev/urandom + eend $? "Error initializing random number generator" + fi + rm -f "$urandom_seed" && save_seed + return 0 +} + +stop() +{ + ebegin "Saving random seed" + save_seed + eend $? "Failed to save random seed" +} diff --git a/init.d/._cfg0001_bootmisc b/init.d/._cfg0001_bootmisc new file mode 100755 index 0000000..cd9f457 --- /dev/null +++ b/init.d/._cfg0001_bootmisc @@ -0,0 +1,243 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +depend() +{ + need localmount + before logger + after clock root sysctl + keyword -prefix -timeout +} + +: ${wipe_tmp:=${WIPE_TMP:-yes}} +: ${log_dmesg:=${LOG_DMESG:-yes}} + +cleanup_tmp_dir() +{ + local dir="$1" + + if ! [ -d "$dir" ]; then + mkdir -p "$dir" || return $? + fi + checkpath -W "$dir" || return 1 + chmod a+rwt "$dir" 2> /dev/null + cd "$dir" || return 1 + if yesno $wipe_tmp; then + ebegin "Wiping $dir directory" + + # Faster than raw find + if ! rm -rf -- [!ajlq\.]* 2>/dev/null ; then + # Blah, too many files + find . -maxdepth 1 -name '[!ajlq\.]*' -exec rm -rf -- {} + + fi + + # pam_mktemp creates a .private directory within which + # each user gets a private directory with immutable + # bit set; remove the immutable bit before trying to + # remove it. + [ -d /tmp/.private ] && chattr -R -a /tmp/.private 2> /dev/null + + # Prune the paths that are left + find . -maxdepth 1 \ + ! -name . \ + ! -name lost+found \ + ! -name quota.user \ + ! -name aquota.user \ + ! -name quota.group \ + ! -name aquota.group \ + ! -name journal \ + -exec rm -rf -- {} + + eend 0 + else + ebegin "Cleaning $dir directory" + rm -rf -- .X*-lock esrv* kio* \ + jpsock.* .fam* .esd* \ + orbit-* ssh-* ksocket-* \ + .*-unix + eend 0 + fi +} + +cleanup_var_run_dir() +{ + ebegin "Cleaning /var/run" + for x in $(find /var/run ! -type d ! -name utmp \ + ! -name random-seed ! -name dev.db \ + ! -name ld-elf.so.hints ! -name ld.so.hints); + do + # Clean stale sockets + if [ -S "$x" ]; then + if command -v fuser >/dev/null 2>&1; then + fuser "$x" >/dev/null 2>&1 || rm -- "$x" + else + rm -- "$x" + fi + fi + [ ! -f "$x" ] && continue + # Do not remove pidfiles of already running daemons + case "$x" in + *.pid) + start-stop-daemon --test --quiet \ + --stop --pidfile "$x" && continue + ;; + esac + rm -f -- "$x" + done + eend 0 +} + +mkutmp() +{ + : >"$1" + # Not all systems have the utmp group + chgrp utmp "$1" 2>/dev/null + chmod 0664 "$1" +} + +migrate_to_run() +{ + src="$1" + dst="$2" + if [ -L $src -a "$(readlink -f $src)" != $dst ]; then + ewarn "$src does not point to $dst." + ewarn "Setting $src to point to $dst." + rm $src + elif [ ! -L $src -a -d $src ]; then + ebegin "Migrating $src to $dst" + cp -a $src/* $dst/ + rm -rf $src + eend $? + fi + # If $src doesn't exist at all, just run this + if [ ! -e $src ]; then + ln -s $dst $src + fi +} + +clean_run() +{ + [ "$RC_SYS" = VSERVER -o "$RC_SYS" = LXC ] && return 0 + local dir + # If / is still read-only due to a problem, this will fail! + if ! checkpath -W /; then + eerror "/ is not writable; unable to clean up underlying /run" + return 1 + fi + if ! checkpath -W /tmp; then + eerror "/tmp is not writable; unable to clean up underlying /run" + return 1 + fi + # Now we know that we can modify /tmp and / + # if mktemp -d fails, it returns an EMPTY string + # STDERR: mktemp: failed to create directory via template ‘/tmp/tmp.XXXXXXXXXX’: Read-only file system + # STDOUT: '' + rc=0 + dir=$(mktemp -d) + if [ -n "$dir" -a -d $dir -a -w $dir ]; then + mount --bind / $dir && rm -rf $dir/run/* || rc=1 + umount $dir + rm -rf $dir + else + rc=1 + fi + if [ $rc -ne 0 ]; then + eerror "Could not clean up underlying /run on /" + return 1 + fi +} + +start() +{ + # Remove any added console dirs + if checkpath -W "$RC_LIBEXECDIR"; then + rm -rf "$RC_LIBEXECDIR"/console/* + fi + + local logw=false runw=false extra= + # Ensure that our basic dirs exist + if [ "$RC_UNAME" = Linux ]; then + # Satisfy Linux FHS + extra=/var/lib/misc + if [ ! -d /run ]; then + extra="/var/run $extra" + fi + else + extra=/var/run + fi + for x in /var/log /tmp $extra; do + if ! [ -d $x ]; then + if ! mkdir -p $x; then + eend 1 "failed to create needed directory $x" + return 1 + fi + fi + done + + if [ "$RC_UNAME" = Linux -a -d /run ]; then + migrate_to_run /var/lock /run/lock + migrate_to_run /var/run /run + clean_run + fi + + if checkpath -W /var/run; then + ebegin "Creating user login records" + local xtra= + [ "$RC_UNAME" = NetBSD ] && xtra=x + for x in "" $xtra; do + mkutmp /var/run/utmp$x + done + [ -e /var/log/wtmp ] || mkutmp /var/log/wtmp + eend 0 + + mountinfo -q -f tmpfs /var/run || cleanup_var_run_dir + fi + + # Clean up /tmp directories + local tmp= + for tmp in ${clean_tmp_dirs:-${wipe_tmp_dirs-/tmp}}; do + mountinfo -q -f tmpfs "$tmp" || cleanup_tmp_dir "$tmp" + done + + if checkpath -W /tmp; then + # Make sure our X11 stuff have the correct permissions + # Omit the chown as bootmisc is run before network is up + # and users may be using lame LDAP auth #139411 + rm -rf /tmp/.ICE-unix /tmp/.X11-unix + mkdir -p /tmp/.ICE-unix /tmp/.X11-unix + chmod 1777 /tmp/.ICE-unix /tmp/.X11-unix + if [ -x /sbin/restorecon ]; then + restorecon /tmp/.ICE-unix /tmp/.X11-unix + fi + fi + + if yesno $log_dmesg; then + if $logw || checkpath -W /var/log; then + # Create an 'after-boot' dmesg log + case "$RC_SYS" in + VSERVER|OPENVZ|LXC|SYSTEMD-NSPAWN) ;; + *) + dmesg > /var/log/dmesg + chmod 640 /var/log/dmesg + ;; + esac + fi + fi + + return 0 +} + +stop() +{ + # Write a halt record if we're shutting down + if [ "$RC_RUNLEVEL" = shutdown ]; then + [ "$RC_UNAME" = Linux ] && halt -w + if [ "$RC_SYS" = OPENVZ ]; then + yesno $RC_REBOOT && printf "" >/reboot + fi + fi + + return 0 +} + +# vim: ft=sh diff --git a/init.d/._cfg0001_devfs b/init.d/._cfg0001_devfs new file mode 100755 index 0000000..294f343 --- /dev/null +++ b/init.d/._cfg0001_devfs @@ -0,0 +1,121 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2008 Roy Marples +# Released under the 2-clause BSD license. + +description="Set up the /dev directory" + +depend() +{ + provide dev-mount + before dev + keyword -prefix -systemd-nspawn -vserver -lxc +} + +mount_dev() +{ + local action=--mount devfstype msg=Mounting + # Some devices require exec, Bug #92921 + local mountopts="exec,nosuid,mode=0755" + if yesno ${skip_mount_dev:-no} ; then + einfo "/dev will not be mounted due to user request" + return 0 + fi + if mountinfo -q /dev; then + action=--remount + mountopts="remount,$mountopts" + msg=Remounting + fi + if fstabinfo -q /dev; then + ebegin "$msg /dev according to /etc/fstab" + fstabinfo -q $action /dev + eend $? + return 0 + fi + if grep -q devtmpfs /proc/filesystems; then + devfstype=devtmpfs + mountopts="$mountopts,size=10M" + elif grep -q tmpfs /proc/filesystems; then + devfstype=tmpfs + mountopts="$mountopts,size=10M" + fi + if [ -n "$devfstype" ]; then + ebegin "$msg $devfstype on /dev" + mount -n -t $devfstype -o $mountopts dev /dev + eend $? + else + ewarn "This kernel does not have devtmpfs or tmpfs support, and there" + ewarn "is no entry for /dev in fstab." + ewarn "This means /dev will not be mounted." + ewarn "To avoid this message, set CONFIG_DEVTMPFS or CONFIG_TMPFS to y" + ewarn "in your kernel configuration or see /etc/conf.d/devfs" + fi + return 0 +} + +seed_dev() +{ + # Seed /dev with some things that we know we need + + # 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 + + # Mount required directories as user may not have them in /etc/fstab + for x in \ + "mqueue /dev/mqueue 1777 ,nodev mqueue" \ + "devpts /dev/pts 0755 ,gid=5,mode=0620 devpts" \ + "tmpfs /dev/shm 1777 ,nodev,mode=1777 shm" \ + ; do + set -- $x + grep -Eq "[[:space:]]+$1$" /proc/filesystems || continue + mountinfo -q $2 && continue + + if [ ! -d $2 ]; then + mkdir -m $3 -p $2 >/dev/null 2>&1 || \ + ewarn "Could not create $2!" + fi + + if [ -d $2 ]; then + ebegin "Mounting $2" + if ! fstabinfo --mount $2; then + mount -n -t $1 -o noexec,nosuid$4 $5 $2 + fi + eend $? + fi + done +} + +restorecon_dev() +{ + if [ -x /sbin/restorecon ]; then + ebegin "Restoring SELinux contexts in /dev" + restorecon -rF /dev >/dev/null 2>&1 + eend $? + fi + + return 0 +} + +start() +{ + mount_dev + seed_dev + restorecon_dev + return 0 +} diff --git a/init.d/._cfg0001_hwclock b/init.d/._cfg0001_hwclock new file mode 100755 index 0000000..6da7f10 --- /dev/null +++ b/init.d/._cfg0001_hwclock @@ -0,0 +1,141 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2008 Roy Marples +# Released under the 2-clause BSD license. + +extra_commands="save show" + +description="Sets the local clock to UTC or Local Time." +description_save="Saves the current time in the BIOS." +description_show="Displays the current time in the BIOS." + +: ${clock_adjfile:=${CLOCK_ADJFILE}} +: ${clock_args:=${CLOCK_OPTS}} +: ${clock_systohc:=${CLOCK_SYSTOHC}} +: ${clock:=${CLOCK:-UTC}} +if [ "$clock" = "UTC" ]; then + utc="UTC" + utc_cmd="--utc" +else + utc="Local Time" + utc_cmd="--localtime" +fi + +depend() +{ + provide clock + if yesno $clock_adjfile; then + use root + else + before * + fi + keyword -openvz -prefix -systemd-nspawn -uml -vserver -xenu -lxc +} + +setupopts() +{ + case "$(uname -m)" in + s390*) + utc="s390" + ;; + *) + if [ -e /proc/devices ] && \ + grep -q " cobd$" /proc/devices + then + utc="coLinux" + fi + ;; + esac + + case "$utc" in + UTC|Local" "Time);; + *) unset utc_cmd;; + esac +} + +# hwclock doesn't always return non zero on error +_hwclock() +{ + local err="$(hwclock "$@" 2>&1 >/dev/null)" + + [ -z "$err" ] && return 0 + echo "${err}" >&2 + return 1 +} + +start() +{ + local retval=0 errstr="" + setupopts + + if [ -z "$utc_cmd" ]; then + ewarn "Not setting clock for $utc system" + return 0 + fi + + ebegin "Setting system clock using the hardware clock [$utc]" + if [ -e /proc/modules ]; then + local rtc= + for rtc in /dev/rtc /dev/rtc[0-9]*; do + [ -e "$rtc" ] && break + done + if [ ! -e "${rtc}" ]; then + modprobe -q rtc-cmos || modprobe -q rtc || modprobe -q genrtc + fi + fi + + # Always set the kernel's time zone. + _hwclock --systz $utc_cmd $clock_args + : $(( retval += $? )) + + if [ -e /etc/adjtime ] && yesno $clock_adjfile; then + _hwclock --adjust $utc_cmd + : $(( retval += $? )) + fi + + if yesno ${clock_hctosys:-YES}; then + _hwclock --hctosys $utc_cmd $clock_args + : $(( retval += $? )) + fi + + eend $retval "Failed to set the system clock" + + return 0 +} + +stop() +{ + # Don't tweak the hardware clock on LiveCD halt. + [ -n "$CDBOOT" ] && return 0 + yesno ${clock_systohc:-YES} || return 0 + + local retval=0 errstr="" + setupopts + + [ -z "$utc_cmd" ] && return 0 + + ebegin "Setting hardware clock using the system clock" "[$utc]" + + if ! yesno $clock_adjfile; then + # Some implementations don't handle adjustments + if LC_ALL=C hwclock --help 2>&1 | grep -q "\-\-noadjfile"; then + utc_cmd="$utc_cmd --noadjfile" + fi + fi + + _hwclock --systohc $utc_cmd $clock_args + retval=$? + + eend $retval "Failed to sync clocks" +} + +save() +{ + clock_systohc=yes + stop +} + +show() +{ + setupopts + hwclock --show "$utc_cmd" $clock_args +} diff --git a/init.d/._cfg0001_local b/init.d/._cfg0001_local new file mode 100755 index 0000000..31e429e --- /dev/null +++ b/init.d/._cfg0001_local @@ -0,0 +1,86 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2008 Roy Marples +# Released under the 2-clause BSD license. + +description="Executes user programs in /etc/local.d" + +depend() +{ + after * + keyword -timeout +} + +start() +{ + ebegin "Starting local" + + local file has_errors=0 redirect retval + yesno $rc_verbose || redirect='> /dev/null 2>&1' + eindent + for file in /etc/local.d/*.start; do + if [ -x "${file}" ]; then + vebegin "Executing \"${file}\"" + eval "${file}" $redirect + retval=$? + if [ ${retval} -ne 0 ]; then + has_errors=1 + fi + veend ${retval} "Execution of \"${file}\" failed." + fi + done + eoutdent + + if command -v local_start >/dev/null 2>&1; then + ewarn "\"/etc/conf.d/local\" should be removed." + ewarn "Please move the code from the local_start function" + ewarn "to executable scripts with an .start extension" + ewarn "in \"/etc/local.d\"" + local_start + fi + + eend ${has_errors} + + # We have to end with a zero exit code, because a failed execution + # of an executable /etc/local.d/*.start file shouldn't result in + # marking the local service as failed. Otherwise we are unable to + # execute any executable /etc/local.d/*.stop file, because a failed + # marked service cannot be stopped (and the stop function would + # actually call the executable /etc/local.d/*.stop file(s)). + return 0 +} + +stop() +{ + ebegin "Stopping local" + + local file has_errors=0 redirect retval + yesno $rc_verbose || redirect='> /dev/null 2>&1' + eindent + for file in /etc/local.d/*.stop; do + if [ -x "${file}" ]; then + vebegin "Executing \"${file}\"" + eval "${file}" $redirect + retval=$? + if [ ${retval} -ne 0 ]; then + has_errors=1 + fi + veend ${retval} "Execution of \"${file}\" failed." + fi + done + eoutdent + + if command -v local_stop >/dev/null 2>&1; then + ewarn "\"/etc/conf.d/local\" should be removed." + ewarn "Please move the code from the local_stop function" + ewarn "to executable scripts with an .stop extension" + ewarn "in \"/etc/local.d\"" + local_stop + fi + + eend ${has_errors} + + # An executable /etc/local.d/*.stop file which failed with a + # non-zero exit status is not a reason to mark this service + # as failed, therefore we have to end with a zero exit code. + return 0 +} diff --git a/init.d/._cfg0001_localmount b/init.d/._cfg0001_localmount new file mode 100755 index 0000000..ae9d3cf --- /dev/null +++ b/init.d/._cfg0001_localmount @@ -0,0 +1,112 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Mounts disks and swap according to /etc/fstab." + +depend() +{ + need fsck + use lvm modules mtab + after lvm modules + keyword -jail -prefix -systemd-nspawn -vserver -lxc +} + +start() +{ + # Mount local filesystems in /etc/fstab. + local types="noproc" x= no_netdev= + for x in $net_fs_list $extra_net_fs_list; do + types="${types},no${x}" + done + + if [ "$RC_UNAME" = Linux ]; then + no_netdev="-O no_netdev" + if mountinfo -q /usr; then + touch "$RC_SVCDIR"/usr_premounted + fi + fi + ebegin "Mounting local filesystems" + mount -at "$types" $no_netdev + eend $? "Some local filesystem failed to mount" + + # Always return 0 - some local mounts may not be critical for boot + return 0 +} + +stop() +{ + yesno $RC_GOINGDOWN || return 0 + # We never unmount / or /dev or $RC_SVCDIR + + # Bug 381783 + local rc_svcdir=$(printf '%s\n' "$RC_SVCDIR" | sed 's:/lib\(32\|64\)\?/:/lib(32|64)?/:g') + + local x= no_umounts_r="/|/dev|/dev/.*|${rc_svcdir}" + no_umounts_r="${no_umounts_r}|/bin|/sbin|/lib(32|64)?|/libexec" + # RC_NO_UMOUNTS is an env var that can be set by plugins + local IFS="$IFS:" + for x in $no_umounts $RC_NO_UMOUNTS; do + no_umounts_r="$no_umounts_r|$x" + done + + if [ "$RC_UNAME" = Linux ]; then + no_umounts_r="$no_umounts_r|/proc|/proc/.*|/run|/sys|/sys/.*" + if [ -e "$rc_svcdir"/usr_premounted ]; then + no_umounts_r="$no_umounts_r|/usr" + fi + fi + no_umounts_r="^($no_umounts_r)$" + + # Flush all pending disk writes now + sync + + . "$RC_LIBEXECDIR"/sh/rc-mount.sh + + if [ "$RC_UNAME" = Linux ] && [ -d /sys/fs/aufs ] ; then + #if / is aufs we remount it noxino during shutdown + if mountinfo -q -f '^aufs$' / ; then + mount -o remount,noxino,rw / + sync + fi + + local aufs_branch aufs_mount_dir aufs_mount_point aufs_si_dir aufs_si_id + for aufs_si_dir in /sys/fs/aufs/*; do + aufs_mount_dir=${aufs_si_dir#/sys/fs/aufs/} + aufs_si_id="$(printf "%s" $aufs_mount_dir | sed 's/_/=/g')" + aufs_mount_point="$(mountinfo -o ${aufs_si_id})" + for x in $aufs_si_dir/br[0-9][0-9][0-9]; do + aufs_branch=$(sed 's/=.*//g' $x) + eindent + if ! mount -o "remount,del:$aufs_branch" "$aufs_mount_point" > /dev/null 2>&1; then + ewarn "Failed to remove branch $aufs_branch from aufs \ + $aufs_mount_point" + fi + eoutdent + sync + done + done + fi + + # Umount loop devices + einfo "Unmounting loop devices" + eindent + do_unmount "umount -d" --skip-point-regex "$no_umounts_r" \ + --node-regex "^/dev/loop" + eoutdent + + # Now everything else, except network filesystems as the + # network should be down by this point. + einfo "Unmounting filesystems" + eindent + local fs= + for x in $net_fs_list $extra_net_fs_list; do + fs="$fs${fs:+|}$x" + done + [ -n "$fs" ] && fs="^($fs)$" + do_unmount umount --skip-point-regex "$no_umounts_r" \ + "${fs:+--skip-fstype-regex}" $fs --nonetdev + eoutdent + + return 0 +} diff --git a/init.d/._cfg0001_loopback b/init.d/._cfg0001_loopback new file mode 100755 index 0000000..2b3b092 --- /dev/null +++ b/init.d/._cfg0001_loopback @@ -0,0 +1,35 @@ +#!/sbin/openrc-run +# Copyright (c) 2013 William Hubbs +# Released under the 2-clause BSD license. + +description="Configures the loopback interface." + +depend() +{ + keyword -jail -prefix -systemd-nspawn -vserver +} + +start() +{ + if [ "$RC_UNAME" = Linux ]; then + ebegin "Bringing up network interface lo" + if command -v ip > /dev/null 2>&1; then + ip addr add 127.0.0.1/8 dev lo brd + scope host + ip route add 127.0.0.0/8 dev lo scope host + ip link set lo up + else + ifconfig lo 127.0.0.1 netmask 255.0.0.0 + route add -net 127.0.0.0 netmask 255.0.0.0 gw 127.0.0.1 + fi + else + ebegin "Bringing up network interface lo0" + ifconfig lo0 127.0.0.1 netmask 255.0.0.0 + route -q add -inet 127.0.0.0 -netmask 255.0.0.0 127.0.0.1 + fi + eend $? +} + +stop() +{ + return 0 +} diff --git a/init.d/._cfg0001_mount-ro b/init.d/._cfg0001_mount-ro new file mode 100755 index 0000000..b2f3a53 --- /dev/null +++ b/init.d/._cfg0001_mount-ro @@ -0,0 +1,49 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Re-mount filesytems read-only for a clean reboot." + +depend() +{ + need killprocs savecache + keyword -openvz -prefix -systemd-nspawn -vserver -lxc +} + +start() +{ + local ret=0 + + # Flush all pending disk writes now + sync + + ebegin "Remounting remaining filesystems read-only" + # We need the do_unmount function + . "$RC_LIBEXECDIR"/sh/rc-mount.sh + eindent + + # Bug 381783 + local rc_svcdir=$(echo $RC_SVCDIR | sed 's:/lib\(32\|64\)\?/:/lib(32|64)?/:g') + + local m="/dev|/dev/.*|/proc|/proc.*|/sys|/sys/.*|/run|${rc_svcdir}" x= fs= + m="$m|/bin|/sbin|/lib(32|64)?|/libexec" + # RC_NO_UMOUNTS is an env var that can be set by plugins + local IFS="$IFS:" + for x in $no_umounts $RC_NO_UMOUNTS; do + m="$m|$x" + done + m="^($m)$" + fs= + for x in $net_fs_list $extra_net_fs_list; do + fs="$fs${fs:+|}$x" + done + [ -n "$fs" ] && fs="^($fs)$" + do_unmount "umount -r" \ + --skip-point-regex "$m" \ + "${fs:+--skip-fstype-regex}" $fs --nonetdev + ret=$? + + eoutdent + + eend $ret +} diff --git a/init.d/._cfg0001_mtab b/init.d/._cfg0001_mtab new file mode 100755 index 0000000..1389858 --- /dev/null +++ b/init.d/._cfg0001_mtab @@ -0,0 +1,41 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2008 Roy Marples +# Released under the 2-clause BSD license. + +description="Update /etc/mtab to match what the kernel knows about" + +depend() +{ + need root + keyword -prefix -systemd-nspawn +} + +start() +{ + [ -L /etc/mtab ] && return 0 + local rc=0 + ebegin "Updating /etc/mtab" + if ! checkpath -W /etc; then + rc=1 + elif [ ! -e /etc/mtab ]; then + ln -snf /proc/self/mounts /etc/mtab + else + ewarn "The support for updating /etc/mtab as a file is" + ewarn "deprecated and will be removed in the future." + ewarn "Please run the following command as root on your system." + ewarn + ewarn "ln -snf /proc/self/mounts /etc/mtab" + ewarn + + # With / as tmpfs we cannot umount -at tmpfs in localmount as that + # makes / readonly and dismounts all tmpfs even if in use which is + # not good. Luckily, umount uses /etc/mtab instead of /proc/mounts + # which allows this hack to work. + grep -v "^[! ]* / tmpfs " /proc/mounts > /etc/mtab + + # Remove stale backups + rm -f /etc/mtab~ /etc/mtab~~ + fi + eend $rc "/etc is not writable; unable to create /etc/mtab" + return 0 +} diff --git a/init.d/._cfg0001_netmount b/init.d/._cfg0001_netmount new file mode 100755 index 0000000..7949d68 --- /dev/null +++ b/init.d/._cfg0001_netmount @@ -0,0 +1,62 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Mounts network shares according to /etc/fstab." + +depend() +{ + config /etc/fstab + use afc-client amd nfsclient autofs openvpn + use dns + keyword -jail -prefix -systemd-nspawn -vserver -lxc +} + +start() +{ + local x= fs= rc= + for x in $net_fs_list $extra_net_fs_list; do + fs="$fs${fs:+,}$x" + done + + ebegin "Mounting network filesystems" + mount -at $fs + rc=$? + if [ "$RC_UNAME" = Linux ]; then + mount -a -O _netdev + rc=$? + fi + ewend $rc "Could not mount all network filesystems" + return 0 +} + +stop() +{ + local x= fs= + + ebegin "Unmounting network filesystems" + . "$RC_LIBEXECDIR"/sh/rc-mount.sh + + for x in $net_fs_list $extra_net_fs_list; do + fs="$fs${fs:+,}$x" + done + if [ -n "$fs" ]; then + umount -at $fs || eerror "Failed to simply unmount filesystems" + fi + + eindent + fs= + for x in $net_fs_list $extra_net_fs_list; do + fs="$fs${fs:+|}$x" + done + [ -n "$fs" ] && fs="^($fs)$" + do_unmount umount ${fs:+--fstype-regex} $fs --netdev + retval=$? + + eoutdent + if [ "$RC_UNAME" = Linux ]; then + umount -a -O _netdev + retval=$? + fi + eend $retval "Failed to unmount network filesystems" +} diff --git a/init.d/._cfg0001_procfs b/init.d/._cfg0001_procfs new file mode 100755 index 0000000..57c0017 --- /dev/null +++ b/init.d/._cfg0001_procfs @@ -0,0 +1,27 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Mounts misc filesystems in /proc." + +depend() +{ + use modules devfs + need localmount + keyword -openvz -prefix -systemd-nspawn -vserver -lxc +} + +start() +{ + # Setup Kernel Support for miscellaneous Binary Formats + if [ -d /proc/sys/fs/binfmt_misc -a ! -e /proc/sys/fs/binfmt_misc/register ]; then + modprobe -q binfmt-misc + if grep -qs binfmt_misc /proc/filesystems; then + ebegin "Mounting misc binary format filesystem" + mount -t binfmt_misc -o nodev,noexec,nosuid \ + binfmt_misc /proc/sys/fs/binfmt_misc + eend $? + fi + fi + return 0 +} diff --git a/init.d/._cfg0001_savecache b/init.d/._cfg0001_savecache new file mode 100755 index 0000000..f3caa0a --- /dev/null +++ b/init.d/._cfg0001_savecache @@ -0,0 +1,49 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Saves the caches OpenRC uses to non volatile storage" + +start() +{ + if [ -e "$RC_SVCDIR"/clock-skewed ]; then + ewarn "WARNING: clock skew detected!" + if ! yesno "${RC_GOINGDOWN}"; then + eerror "Not saving deptree cache" + return 1 + fi + fi + if ! checkpath -W "$RC_LIBEXECDIR"; then + ewarn "WARNING: ${RC_LIBEXECDIR} is not writable!" + if ! yesno "${RC_GOINGDOWN}"; then + ewarn "Unable to save deptree cache" + return 1 + fi + return 0 + fi + ebegin "Saving dependency cache" + local rc= + if [ ! -d "$RC_LIBEXECDIR"/cache ]; then + rm -rf "$RC_LIBEXECDIR"/cache + if ! mkdir -p "$RC_LIBEXECDIR"/cache; then + rc=$? + if yesno "${RC_GOINGDOWN}"; then + rc=0 + fi + eend $rc "Unable to create $RC_SVCDIR/cache" + return $rc + fi + fi + local save= + for x in deptree depconfig shutdowntime softlevel nettree rc.log; do + [ -e "$RC_SVCDIR/$x" ] && save="$save $RC_SVCDIR/$x" + done + if [ -n "$save" ]; then + cp -p $save "$RC_LIBEXECDIR"/cache 2>/dev/null + fi + rc=$? + if yesno "${RC_GOINGDOWN}"; then + rc=0 + fi + eend $rc +} diff --git a/init.d/._cfg0001_swclock b/init.d/._cfg0001_swclock new file mode 100755 index 0000000..d26621a --- /dev/null +++ b/init.d/._cfg0001_swclock @@ -0,0 +1,30 @@ +#!/sbin/openrc-run +# Copyright (c) 2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Sets the local clock to the mtime of a given file." + +depend() +{ + before * + provide clock + keyword -openvz -prefix -systemd-nspawn -uml -vserver -xenu -lxc +} + +# swclock is an OpenRC built in + +start() +{ + ebegin "Setting the local clock based on last shutdown time" + if ! swclock 2> /dev/null; then + swclock --warn /sbin/openrc-run + fi + eend $? +} + +stop() +{ + ebegin "Saving the shutdown time" + swclock --save + eend $? +} diff --git a/init.d/._cfg0001_sysctl b/init.d/._cfg0001_sysctl new file mode 100755 index 0000000..5618a1d --- /dev/null +++ b/init.d/._cfg0001_sysctl @@ -0,0 +1,19 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2008 Roy Marples +# Released under the 2-clause BSD license. + +depend() +{ + before bootmisc logger + keyword -prefix -systemd-nspawn -vserver +} + +start() +{ + local quiet + yesno $rc_verbose || quiet=-q + + ebegin "Configuring kernel parameters" + sysctl ${quiet} --system + eend $? "Unable to configure some kernel parameters" +} diff --git a/init.d/._cfg0001_sysfs b/init.d/._cfg0001_sysfs new file mode 100755 index 0000000..5dc62cd --- /dev/null +++ b/init.d/._cfg0001_sysfs @@ -0,0 +1,151 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples +# Released under the 2-clause BSD license. + +description="Mount the sys filesystem." + +sysfs_opts=nodev,noexec,nosuid + +depend() +{ + keyword -lxc -prefix -systemd-nspawn -vserver +} + +mount_sys() +{ + grep -Eq "[[:space:]]+sysfs$" /proc/filesystems || return 1 + mountinfo -q /sys && return 0 + + if [ ! -d /sys ]; then + if ! mkdir -m 0755 /sys; then + ewarn "Could not create /sys!" + return 1 + fi + fi + + ebegin "Mounting /sys" + if ! fstabinfo --mount /sys; then + mount -n -t sysfs -o ${sysfs_opts} sysfs /sys + fi + eend $? +} + +mount_misc() +{ + # Setup Kernel Support for securityfs + if [ -d /sys/kernel/security ] && \ + ! mountinfo -q /sys/kernel/security; then + if grep -qs securityfs /proc/filesystems; then + ebegin "Mounting security filesystem" + mount -n -t securityfs -o ${sysfs_opts} \ + securityfs /sys/kernel/security + eend $? + fi + fi + + # Setup Kernel Support for debugfs + if [ -d /sys/kernel/debug ] && ! mountinfo -q /sys/kernel/debug; then + if grep -qs debugfs /proc/filesystems; then + ebegin "Mounting debug filesystem" + mount -n -t debugfs -o ${sysfs_opts} debugfs /sys/kernel/debug + eend $? + fi + fi + + # Setup Kernel Support for configfs + if [ -d /sys/kernel/config ] && ! mountinfo -q /sys/kernel/config; then + if grep -qs configfs /proc/filesystems; then + ebegin "Mounting config filesystem" + mount -n -t configfs -o ${sysfs_opts} configfs /sys/kernel/config + eend $? + fi + fi + + # set up kernel support for cgroups + if [ -d /sys/fs/cgroup ] && ! mountinfo -q /sys/fs/cgroup; then + if grep -qs cgroup /proc/filesystems; then + ebegin "Mounting cgroup filesystem" + local opts="${sysfs_opts},mode=755,size=${rc_cgroupsize:-10m}" + mount -n -t tmpfs -o ${opts} cgroup_root /sys/fs/cgroup + eend $? + fi + fi + + # set up kernel support for fusectl + if [ -d /sys/fs/fuse/connections ] \ + && ! mountinfo -q /sys/fs/fuse/connections; then + if grep -qs fusectl /proc/filesystems; then + ebegin "Mounting fuse control filesystem" + mount -n -t fusectl -o ${sysfs_opts} \ + fusectl /sys/fs/fuse/connections + eend $? + fi + fi + + # Setup Kernel Support for SELinux + if [ -d /sys/fs/selinux ] && ! mountinfo -q /sys/fs/selinux; then + if grep -qs selinuxfs /proc/filesystems; then + ebegin "Mounting SELinux filesystem" + mount -t selinuxfs selinuxfs /sys/fs/selinux + eend $? + fi + fi + + # setup up kernel support for efivarfs + # slightly complicated, as if it's build as a module but NOT yet loaded, + # it will NOT appear in /proc/filesystems yet + if [ -d /sys/firmware/efi/efivars ] \ + && ! mountinfo -q /sys/firmware/efi/efivars; then + modprobe -q efivarfs + if grep -qs efivarfs /proc/filesystems; then + ebegin "Mounting efivarfs filesystem" + mount -n -t efivarfs -o ${sysfs_opts} \ + efivarfs /sys/firmware/efi/efivars + eend $? + fi + fi +} + +mount_cgroups() +{ + mountinfo -q /sys/fs/cgroup || return 0 + + if ! mountinfo -q /sys/fs/cgroup/openrc; then + local agent="/lib64/rc/sh/cgroup-release-agent.sh" + mkdir /sys/fs/cgroup/openrc + mount -n -t cgroup \ + -o none,${sysfs_opts},name=openrc,release_agent="$agent" \ + openrc /sys/fs/cgroup/openrc + echo 1 > /sys/fs/cgroup/openrc/notify_on_release + fi + + yesno ${rc_controller_cgroups:-YES} && [ -e /proc/cgroups ] || return 0 + while read name hier groups enabled rest; do + case "${enabled}" in + 1) mountinfo -q /sys/fs/cgroup/${name} && continue + mkdir /sys/fs/cgroup/${name} + mount -n -t cgroup -o ${sysfs_opts},${name} \ + ${name} /sys/fs/cgroup/${name} + ;; + esac + done < /proc/cgroups +} + +restorecon_sys() +{ + if [ -x /sbin/restorecon ]; then + ebegin "Restoring SELinux contexts in /sys" + restorecon -F /sys/devices/system/cpu/online >/dev/null 2>&1 + restorecon -rF /sys/fs/cgroup >/dev/null 2>&1 + eend $? + fi +} + +start() +{ + mount_sys + mount_misc + mount_cgroups + restorecon_sys + return 0 +} diff --git a/init.d/._cfg0001_tmpfiles.dev b/init.d/._cfg0001_tmpfiles.dev new file mode 100755 index 0000000..c7382ff --- /dev/null +++ b/init.d/._cfg0001_tmpfiles.dev @@ -0,0 +1,20 @@ +#!/sbin/openrc-run +# Copyright 1999-2012 Gentoo Foundation +# Released under the 2-clause BSD license. + +description="Set up tmpfiles.d entries" + +depend() +{ + use dev-mount + before dev + keyword -prefix -vserver +} + +start() +{ + ebegin "Setting up tmpfiles.d entries for /dev" + /lib64/rc/sh/tmpfiles.sh --prefix=/dev --create --boot ${tmpfiles_opts} + eend $? + return 0 +} diff --git a/init.d/._cfg0001_tmpfiles.setup b/init.d/._cfg0001_tmpfiles.setup new file mode 100755 index 0000000..3d19cb0 --- /dev/null +++ b/init.d/._cfg0001_tmpfiles.setup @@ -0,0 +1,19 @@ +#!/sbin/openrc-run +# Copyright 1999-2012 Gentoo Foundation +# Released under the 2-clause BSD license. + +description="Set up tmpfiles.d entries" + +depend() +{ + need localmount +} + +start() +{ + ebegin "Setting up tmpfiles.d entries" + /lib64/rc/sh/tmpfiles.sh --exclude-prefix=/dev --create --remove --boot \ + ${tmpfiles_opts} + eend $? + return 0 +} diff --git a/init.d/binfmt b/init.d/binfmt new file mode 100755 index 0000000..057c76f --- /dev/null +++ b/init.d/binfmt @@ -0,0 +1,20 @@ +#!/sbin/openrc-run +# Copyright 2015 William Hubbs +# Released under the 2-clause BSD license. + +description="Register misc binary format handlers" + +depend() +{ + after procfs + use modules devfs + keyword -openvz -prefix -systemd-nspawn -vserver -lxc +} + +start() +{ + ebegin "Loading custom binary format handlers" + "$RC_LIBEXECDIR"/sh/binfmt.sh + eend $? +return 0 +} diff --git a/init.d/osclock b/init.d/osclock new file mode 100755 index 0000000..486990e --- /dev/null +++ b/init.d/osclock @@ -0,0 +1,12 @@ +#!/sbin/openrc-run +# Copyright (c) 2014 Ralph Sennhauser +# Released under the 2-clause BSD license. + +# Can be used on OSs that take care of the clock. + +description="Provides clock" + +depend() +{ + provide clock +} diff --git a/init.d/s6-svscan b/init.d/s6-svscan new file mode 100755 index 0000000..f73746c --- /dev/null +++ b/init.d/s6-svscan @@ -0,0 +1,31 @@ +#!/sbin/openrc-run +# Copyright (C) 2015 William Hubbs +# Released under the 2-clause BSD license. + +command=/bin/s6-svscan +command_args="${RC_SVCDIR}"/s6-scan +command_background=yes +pidfile=/var/run/s6-svscan.pid + +depend() +{ + need localmount +} + +start_pre() +{ + einfo "Creating s6 scan directory" + checkpath -d -m 0755 "$RC_SVCDIR"/s6-scan + return $? +} + +stop_post() +{ + ebegin "Stopping any remaining s6 services" + s6-svc -dx "${RC_SVCDIR}"/s6-scan/* 2>/dev/null || true + eend $? + + ebegin "Stopping any remaining s6 service loggers" + s6-svc -dx "${RC_SVCDIR}"/s6-scan/*/log 2>/dev/null || true + eend $? +} diff --git a/logrotate.d/._cfg0000_openrc b/logrotate.d/._cfg0000_openrc new file mode 100644 index 0000000..5e5e64b --- /dev/null +++ b/logrotate.d/._cfg0000_openrc @@ -0,0 +1,4 @@ +/var/log/rc.log { + missingok + notifempty +}