diff options
author | Abdoulaye Walsimou Gaye <awg@embtoolkit.org> | 2014-03-09 18:21:33 +0100 |
---|---|---|
committer | Abdoulaye Walsimou Gaye <awg@embtoolkit.org> | 2014-03-09 18:21:33 +0100 |
commit | fee076399af853c5c751a7c901b673c4f7c01e97 (patch) | |
tree | d37074ae22670708b7ef47430d38a46a156ef6a0 /packages | |
parent | 96afd7fc069999de0d3a28ad887a42ee62e5abda (diff) | |
download | embtoolkit-fee076399af853c5c751a7c901b673c4f7c01e97.tar.gz embtoolkit-fee076399af853c5c751a7c901b673c4f7c01e97.tar.bz2 embtoolkit-fee076399af853c5c751a7c901b673c4f7c01e97.tar.xz |
RootFS: move openRC under packages
Signed-off-by: Abdoulaye Walsimou Gaye <awg@embtoolkit.org>
Diffstat (limited to 'packages')
38 files changed, 2008 insertions, 1 deletions
diff --git a/packages/system/openrc/etc/conf.d/bootmisc b/packages/system/openrc/etc/conf.d/bootmisc new file mode 100644 index 0000000..d79706c --- /dev/null +++ b/packages/system/openrc/etc/conf.d/bootmisc @@ -0,0 +1,10 @@ +# List of /tmp directories we should clean up +clean_tmp_dirs="/tmp" + +# Should we wipe the tmp paths completely or just selectively remove known +# locks / files / etc... ? +wipe_tmp="YES" + +# Write the initial dmesg log into /var/log/dmesg after boot +# This may be useful if you need the kernel boot log afterwards +log_dmesg="YES" diff --git a/packages/system/openrc/etc/conf.d/dmesg b/packages/system/openrc/etc/conf.d/dmesg new file mode 100644 index 0000000..cd4b8b3 --- /dev/null +++ b/packages/system/openrc/etc/conf.d/dmesg @@ -0,0 +1,3 @@ +# Sets the level at which logging of messages is done to the +# console. See dmesg(1) for more info. +dmesg_level="1" diff --git a/packages/system/openrc/etc/conf.d/hostname b/packages/system/openrc/etc/conf.d/hostname new file mode 100644 index 0000000..ebdc8f1 --- /dev/null +++ b/packages/system/openrc/etc/conf.d/hostname @@ -0,0 +1,2 @@ +# Set to the hostname of this machine +hostname="localhost" diff --git a/packages/system/openrc/etc/conf.d/killprocs b/packages/system/openrc/etc/conf.d/killprocs new file mode 100644 index 0000000..0cf10d0 --- /dev/null +++ b/packages/system/openrc/etc/conf.d/killprocs @@ -0,0 +1,3 @@ +# If you wish to pass any options to killall5 during shutdown, +# you should do so here. +killall5_opts="" diff --git a/packages/system/openrc/etc/conf.d/localmount b/packages/system/openrc/etc/conf.d/localmount new file mode 100644 index 0000000..e3361da --- /dev/null +++ b/packages/system/openrc/etc/conf.d/localmount @@ -0,0 +1,3 @@ +# Stop the unmounting of certain points. +# This could be useful for some NFS related work. +#no_umounts="/dir1:/var/dir2" diff --git a/packages/system/openrc/etc/conf.d/modules b/packages/system/openrc/etc/conf.d/modules new file mode 100644 index 0000000..a062a62 --- /dev/null +++ b/packages/system/openrc/etc/conf.d/modules @@ -0,0 +1,23 @@ +# You can define a list modules for a specific kernel version, +# a released kernel version, a main kernel version or just a list. +# The most specific versioned variable will take precedence. +#modules_2_6_23_gentoo_r5="ieee1394 ohci1394" +#modules_2_6_23="tun ieee1394" +#modules_2_6="tun" +#modules_2="ipv6" +#modules="ohci1394" + +# You can give modules a different name when they load - the new name +# will also be used to pick arguments below. +#modules="dummy:dummy1" + +# Give the modules some arguments if needed, per version if necessary. +# Again, the most specific versioned variable will take precedence. +#module_ieee1394_args="debug" +#module_ieee1394_args_2_6_23_gentoo_r5="debug2" +#module_ieee1394_args_2_6_23="debug3" +#module_ieee1394_args_2_6="debug4" +#module_ieee1394_args_2="debug5" + +# You should consult your kernel documentation and configuration +# for a list of modules and their options. diff --git a/packages/system/openrc/etc/conf.d/netmount b/packages/system/openrc/etc/conf.d/netmount new file mode 100644 index 0000000..fc19fd4 --- /dev/null +++ b/packages/system/openrc/etc/conf.d/netmount @@ -0,0 +1,40 @@ +# You will need to set the dependencies in the netmount script to match +# the network configuration tools you are using. This should be done in +# this file by following the examples below, and not by changing the +# service script itself. +# +# Each of these examples is meant to be used separately. So, for +# example, do not set rc_need to something like "net.eth0 dhcpcd". +# +# If you are using newnet and configuring your interfaces with static +# addresses with the network script, you should use this setting. +# +#rc_need="network" +# +# If you are using oldnet, you must list the specific net.* services you +# need. +# +# This example assumes all of your netmounts can be reached on +# eth0. +# +#rc_need="net.eth0" +# +# This example assumes some of your netmounts are on eth1 and some +# are on eth2. +# +#rc_need="net.eth1 net.eth2" +# +# If you are using a dynamic network management tool like +# networkmanager, dhcpcd in standalone mode, wicd, badvpn-ncd, etc, to +# manage the network interfaces with the routes to your netmounts, you +# should list that tool. +# +#rc_need="networkmanager" +#rc_need="dhcpcd" +#rc_need="wicd" +# +# The default setting is designed to be backward compatible with our +# current setup, but you are highly discouraged from using this. In +# other words, please change it to be more suited to your system. +# +rc_need="net" diff --git a/packages/system/openrc/etc/conf.d/network b/packages/system/openrc/etc/conf.d/network new file mode 100644 index 0000000..3548077 --- /dev/null +++ b/packages/system/openrc/etc/conf.d/network @@ -0,0 +1,71 @@ +# Assign static IP addresses and run custom scripts per interface. +# Seperate commands with ; +# Prefix with ! to run a shell script. +# Use \$int to represent the interface +#ifconfig_eth0="192.168.0.10 netmask 255.255.255.0" + +# You also have ifup_eth0 and ifdown_eth0 to run other commands when +# eth0 is started and stopped. +# You should note that we don't stop the network at system shutdown by default. +# If you really need this, then set keep_network=NO + +# Lastly, the interfaces variable pulls in virtual interfaces that cannot +# be automatically detected. +#interfaces="br0 bond0 vlan0" + +# You can also use files instead of variables here if you like: +# /etc/ifconfig.eth0 is equivalent to ifconfig_eth0 +# /etc/ip.eth0 is equivalent to ifconfig_eth0 +# /etc/ifup.eth0 is equivalent to ifup_eth0 +# /etc/ifdown.eth0 is equivalent to ifdown_eth0 +# Any files found will automatically be put into the interfaces variable. +# You don't need to escape variables in files, so use $int instead of \$int. + +# If you require DHCP, you should install dhcpcd and it to the boot or +# default runlevel. + +# NIS users can set the domain name here +#domainname="foobar" + +# You can assign a default route +#defaultroute="gw 192.168.0.1" +#defaultroute6="gw 2001:a:b:c" + +# ifconfig under Linux is not that powerful and doesn't easily handle +# multiple addresses +# On the other hand, ip (iproute2) is quite powerful and is also supported +#ip_eth0="192.168.0.10/24; 192.168.10.10/24" + +# You can also use ip to add the default route. +#defaultiproute="via 192.168.0.1" +#defaultiproute6="via 2001:a:b:c" + +# ip doesn't handle MTU like ifconfig, but we can do it like so +#ifup_eth0="ip link set \$int mtu 1500" + +# Create a bonded interface +#interfaces="bond0" +#ifup_bond0="modprobe bonding; ifconfig \$int up; ifenslave \$int bge0" +#ifconfig_bond0="192.168.0.10 netmask 255.255.255.0" +#ifdown_bond0="rmmod bonding" + +# Create tap interface and a bridge interface. +# We add the tap to the bridge. +# An external program, like dhcpcd, will configure the IP on the bridge +#interfaces="tun0 br0" +#ifup_tun0="tunctl -t \$int" +#ifdown_tun0="tunctl -d \$int" +#ifup_br0="brctl addbr \$int; brctl add \$int eth1; brtctl add \$int eth2" +#ifdown_br0="ifconfig \$int down; btctl delbr \$int" + +# Create VLAN +#interfaces="eth0_2 eth0_3 eth0_4" +#ifup_eth0="vconfig add \$int 2; vconfig add \$int 3; vconfig add \$int 4" +#ifconfig_eth0_2="192.168.2.10 netmask 255.255.255.0" +#ifconfig_eth0_3="192.168.3.10 netmask 255.255.255.0" +#ifconfig_eth0_4="192.168.4.10 netmask 255.255.255.0" +#ifdown_eth0="vconfig rem \$int.2; vconfig rem \$int.3; vconfig rem \$int.4" + +# Normally you would use wpa_supplicant to configure wireless, but you can +# use iwconfig also +#ifup_wlan0="iwconfig \$int key s:secretkey enc open essid foobar" diff --git a/packages/system/openrc/etc/conf.d/staticroute b/packages/system/openrc/etc/conf.d/staticroute new file mode 100644 index 0000000..68d22eb --- /dev/null +++ b/packages/system/openrc/etc/conf.d/staticroute @@ -0,0 +1,8 @@ +# Separate multiple routes using ; or new lines. + +# Example static routes. See route(8) for syntax. +#staticroute="net 192.168.0.0 netmask 255.255.255.0 gw 10.73.1.1 +#net 192.168.1.0 netmask 255.255.255.0 gw 10.73.1.1" + +# Example static routes using iproute2. See ip(8) for syntax. +#staticiproute="192.168.0.0/24 via 10.73.1.1; 192.168.1.0/24 via 10.73.1.1" diff --git a/packages/system/openrc/etc/conf.d/udhcpc b/packages/system/openrc/etc/conf.d/udhcpc new file mode 100644 index 0000000..4fe22b4 --- /dev/null +++ b/packages/system/openrc/etc/conf.d/udhcpc @@ -0,0 +1,5 @@ +# pidfile used for udhcpc +#udhcpc_pidfile=/run/udhcpc.pid + +# Additional argument when starting udhcpc +udhcpc_args="" diff --git a/packages/system/openrc/etc/conf.d/urandom b/packages/system/openrc/etc/conf.d/urandom new file mode 100644 index 0000000..05538e0 --- /dev/null +++ b/packages/system/openrc/etc/conf.d/urandom @@ -0,0 +1,5 @@ +# Sometimes you want to have urandom start before "localmount" +# (say for crypt swap), so you will need to customize this +# behavior. If you have /var on a separate partition, then +# make sure this path lives on your root device somewhere. +urandom_seed="/etc/random-seed" diff --git a/packages/system/openrc/etc/defaultdomain b/packages/system/openrc/etc/defaultdomain new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/packages/system/openrc/etc/defaultdomain diff --git a/packages/system/openrc/etc/init.d/bootmisc b/packages/system/openrc/etc/init.d/bootmisc new file mode 100644 index 0000000..8a1b008 --- /dev/null +++ b/packages/system/openrc/etc/init.d/bootmisc @@ -0,0 +1,216 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +depend() +{ + need localmount + after root sysctl + keyword -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 ] && return 0 + local dir + dir=$(mktemp -d) + mount --bind / $dir + rm -rf $dir/run/* + umount $dir + rm -rf $dir +} + +start() +{ + # Remove any added console dirs + rm -rf "$RC_LIBEXECDIR"/console/* + + 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 + if [ "$RC_SYS" != VSERVER -a "$RC_SYS" != OPENVZ -a "$RC_SYS" != LXC ]; then + dmesg > /var/log/dmesg + chmod 640 /var/log/dmesg + fi + 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/packages/system/openrc/etc/init.d/devfs b/packages/system/openrc/etc/init.d/devfs new file mode 100644 index 0000000..bfcb644 --- /dev/null +++ b/packages/system/openrc/etc/init.d/devfs @@ -0,0 +1,32 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2008 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +description="Mount system critical filesystems in /dev." + +start() { + # Mount required stuff as user may not have then 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 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 + return 0 +} diff --git a/packages/system/openrc/etc/init.d/dmesg b/packages/system/openrc/etc/init.d/dmesg new file mode 100644 index 0000000..34d77bd --- /dev/null +++ b/packages/system/openrc/etc/init.d/dmesg @@ -0,0 +1,17 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2008 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +description="Set the dmesg level for a cleaner boot" + +depend() +{ + before modules +} + +start() +{ + if [ -n "$dmesg_level" ]; then + dmesg -n$dmesg_level + fi +} diff --git a/packages/system/openrc/etc/init.d/hostname b/packages/system/openrc/etc/init.d/hostname new file mode 100644 index 0000000..34acbf8 --- /dev/null +++ b/packages/system/openrc/etc/init.d/hostname @@ -0,0 +1,15 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +description="Sets the hostname of the machine." + +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/packages/system/openrc/etc/init.d/killprocs b/packages/system/openrc/etc/init.d/killprocs new file mode 100644 index 0000000..6c1fa18 --- /dev/null +++ b/packages/system/openrc/etc/init.d/killprocs @@ -0,0 +1,17 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2008 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +description="Kill all processes so we can unmount disks cleanly." + +start() +{ + ebegin "Terminating remaining processes" + killall5 -15 ${killall5_opts} + sleep 1 + eend 0 + ebegin "Killing remaining processes" + killall5 -9 ${killall5_opts} + sleep 1 + eend 0 +} diff --git a/packages/system/openrc/etc/init.d/localmount b/packages/system/openrc/etc/init.d/localmount new file mode 100644 index 0000000..d6ef8fd --- /dev/null +++ b/packages/system/openrc/etc/init.d/localmount @@ -0,0 +1,85 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +description="Mounts disks and swap according to /etc/fstab." + +depend() +{ + use modules mtab + after modules +} + +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 + + # 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/packages/system/openrc/etc/init.d/loopback b/packages/system/openrc/etc/init.d/loopback new file mode 100644 index 0000000..0d8c4a6 --- /dev/null +++ b/packages/system/openrc/etc/init.d/loopback @@ -0,0 +1,24 @@ +#!/sbin/openrc-run +# Copyright (c) 2013 William Hubbs <w.d.hubbs@gmail.com> +# Released under the 2-clause BSD license. + +description="Configures the loopback interface." + +start() +{ + if [ "$RC_UNAME" = Linux ]; then + ebegin "Bringing up network interface lo" + 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 + 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/packages/system/openrc/etc/init.d/modules b/packages/system/openrc/etc/init.d/modules new file mode 100644 index 0000000..5daf554 --- /dev/null +++ b/packages/system/openrc/etc/init.d/modules @@ -0,0 +1,57 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +description="Loads a user defined list of kernel modules." + +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/packages/system/openrc/etc/init.d/mtab b/packages/system/openrc/etc/init.d/mtab new file mode 100644 index 0000000..21dbae2 --- /dev/null +++ b/packages/system/openrc/etc/init.d/mtab @@ -0,0 +1,35 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2008 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +description="Update /etc/mtab to match what the kernel knows about" + +depend() +{ + need root +} + +start() +{ + if [ -L /etc/mtab ] + then + einfo "Skipping mtab update (mtab is a symbolic link)" + return 0 + fi + + ebegin "Updating /etc/mtab" + if ! echo 2>/dev/null >/etc/mtab; then + ewend 1 "/etc/mtab is not updateable" + return 0 + fi + + # 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~~ + eend 0 +} diff --git a/packages/system/openrc/etc/init.d/netmount b/packages/system/openrc/etc/init.d/netmount new file mode 100644 index 0000000..0f3757d --- /dev/null +++ b/packages/system/openrc/etc/init.d/netmount @@ -0,0 +1,82 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +description="Mounts network shares, other than NFS, according to /etc/fstab." +# We skip all NFS shares in this script because they require extra +# daemons to be running on the client in order to work correctly. +# It is best to allow nfs-utils to handle all nfs shares. + +depend() +{ + config /etc/fstab + use dns +} + +start() +{ + local x= fs= rc= + for x in $net_fs_list $extra_net_fs_list; do + case "$x" in + nfs|nfs4) + continue + ;; + esac + 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 + case "$x" in + nfs|nfs4) + continue + ;; + *) + fs="$fs${fs:+,}$x" + ;; + esac + 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 + case "$x" in + nfs|nfs4) + continue + ;; + *) + fs="$fs${fs:+|}$x" + ;; + esac + 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/packages/system/openrc/etc/init.d/network b/packages/system/openrc/etc/init.d/network new file mode 100644 index 0000000..cebcc0c --- /dev/null +++ b/packages/system/openrc/etc/init.d/network @@ -0,0 +1,352 @@ +#!/sbin/openrc-run +# Copyright (c) 2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +# This script was inspired by the equivalent rc.d network from NetBSD. + +description="Configures network interfaces." +__nl=" +" + +depend() +{ + need localmount + after bootmisc + if [ -n "$(interfaces)" ]; then + provide net + fi +} + +uniqify() +{ + local result= i= + for i; do + case " $result " in + *" $i "*);; + *) result="$result $i";; + esac + done + echo "${result# *}" +} + +reverse() +{ + local result= i= + for i; do + result="$i $result" + done + echo "${result# *}" +} + +sys_interfaces() +{ + case "$RC_UNAME" in + Linux) + local w= rest= i= cmd=$1 + while read w rest; do + i=${w%%:*} + case "$i" in + "$w") continue ;; + lo|lo0) continue ;; + *) ;; + esac + if [ "$cmd" = u ]; then + ifconfig "$i" | grep -q "[ ]*UP" || continue + fi + printf "%s " "$i" + done </proc/net/dev + ;; + *) + ifconfig -l$1 + ;; + esac +} + +tentative() +{ + local inet= address= rest= + + case "$RC_UNAME" in + Linux) + [ -x /sbin/ip ] || [ -x /bin/ip ] || return 1 + [ -n "$(ip -f inet6 addr show tentative 2>/dev/null)" ] + ;; + *) + local inet= address= rest= + LC_ALL=C ifconfig -a | while read inet address rest; do + case "${inet}" in + inet6) + case "${rest}" in + *" "tentative*) return 2;; + esac + ;; + esac + done + [ $? = 2 ] + ;; + esac +} + + +auto_interfaces() +{ + local ifs= c= f= + + case "$RC_UNAME" in + NetBSD) + for c in $(ifconfig -C 2>/dev/null); do + for f in /etc/ifconfig.${c}[0-9]*; do + [ -f "$f" ] && printf "%s" "$f{##*.} " + done + done + ;; + *) + for f in /etc/ifconfig.*; do + [ -f "$f" ] && printf "%s" "${f##*.} " + done + for f in /etc/ip.*; do + [ -f "$f" ] && printf "%s" "${f##*.} " + done + ;; + esac + echo +} + +interfaces() +{ + uniqify $(sys_interfaces "$@") $interfaces $(auto_interfaces) +} + +dumpargs() +{ + local f="$1" + + shift + case "$@" in + '') [ -f "$f" ] && cat "$f";; + *"$__nl"*) echo "$@";; + *) + ( + set -o noglob + IFS=';'; set -- $@ + IFS="$__nl"; echo "$*" + );; + esac +} + +intup=false +runip() +{ + local int="$1" err= + shift + + # Ensure we have a valid broadcast address + case "$@" in + *" broadcast "*|*" brd "*) ;; + *:*) ;; # Ignore IPv6 + *) set -- "$@" brd +;; + esac + + err=$(LC_ALL=C ip address add "$@" dev "$int" 2>&1) + if [ -z "$err" ]; then + # ip does not bring up the interface when adding addresses + if ! $intup; then + ip link set "$int" up + intup=true + fi + return 0 + fi + if [ "$err" = "RTNETLINK answers: File exists" ]; then + ip address del "$@" dev "$int" 2>/dev/null + fi + # Localise the error + ip address add "$@" dev "$int" +} + +routeflush() +{ + if [ "$RC_UNAME" = Linux ]; then + if [ -x /sbin/ip ] || [ -x /bin/ip ]; then + ip route flush scope global + ip route delete default 2>/dev/null + else + # Sadly we also delete some link routes, but + # this cannot be helped + local dest= gate= net= flags= rest= + route -n | while read dest gate net flags rest; do + [ -z "$net" ] && continue + case "$dest" in + [0-9]*) ;; + *) continue;; + esac + local xtra= netmask="netmask $net" + case "$flags" in + U) continue;; + *H*) flags=-host; netmask=;; + *!*) flags=-net; xtra=reject;; + *) flags=-net;; + esac + route del $flags $dest $netmask $xtra + done + # Erase any default dev eth0 routes + route del default 2>/dev/null + fi + else + route -qn flush + fi +} + +runargs() +{ + dumpargs "$@" | while read -r args; do + case "$args" in + ''|"#"*) ;; + *) + ( + eval vebegin "${args#*!}" + eval "${args#*!}" + veend $? + );; + esac + done +} + +start() +{ + local cr=0 r= int= intv= cmd= args= upcmd= + + if [ -z "$domainname" -a -s /etc/defaultdomain ]; then + domainname=$(cat /etc/defaultdomain) + fi + if [ -n "$domainname" ]; then + ebegin "Setting NIS domainname: $domainname" + domainname "$domainname" + eend $? + fi + + einfo "Starting network" + routeflush + eindent + for int in $(interfaces); do + local func= cf= + intv=$(shell_var "$int") + eval upcmd=\$ifup_$intv + for func in ip ifconfig; do + eval cmd=\$${func}_$intv + if [ -n "$cmd" -o -f /etc/"$func.$int" ]; then + cf=/etc/"$func.$int" + break + fi + done + [ -n "$cf" -o -n "$upcmd" -o \ + -f /etc/ifup."$int" -o -f "$cf" ] || continue + veinfo "$int" + case "$func" in + ip) func=runip; intup=false;; + esac + eindent + runargs /etc/ifup."$int" "$upcmd" + r=0 + dumpargs "$cf" "$cmd" | while read -r args; do + case "$args" in + ''|"#"*) ;; + "!"*) + ( + eval vebegin "${args#*!}" + eval "${args#*!}" + veend $? + );; + *) + ( + set -o noglob + eval set -- "$args" + vebegin "$@" + $func "$int" "$@" + veend $? + );; + esac + done + eoutdent + done + eoutdent + eend $cr + + # Wait for any inet6 tentative addresses + r=5 + while [ $r -gt 0 ]; do + tentative || break + [ $r = 5 ] && vebegin "Waiting for tentative addresses" + sleep 1 + : $(( r -= 1 )) + done + if [ $r != 5 ]; then + [ $r != 0 ] + veend $? + fi + + if [ -n "$defaultroute" ]; then + ebegin "Setting default route $defaultroute" + route add default $defaultroute + eend $? + elif [ -n "$defaultiproute" ]; then + ebegin "Setting default route $defaultiproute" + ip route add default $defaultiproute + eend $? + fi + + if [ -n "$defaultroute6" ]; then + ebegin "Setting default route $defaultroute6" + if [ "$RC_UNAME" = Linux ]; then + routecmd="route -A inet6 add" + else + routecmd="route -inet6 add" + fi + $routecmd default $defaultroute6 + eend $? + elif [ -n "$defaultiproute6" ]; then + ebegin "Setting default route $defaultiproute6" + ip -f inet6 route add default $defaultiproute6 + eend $? + fi + + return 0 +} + +stop() +{ + # Don't stop the network at shutdown. + # We don't use the noshutdown keyword so that we are started again + # correctly if we go back to multiuser. + yesno ${keep_network:-YES} && yesno $RC_GOINGDOWN && return 0 + + local int= intv= cmd= downcmd= r= + einfo "Stopping network" + routeflush + eindent + for int in $(reverse $(interfaces u)); do + case "$int" in + lo|lo0) continue ;; + *) ;; + esac + intv=$(shell_var "$int") + eval downcmd=\$ifdown_$intv + eval cmd=\$ip_$intv + [ -z "$cmd" ] && eval cmd=\$ifconfig_$intv + if [ -n "$cmd" -o -f /etc/ip."$int" -o \ + -f /etc/ifconfig."$int" -o \ + -n "$downcmd" -o -f /etc/ifdown."$int" ]; + then + veinfo "$int" + runargs /etc/ifdown."$int" "$downcmd" + if [ -x /sbin/ip ] || [ -x /bin/ip ]; then + # We need to do this, otherwise we may + # fail to add things correctly on restart + ip address flush dev "$int" 2>/dev/null + fi + ifconfig "$int" down 2>/dev/null + ifconfig "$int" destroy 2>/dev/null + fi + done + eoutdent + eend 0 +} diff --git a/packages/system/openrc/etc/init.d/procfs b/packages/system/openrc/etc/init.d/procfs new file mode 100644 index 0000000..be016d9 --- /dev/null +++ b/packages/system/openrc/etc/init.d/procfs @@ -0,0 +1,72 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +description="Mounts misc filesystems in /proc." + +depend() +{ + use modules devfs + need localmount +} + +start() +{ + # Make sure we insert usbcore if it's a module + if [ -f /proc/modules -a ! -d /sys/module/usbcore -a ! -d /proc/bus/usb ]; then + modprobe -q usbcore + fi + + [ -e /proc/filesystems ] || return 0 + + # Setup Kernel Support for miscellaneous Binary Formats + if [ -d /proc/sys/fs/binfmt_misc -a ! -e /proc/sys/fs/binfmt_misc/register ]; then + 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 + if eend $? ; then + local fmts + ebegin "Loading custom binary format handlers" + fmts=$(grep -hsv -e '^[#;]' -e '^[[:space:]]*$' \ + /run/binfmt.d/*.conf \ + /etc/binfmt.d/*.conf \ + ""/usr/lib/binfmt.d/*.conf) + if [ -n "${fmts}" ]; then + echo "${fmts}" > /proc/sys/fs/binfmt_misc/register + fi + eend $? + fi + fi + fi + + [ "$RC_SYS" = "OPENVZ" ] && return 0 + + # Check what USB fs the kernel support. Currently + # 2.5+ kernels, and later 2.4 kernels have 'usbfs', + # while older kernels have 'usbdevfs'. + if [ -d /proc/bus/usb -a ! -e /proc/bus/usb/devices ]; then + local usbfs=$(grep -Fow usbfs /proc/filesystems || + grep -Fow usbdevfs /proc/filesystems) + if [ -n "$usbfs" ]; then + ebegin "Mounting USB device filesystem [$usbfs]" + local usbgid="$(getent group usb | \ + sed -e 's/.*:.*:\(.*\):.*/\1/')" + mount -t $usbfs \ + -o ${usbgid:+devmode=0664,devgid=$usbgid,}noexec,nosuid \ + usbfs /proc/bus/usb + eend $? + fi + fi + + # Setup Kernel Support for SELinux + if [ -d /selinux ] && ! mountinfo -q /selinux; then + if grep -qs selinuxfs /proc/filesystems; then + ebegin "Mounting SELinux filesystem" + mount -t selinuxfs selinuxfs /selinux + eend $? + fi + fi + + return 0 +} diff --git a/packages/system/openrc/etc/init.d/root b/packages/system/openrc/etc/init.d/root new file mode 100644 index 0000000..973ef1d --- /dev/null +++ b/packages/system/openrc/etc/init.d/root @@ -0,0 +1,42 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +description="Mount the root fs read/write" + +start() +{ + case ",$(fstabinfo -o /)," in + *,ro,*) + ;; + *) + # Check if the rootfs isn't already writable. + if ! checkpath -W /; then + 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" + 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/packages/system/openrc/etc/init.d/staticroute b/packages/system/openrc/etc/init.d/staticroute new file mode 100644 index 0000000..76d46fa --- /dev/null +++ b/packages/system/openrc/etc/init.d/staticroute @@ -0,0 +1,103 @@ +#!/sbin/openrc-run +# Copyright (c) 2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +# This script was inspired by the equivalent rc.d staticroute from NetBSD. + +description="Configures static routes." +__nl=" +" + +depend() +{ + provide net + use network +} + +pre_flight_checks() +{ + route=route + [ -s /etc/route.conf ] && return 0 + + if [ -n "$staticiproute" ]; then + route="ip route" + staticroute="$staticiproute" + fi +} + +dump_args() +{ + # Route configuration file, as used by the NetBSD RC system + if [ -s /etc/route.conf ]; then + cat /etc/route.conf + return $? + fi + + case "$staticroute" in + *"$__nl"*) + echo "$staticroute" + ;; + *) + ( + set -o noglob + IFS=';'; set -- $staticroute + IFS="$__nl"; echo "$*" + ) + ;; + esac +} + +do_routes() +{ + local xtra= family= + [ "$RC_UNAME" != Linux ] && xtra=-q + + ebegin "$1 static routes" + eindent + pre_flight_checks + dump_args | while read args; do + [ -z "$args" ] && continue + case "$args" in + "#"*) + ;; + "+"*) + [ $2 = "add" ] && eval ${args#*+} + ;; + "-"*) + [ $2 = "del" -o $2 = "delete" ] && eval ${args#*-} + ;; + *) + veinfo "$args" + case "$route" in + "ip route") + ip route $2 $args + ;; + *) + # Linux route does cannot work it out ... + if [ "$RC_UNAME" = Linux ]; then + case "$args" in + *:*) family="-A inet6";; + *) family=;; + esac + fi + route $family $xtra $2 -$args + ;; + esac + veend $? + esac + done + eoutdent + eend 0 +} + +start() +{ + do_routes "Adding" "add" +} + +stop() +{ + local cmd="delete" + [ "$RC_UNAME" = Linux ] && cmd="del" + do_routes "Deleting" "$cmd" +} diff --git a/packages/system/openrc/etc/init.d/swap b/packages/system/openrc/etc/init.d/swap new file mode 100644 index 0000000..caff097 --- /dev/null +++ b/packages/system/openrc/etc/init.d/swap @@ -0,0 +1,30 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +start() +{ + ebegin "Activating swap devices" + case "$RC_UNAME" in + Linux) swapon -a >/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/packages/system/openrc/etc/init.d/sysctl b/packages/system/openrc/etc/init.d/sysctl new file mode 100644 index 0000000..390e72a --- /dev/null +++ b/packages/system/openrc/etc/init.d/sysctl @@ -0,0 +1,33 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2008 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +depend() +{ + before bootmisc +} + +start() +{ + local conf= retval=0 err errs + + ebegin "Configuring kernel parameters" + eindent + + for conf in /etc/sysctl.conf /etc/sysctl.d/*.conf; do + if [ -r "$conf" ]; then + vebegin "applying $conf" + if ! err=$(sysctl -p "$conf" 2>&1 >/dev/null) ; then + errs="${errs} ${err}" + sysctl -e -p "${conf}" >/dev/null + fi + veend $? || retval=1 + fi + done + + eoutdent + if [ ${retval} -eq 0 ] && [ -n "${errs}" ] ; then + ewarn "Unknown keys:${errs}" + fi + eend $retval "Some errors were encountered: ${errs}" +} diff --git a/packages/system/openrc/etc/init.d/sysfs b/packages/system/openrc/etc/init.d/sysfs new file mode 100644 index 0000000..8a0f794 --- /dev/null +++ b/packages/system/openrc/etc/init.d/sysfs @@ -0,0 +1,131 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +description="Mount the sys filesystem." + +sysfs_opts=nodev,noexec,nosuid + +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 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 + + local agent="/usr/libexec/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 + + yesno ${rc_controller_cgroups:-YES} && [ -e /proc/cgroups ] || return 0 + while read name hier groups enabled rest; do + case "${enabled}" in + 1) mkdir /sys/fs/cgroup/${name} + mount -n -t cgroup -o ${sysfs_opts},${name} \ + ${name} /sys/fs/cgroup/${name} + ;; + esac + done < /proc/cgroups +} + +start() +{ + local retval + mount_sys + retval=$? + if [ $retval -eq 0 ]; then + mount_misc + retval=$? + fi + if [ $retval -eq 0 ]; then + mount_cgroups + retval=$? + fi + return $retval +} diff --git a/packages/system/openrc/etc/init.d/udhcpc b/packages/system/openrc/etc/init.d/udhcpc new file mode 100644 index 0000000..9def7b6 --- /dev/null +++ b/packages/system/openrc/etc/init.d/udhcpc @@ -0,0 +1,15 @@ +#!/sbin/openrc-run +# Copyright (c) 2013 Abdoulaye Walsimou GAYE <awg@embtoolkit.org> +# Released under the 2-clause BSD license. + +command=/sbin/udhcpc +pidfile=${udhcpc_pidfile:=/var/run/udhcpc.pid} +command_args=--pidfile=${pidfile} ${udhcpc_args} +name="Busybox DHCP client" + +depend() +{ + provide net + need localmount + after bootmisc modules +} diff --git a/packages/system/openrc/etc/init.d/urandom b/packages/system/openrc/etc/init.d/urandom new file mode 100644 index 0000000..1498cc2 --- /dev/null +++ b/packages/system/openrc/etc/init.d/urandom @@ -0,0 +1,44 @@ +#!/sbin/openrc-run +# Copyright (c) 2007-2009 Roy Marples <roy@marples.name> +# Released under the 2-clause BSD license. + +: ${urandom_seed:=${URANDOM_SEED:-/etc/random-seed}} +description="Initializes the random number generator." + +depend() +{ + need localmount +} + +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/packages/system/openrc/etc/issue.freebsd b/packages/system/openrc/etc/issue.freebsd new file mode 100644 index 0000000..81d5dec --- /dev/null +++ b/packages/system/openrc/etc/issue.freebsd @@ -0,0 +1,21 @@ + +8888888888 888 88888888888 888 888 d8P d8b 888 +888 888 888 888 888 d8P Y8P 888 +888 888 888 888 888 d8P 888 +8888888 88888b.d88b. 88888b. 888 .d88b. .d88b. 888 888d88K 888 888888 +888 888 "888 "88b 888 "88b 888 d88""88b d88""88b 888 8888888b 888 888 +888 888 888 888 888 888 888 888 888 888 888 888 888 Y88b 888 888 +888 888 888 888 888 d88P 888 Y88..88P Y88..88P 888 888 Y88b 888 Y88b. +8888888888 888 888 888 88888P" 888 "Y88P" "Y88P" 888 888 Y88b 888 "Y888 + + 8888888888 888888b. .d8888b. 8888888b. + 888 888 "88b d88P Y88b 888 "Y88b + 888 888 .88P Y88b. 888 888 + 8888888 888d888 .d88b. .d88b. 8888888K. "Y888b. 888 888 + 888 888P" d8P Y8b d8P Y8b 888 "Y88b "Y88b. 888 888 + 888 888 88888888 88888888 888 888 "888 888 888 + 888 888 Y8b. Y8b. 888 d88P Y88b d88P 888 .d88P + 888 888 "Y8888 "Y8888 8888888P" "Y8888P" 8888888P" + +Welcome to the EmbToolkit FreeBSD development environment. + diff --git a/packages/system/openrc/etc/issue.linux b/packages/system/openrc/etc/issue.linux new file mode 100644 index 0000000..804bd89 --- /dev/null +++ b/packages/system/openrc/etc/issue.linux @@ -0,0 +1,21 @@ + +8888888888 888 88888888888 888 888 d8P d8b 888 +888 888 888 888 888 d8P Y8P 888 +888 888 888 888 888 d8P 888 +8888888 88888b.d88b. 88888b. 888 .d88b. .d88b. 888 888d88K 888 888888 +888 888 "888 "88b 888 "88b 888 d88""88b d88""88b 888 8888888b 888 888 +888 888 888 888 888 888 888 888 888 888 888 888 888 Y88b 888 888 +888 888 888 888 888 d88P 888 Y88..88P Y88..88P 888 888 Y88b 888 Y88b. +8888888888 888 888 888 88888P" 888 "Y88P" "Y88P" 888 888 Y88b 888 "Y888 + + 888 d8b + 888 Y8P + 888 + 888 888 88888b. 888 888 888 888 + 888 888 888 "88b 888 888 `Y8bd8P' + 888 888 888 888 888 888 X88K + 888 888 888 888 Y88b 888 .d8""8b. + 88888888 888 888 888 "Y88888 888 888 + +Welcome to the EmbToolkit Linux development environment. + diff --git a/packages/system/openrc/etc/rc.conf b/packages/system/openrc/etc/rc.conf new file mode 100644 index 0000000..ae4d664 --- /dev/null +++ b/packages/system/openrc/etc/rc.conf @@ -0,0 +1,215 @@ +# 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=/bin/sh + +# 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" + +# 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 + +############################################################################## +# 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="NO" + +# 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 +#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 +# "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/<service>. +# To perform this cleanup manually for a stopped service, you can +# execute cgroup_cleanup with /etc/init.d/<service> cgroup_cleanup or +# rc-service <service> cgroup_cleanup. +# rc_cgroup_cleanup="NO" diff --git a/packages/system/openrc/openrc.kconfig b/packages/system/openrc/openrc.kconfig new file mode 100644 index 0000000..851b2d7 --- /dev/null +++ b/packages/system/openrc/openrc.kconfig @@ -0,0 +1,41 @@ +################################################################################ +# Copyright(C) 2013 Abdoulaye Walsimou GAYE. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +################################################################################ +# +# \file openrc.kconfig +# \brief openrc.kconfig of Embtoolkit +# \author Abdoulaye Walsimou GAYE <awg@embtoolkit.org> +# \date December 2013 +################################################################################ + +config EMBTK_HAVE_OPENRC + bool + depends on EMBTK_HAVE_ROOTFS + default y + select KEMBTK_UCLIBC_UCLIBC_HAS_SYSLOG if EMBTK_CLIB_UCLIBC + select KEMBTK_UCLIBC_UCLIBC_HAS_LIBUTIL if EMBTK_CLIB_UCLIBC + select EMBTK_OPENRC_NEED_PATCH + help + OpenRC is a dependency-based init system that works with the system + provided init program, normally /sbin/init. + +config EMBTK_OPENRC_VERSION_STRING + string + default "embtk-0.13" + +config EMBTK_OPENRC_NEED_PATCH + bool diff --git a/packages/system/openrc/openrc.mk b/packages/system/openrc/openrc.mk new file mode 100644 index 0000000..62eb75a --- /dev/null +++ b/packages/system/openrc/openrc.mk @@ -0,0 +1,128 @@ +################################################################################ +# Copyright(C) 2013-2014 Abdoulaye Walsimou GAYE. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +################################################################################ +# +# \file openrc.mk +# \brief openrc.mk of Embtoolkit +# \author Abdoulaye Walsimou GAYE <awg@embtoolkit.org> +# \date December 2013 +################################################################################ + +OPENRC_NAME := openrc +OPENRC_VERSION := $(call embtk_get_pkgversion,openrc) +OPENRC_SITE := $(embtk_ftp/packages-mirror) +OPENRC_PACKAGE := openrc-$(OPENRC_VERSION).tar.bz2 +OPENRC_SRC_DIR := $(embtk_pkgb)/openrc-$(OPENRC_VERSION) +OPENRC_BUILD_DIR := $(embtk_pkgb)/openrc-$(OPENRC_VERSION) + +embtk_openrc_mk := $(EMBTK_ROOT)/packages/system/openrc + +embtk_openrc_hostname := EmbToolkit-$(embtk_os) + +# sysinit runlevel scripts +embtk_openrc_sysinit := devfs dmesg sysfs + +# boot runlevel scripts +embtk_openrc_boot := bootmisc hostname localmount loopback modules mtab +embtk_openrc_boot += network procfs root staticroute swap sysctl urandom + +# default runlevel scripts +embtk_openrc_default-y := +embtk_openrc_default := netmount +embtk_openrc_default-$(CONFIG_KEMBTK_BUSYB_UDHCPC) += udhcpc +embtk_openrc_default += $(embtk_openrc_default-y) + +# shutdown runlevel scripts +embtk_openrc_shutdown := killprocs + +# Installed dir/files in sysroot +OPENRC_ETC := conf.d init.d.misc init.d local.d rc.conf runlevels +OPENRC_ETC += sysctl.d +OPENRC_LIBEXECS := rc + +ifeq ($(embtk_os),linux) +OPENRC_MAKE_OPTS := OS=Linux +endif + +OPENRC_MAKE_ENV := LIBNAME=$(LIBDIR) MKSTATICLIBS=no MKPKGCONFIG=no +OPENRC_MAKE_ENV += AR=$(TARGETAR) RANLIB=$(TARGETRANLIB) +OPENRC_MAKE_ENV += CC=$(TARGETCC_CACHED) CFLAGS="$(TARGET_CFLAGS)" +OPENRC_MAKE_ENV += LIBEXECDIR=/usr/libexec/rc +OPENRC_MAKE_ENV += BRANDING="EmbToolkit v$(EMBTK_VERSION)" +OPENRC_MAKE_ENV += MKCONFD=no +OPENRC_MAKE_ENV += MKETC=no +OPENRC_MAKE_ENV += MKINITD=no +OPENRC_MAKE_ENV += MKLOCALD=no +OPENRC_MAKE_ENV += MKMAN=no +OPENRC_MAKE_ENV += MKSCRIPTS=no +OPENRC_MAKE_ENV += MKSYSCTLD=no +OPENRC_MAKE_ENV += MKRUNLEVELS=no + +define embtk_install_openrc + $(call embtk_makeinstall_pkg,openrc) +endef + +define __embtk_install_openrc_runlevel + install -d $(embtk_rootfs)/etc/runlevels/$(1) || exit $$? + for f in $(embtk_openrc_$(1)); do \ + install -m 0755 $(embtk_openrc_mk)/etc/init.d/$$f \ + $(embtk_rootfs)/etc/init.d/$$f || exit $$?; \ + ln -snf /etc/init.d/$$f \ + $(embtk_rootfs)/etc/runlevels/$(1)/$$f || exit $$?; \ + done +endef + +define __embtk_install_openrc_confd + install -d $(embtk_rootfs)/etc/conf.d || exit $$? + for f in $(embtk_openrc_mk)/etc/conf.d/*; do \ + install -m 0644 $$f $(embtk_rootfs)/etc/conf.d || exit $$?; \ + done + echo "hostname=\"$(embtk_openrc_hostname)\"" \ + > $(embtk_rootfs)/etc/conf.d/hostname + echo "$(embtk_openrc_hostname)" \ + > $(embtk_rootfs)/etc/hostname +endef + +define embtk_postinstall_openrc + $(__embtk_install_openrc_confd) + install -d $(embtk_rootfs)/etc/init.d || exit $$? + install -m 0644 $(embtk_openrc_mk)/etc/defaultdomain \ + $(embtk_rootfs)/etc/defaultdomain || exit $$? + install -m 0644 $(embtk_openrc_mk)/etc/rc.conf \ + $(embtk_rootfs)/etc/rc.conf || exit $$? + $(if $(CONFIG_EMBTK_OS_LINUX), + install -m 0644 $(embtk_openrc_mk)/etc/issue.linux \ + $(embtk_rootfs)/etc/issue) + $(call __embtk_install_openrc_runlevel,sysinit) + $(call __embtk_install_openrc_runlevel,boot) + $(call __embtk_install_openrc_runlevel,default) + $(call __embtk_install_openrc_runlevel,shutdown) +endef + +define embtk_cleanup_openrc + rm -rf $(embtk_sysroot)/$(LIBDIR)/libeinfo.* + rm -rf $(embtk_sysroot)/$(LIBDIR)/librc.* + rm -rf $(embtk_sysroot)/bin/rc-status + rm -rf $(embtk_sysroot)/sbin/rc + rm -rf $(embtk_sysroot)/sbin/rc-service + rm -rf $(embtk_sysroot)/sbin/rc-update + rm -rf $(embtk_sysroot)/sbin/runscript + rm -rf $(embtk_sysroot)/sbin/service + rm -rf $(embtk_sysroot)/sbin/start-stop-daemon + rm -rf $(embtk_sysroot)/sbin/openrc + rm -rf $(embtk_sysroot)/sbin/openrc-run +endef diff --git a/packages/system/system.kconfig b/packages/system/system.kconfig index 78cb175..76d9099 100644 --- a/packages/system/system.kconfig +++ b/packages/system/system.kconfig @@ -23,8 +23,11 @@ # \date July 2010 ################################################################################ -#DBUS +# DBUS source packages/system/dbus/dbus.kconfig # e2fsprogs source packages/system/e2fsprogs/e2fsprogs.kconfig + +# OpenRC +source packages/system/openrc/openrc.kconfig diff --git a/packages/system/system.mk b/packages/system/system.mk index b417976..5fc7188 100644 --- a/packages/system/system.mk +++ b/packages/system/system.mk @@ -31,3 +31,6 @@ $(call embtk_include_pkg,dbus) # e2fsprogs $(call embtk_include_pkg,e2fsprogs) $(call embtk_include_hostpkg,e2fsprogs_host) + +# OpenRC +$(call embtk_include_pkg,openrc) |