Browse Source

Import 2.0.1-4

lxc
mid-kid 7 years ago
commit
9cee612f10
  1. 25
      doinst.sh
  2. BIN
      lxc-2.0.1.tar.xz
  3. 489
      lxc-slackware.in
  4. 182
      lxc.SlackBuild
  5. 63
      rc.lxc
  6. 11
      scripts/README
  7. 316
      scripts/rc.6.lxc
  8. 299
      scripts/rc.6.orig
  9. 397
      scripts/rc.M.lxc
  10. 386
      scripts/rc.M.orig
  11. 474
      scripts/rc.S.lxc
  12. 445
      scripts/rc.S.orig
  13. 331
      scripts/rc.inet1.lxc
  14. 320
      scripts/rc.inet1.orig
  15. 19
      slack-desc

25
doinst.sh

@ -0,0 +1,25 @@
config() {
NEW="$1"
OLD="$(dirname $NEW)/$(basename $NEW .new)"
if [ ! -r $OLD ]; then
mv $NEW $OLD
elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
rm $NEW
fi
}
preserve_perms() {
NEW="$1"
OLD="$(dirname $NEW)/$(basename $NEW .new)"
if [ -e $OLD ]; then
cp -a $OLD ${NEW}.incoming
cat $NEW > ${NEW}.incoming
mv ${NEW}.incoming $NEW
fi
config $NEW
}
preserve_perms etc/rc.d/rc.lxc.new
config etc/lxc/default.conf.new
config etc/default/lxc.new

BIN
lxc-2.0.1.tar.xz

Binary file not shown.

489
lxc-slackware.in

@ -0,0 +1,489 @@
#!/bin/bash
#
# lxc: linux Container library
# Authors:
# Daniel Lezcano <daniel.lezcano@free.fr>
# Template for slackware by Matteo Bernardini <ponce@slackbuilds.org>
# some parts are taken from the debian one (used as model)
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# This library 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
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
cache=${cache:-/var/cache/lxc/slackware}
# Use the primary Slackware site by default, but please consider changing
# this to a closer mirror site.
MIRROR=${MIRROR:-http://ftp.slackware.com/pub/slackware}
if [ -z "$arch" ]; then
case "$( uname -m )" in
i?86) arch=i486 ;;
arm*) arch=arm ;;
*) arch=$( uname -m ) ;;
esac
fi
configure_slackware()
{
rootfs=$1
hostname=$2
echo "Configuring..." ; echo
# The next part contains excerpts taken from SeTconfig (written by
# Patrick Volkerding) from the slackware setup disk.
# But before pasting them just set a variable to use them as they are
T_PX=$rootfs
( cd $T_PX ; chmod 755 ./ )
( cd $T_PX ; chmod 755 ./var )
if [ -d $T_PX/usr/src/linux ]; then
chmod 755 $T_PX/usr/src/linux
fi
if [ ! -d $T_PX/proc ]; then
mkdir $T_PX/proc
chown root.root $T_PX/proc
fi
if [ ! -d $T_PX/sys ]; then
mkdir $T_PX/sys
chown root.root $T_PX/sys
fi
chmod 1777 $T_PX/tmp
if [ ! -d $T_PX/var/spool/mail ]; then
mkdir -p $T_PX/var/spool/mail
chmod 755 $T_PX/var/spool
chown root.mail $T_PX/var/spool/mail
chmod 1777 $T_PX/var/spool/mail
fi
echo "#!/bin/sh" > $T_PX/etc/rc.d/rc.keymap
echo "# Load the keyboard map. More maps are in /usr/share/kbd/keymaps." \
>> $T_PX/etc/rc.d/rc.keymap
echo "if [ -x /usr/bin/loadkeys ]; then" >> $T_PX/etc/rc.d/rc.keymap
echo " /usr/bin/loadkeys us" >> $T_PX/etc/rc.d/rc.keymap
echo "fi" >> $T_PX/etc/rc.d/rc.keymap
chmod 755 $T_PX/etc/rc.d/rc.keymap
# Network configuration is left to the user, that have to edit
# /etc/rc.d/rc.inet1.conf and /etc/resolv.conf of the container
# just set the hostname
cat <<EOF > $rootfs/etc/HOSTNAME
$hostname.example.net
EOF
cp $rootfs/etc/HOSTNAME $rootfs/etc/hostname
# make needed devices, from Chris Willing's MAKEDEV.sh
# http://www.vislab.uq.edu.au/howto/lxc/MAKEDEV.sh
DEV=$rootfs/dev
mkdir -p ${DEV}
mknod -m 666 ${DEV}/null c 1 3
mknod -m 666 ${DEV}/zero c 1 5
mknod -m 666 ${DEV}/random c 1 8
mknod -m 666 ${DEV}/urandom c 1 9
mkdir -m 755 ${DEV}/pts
mkdir -m 1777 ${DEV}/shm
mknod -m 666 ${DEV}/tty c 5 0
mknod -m 600 ${DEV}/console c 5 1
mknod -m 666 ${DEV}/tty0 c 4 0
mknod -m 666 ${DEV}/tty1 c 4 1
mknod -m 666 ${DEV}/tty2 c 4 2
mknod -m 666 ${DEV}/tty3 c 4 3
mknod -m 666 ${DEV}/tty4 c 4 4
mknod -m 666 ${DEV}/tty5 c 4 5
mknod -m 666 ${DEV}/full c 1 7
mknod -m 600 ${DEV}/initctl p
mknod -m 660 ${DEV}/loop0 b 7 0
mknod -m 660 ${DEV}/loop1 b 7 1
ln -s pts/ptmx ${DEV}/ptmx
ln -s /proc/self/fd ${DEV}/fd
echo "Adding an etc/fstab that must be modified later with the"
echo "full path of the container's rootfs if you decide to move it."
cat >$rootfs/etc/fstab <<EOF
lxcpts $rootfs/dev/pts devpts defaults,newinstance 0 0
none $rootfs/proc proc defaults 0 0
none $rootfs/sys sysfs defaults 0 0
none /dev/shm tmpfs defaults 0 0
none /run tmpfs defaults,mode=0755 0 0
EOF
# Back up the existing init scripts and install the lxc versions:
( cd $rootfs/etc/rc.d
cp -a /usr/share/lxc/scripts/slackware/* .
chmod 755 *.lxc
for file in *.lxc ; do
cp -a $(basename $file .lxc) $(basename $file .lxc).orig
cp -a $file $(basename $file .lxc)
done
)
# restart rc.inet1 to have routing for the loop device
echo "/etc/rc.d/rc.inet1 restart" >> $rootfs/etc/rc.d/rc.local
# reduce the number of local consoles: two should be enough
sed -i '/^c3\|^c4\|^c5\|^c6/s/^/# /' $rootfs/etc/inittab
# In a container, use shutdown for powerfail conditions. LXC sends the SIGPWR
# signal to init to shut down the container with lxc-stop and without this the
# container will be force stopped after a one minute timeout.
sed -i "s,pf::powerfail:/sbin/genpowerfail start,pf::powerfail:/sbin/shutdown -h now,g" $rootfs/etc/inittab
sed -i "s,pg::powerokwait:/sbin/genpowerfail stop,pg::powerokwait:/sbin/shutdown -c,g" $rootfs/etc/inittab
# set a default combination for the luggage
echo "root:root" | chroot $rootfs chpasswd
echo "Root default password is 'root', please change it!"
# borrow the time configuration from the local machine
cp -a /etc/localtime $rootfs/etc/localtime
return 0
}
copy_slackware()
{
rootfs=$1
# make a local copy of the installed filesystem
echo -n "Copying rootfs to $rootfs..."
mkdir -p $rootfs
cp -a $cache/rootfs-$release-$arch/* $rootfs/ || exit 1
# fix fstab with the actual path
sed -i "s|$cache/rootfs-$release-$arch|$rootfs|" $rootfs/etc/fstab
return 0
}
install_slackware()
{
rootfs=$1
mkdir -p /var/lock/subsys/
(
flock -n -x 200
if [ $? -ne 0 ]; then
echo "Cache repository is busy."
return 1
fi
if [ "$arch" == "x86_64" ]; then
PKGMAIN=slackware64
elif [ "$arch" == "arm" ]; then
PKGMAIN=slackwarearm
else
PKGMAIN=slackware
fi
export CONF=$cache/slackpkg-conf
export ROOT=$cache/rootfs-$release-$arch
mkdir -p $cache/cache-$release-$arch $cache/rootfs-$release-$arch \
$cache/slackpkg-$release-$arch $CONF/templates
echo "$MIRROR/$PKGMAIN-$release/" > $CONF/mirrors
touch $CONF/blacklist
cat <<EOF > $CONF/slackpkg.conf
# v2.8
ARCH=$arch
TEMP=$cache/cache-$release-$arch
WORKDIR=$cache/slackpkg-$release-$arch
DELALL=off
CHECKMD5=on
CHECKGPG=on
CHECKSIZE=off
PRIORITY=( patches %PKGMAIN extra pasture testing )
POSTINST=on
ONLY_NEW_DOTNEW=off
ONOFF=on
DOWNLOAD_ALL=on
DIALOG=off
BATCH=on
DEFAULT_ANSWER=y
USE_INCLUDES=on
SPINNING=off
EOF
# thanks to Vincent Batts for this list of packages
# (that I modified a little :P)
# http://connie.slackware.com/~vbatts/minimal/
cat <<EOF > $CONF/templates/minimal-lxc.template
aaa_base
aaa_elflibs
aaa_terminfo
bash
bin
bzip2
coreutils
dcron
dhcpcd
dialog
diffutils
e2fsprogs
elvis
etc
eudev
findutils
gawk
glibc-solibs
gnupg
grep
gzip
iputils
logrotate
mpfr
net-tools
network-scripts
ncurses
openssh
openssl-solibs
pkgtools
procps-ng
sed
shadow
sharutils
slackpkg
sysklogd
sysvinit
sysvinit-functions
sysvinit-scripts
tar
util-linux
wget
which
xz
EOF
TEMPLATE=${TEMPLATE:-minimal-lxc}
if [ ! "$TEMPLATE" = "minimal-lxc" ]; then
if [ -f /etc/slackpkg/templates/$TEMPLATE.template ]; then
cat /etc/slackpkg/templates/$TEMPLATE.template \
> $CONF/templates/$TEMPLATE.template
else
TEMPLATE="minimal-lxc"
fi
fi
# clean previous installs
rm -fR $ROOT/*
slackpkg -default_answer=n update
slackpkg install-template $TEMPLATE
# add a slackpkg default mirror
echo "$MIRROR/$PKGMAIN-$release/" >> $ROOT/etc/slackpkg/mirrors
# blacklist the devs package (we have to use our premade devices).
# do the same with the kernel packages (we use the host's one),
# but leave available headers and sources
echo "devs" >> $ROOT/etc/slackpkg/blacklist
sed -i \
-e "s|^#kernel-|kernel-|" \
-e "s|^kernel-headers|#kernel-headers|" \
-e "s|^kernel-source|#kernel-source|" \
$ROOT/etc/slackpkg/blacklist
return 0
) 200>/var/lock/subsys/lxc
return $?
}
copy_configuration()
{
path=$1
rootfs=$2
name=$3
cat <<EOF >> $path/config
lxc.utsname = $name
lxc.mount = $rootfs/etc/fstab
lxc.tty = 4
lxc.pts = 1024
lxc.rootfs = $rootfs
lxc.cgroup.devices.deny = a
# /dev/null and zero
lxc.cgroup.devices.allow = c 1:3 rwm
lxc.cgroup.devices.allow = c 1:5 rwm
# consoles
lxc.cgroup.devices.allow = c 5:1 rwm
lxc.cgroup.devices.allow = c 5:0 rwm
lxc.cgroup.devices.allow = c 4:0 rwm
lxc.cgroup.devices.allow = c 4:1 rwm
# /dev/{,u}random
lxc.cgroup.devices.allow = c 1:9 rwm
lxc.cgroup.devices.allow = c 1:8 rwm
lxc.cgroup.devices.allow = c 136:* rwm
lxc.cgroup.devices.allow = c 5:2 rwm
# rtc
lxc.cgroup.devices.allow = c 254:0 rwm
# we don't trust even the root user in the container, better safe than sorry.
# comment out only if you know what you're doing.
lxc.cap.drop = sys_module mknod mac_override mac_admin sys_time setfcap setpcap
# you can try also this alternative to the line above, whatever suits you better.
# lxc.cap.drop=sys_admin
EOF
if [ $? -ne 0 ]; then
echo "Failed to add configuration."
return 1
fi
return 0
}
clean()
{
if [ ! -e $cache ]; then
exit 0
fi
# lock, so we won't purge while someone is creating a repository
(
flock -n -x 200
if [ $? != 0 ]; then
echo "Cache repository is busy."
exit 1
fi
echo -n "Purging the download cache..."
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
exit 0
) 200>/var/lock/subsys/lxc
}
usage()
{
cat <<EOF
$1 -h|--help -p|--path=<path> --clean
EOF
return 0
}
options=$(getopt -o hp:n:a:r:c -l help,rootfs:,path:,name:,arch:,release:,clean -- "$@")
if [ $? -ne 0 ]; then
usage $(basename $0)
exit 1
fi
eval set -- "$options"
while true
do
case "$1" in
-h|--help) usage $0 && exit 0;;
-p|--path) path=$2; shift 2;;
--rootfs) rootfs=$2; shift 2;;
-a|--arch) arch=$2; shift 2;;
-r|--release) release=$2; shift 2;;
-n|--name) name=$2; shift 2;;
-c|--clean) clean=$2; shift 2;;
--) shift 1; break ;;
*) break ;;
esac
done
if [ ! -z "$clean" -a -z "$path" ]; then
clean || exit 1
exit 0
fi
type installpkg
if [ $? -ne 0 ]; then
echo "'installpkg' command is missing."
exit 1
fi
type slackpkg
if [ $? -ne 0 ]; then
echo "'slackpkg' command is missing."
exit 1
fi
if [ -z "$path" ]; then
echo "'path' parameter is required."
exit 1
fi
if [ "$(id -u)" != "0" ]; then
echo "This script should be run as 'root'."
exit 1
fi
# If no release version was specified, use current
release=${release:-current}
if [ -z "$name" ]; then
# no name given? set a default one
name=slackwarecontainer
fi
# detect rootfs
config="$path/config"
if [ -z "$rootfs" ]; then
if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
rootfs=$(awk -F= '/^lxc.rootfs =/{ print $2 }' $config)
else
rootfs=$path/rootfs
fi
fi
echo
set -e
install_slackware $rootfs
if [ $? -ne 0 ]; then
echo "Failed to install slackware."
exit 1
fi
echo
configure_slackware $cache/rootfs-$release-$arch $name
if [ $? -ne 0 ]; then
echo "Failed to configure slackware for a container."
exit 1
fi
echo
rootfs=$path/rootfs
copy_slackware $rootfs
if [ $? -ne 0 ]; then
echo "Failed to copy rootfs."
exit 1
fi
echo
copy_configuration $path $rootfs $name
if [ $? -ne 0 ]; then
echo "Failed to write configuration file."
exit 1
fi
if [ ! -z $clean ]; then
clean || exit 1
exit 0
fi

182
lxc.SlackBuild

@ -0,0 +1,182 @@
#!/bin/sh
# Copyright 2011, 2012, 2013, 2014, 2015, 2016 Patrick J. Volkerding, Sebeka, Minnesota, USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Modified by Matteo Bernardini <ponce@slackbuilds.org> (2014)
PKGNAM=lxc
VERSION=${VERSION:-$(echo $PKGNAM-*.tar.?z* | rev | cut -f 3- -d . | rev | cut -f 2- -d -)}
BUILD=${BUILD:-4}
# Automatically determine the architecture we're building on:
if [ -z "$ARCH" ]; then
case "$( uname -m )" in
i?86) export ARCH=i586 ;;
arm*) export ARCH=arm ;;
# Unless $ARCH is already set, use uname -m for all other archs:
*) export ARCH=$( uname -m ) ;;
esac
fi
NUMJOBS=${NUMJOBS:-" -j7 "}
if [ "$ARCH" = "i586" ]; then
SLKCFLAGS="-O2 -march=i586 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "s390" ]; then
SLKCFLAGS="-O2"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
SLKCFLAGS="-O2 -fPIC"
LIBDIRSUFFIX="64"
else
SLKCFLAGS="-O2"
LIBDIRSUFFIX=""
fi
CWD=$(pwd)
TMP=${TMP:-/tmp}
PKG=$TMP/package-$PKGNAM
rm -rf $PKG
mkdir -p $TMP $PKG
cd $TMP
rm -rf $PKGNAM-$VERSION
tar xvf $CWD/$PKGNAM-$VERSION.tar.?z* || exit 1
cd $PKGNAM-$VERSION
chown -R root:root .
find . \
\( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
-exec chmod 755 {} \; -o \
\( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \
-exec chmod 644 {} \;
# Add the template file:
cat $CWD/lxc-slackware.in > templates/lxc-slackware.in
# Our python package is not split:
sed -i "s|PKG_CHECK_MODULES(\[PYTHONDEV.*||" configure.ac || exit 1
autoreconf -fi
# Enable python stuff only if python3 is installed
python=""
[ -x /usr/bin/python3 ] && export PYTHON=/usr/bin/python3 && python="--enable-python"
# Configure:
# lua is autodetected
CFLAGS="$SLKCFLAGS" \
./configure \
--prefix=/usr \
--sysconfdir=/etc \
--libdir=/usr/lib${LIBDIRSUFFIX} \
--localstatedir=/var \
--mandir=/usr/man \
--docdir=/usr/doc/$PKGNAM-$VERSION \
--infodir=/usr/info \
--with-global-conf=/etc/lxc/lxc.conf \
--with-rootfs-path=/var/lib/rootfs-lxc \
$python \
--build=$ARCH-slackware-linux
# Build and install:
make $NUMJOBS || make || exit 1
make install DESTDIR=$PKG || exit 1
# Add the modified Slackware startup scripts:
mkdir -p $PKG/usr/share/lxc/scripts/slackware
cp -a $CWD/scripts/*.lxc $PKG/usr/share/lxc/scripts/slackware
chown root:root $PKG/usr/share/lxc/scripts/slackware/*
chmod 644 $PKG/usr/share/lxc/scripts/slackware/*
# Make the default configuration directories and an empty rootfs folder:
mkdir -p $PKG/var/lib/lxc $PKG/etc/lxc $PKG/var/lib/rootfs-lxc
# Create a sample default configuration file:
echo "lxcpath = /var/lib/lxc" > $PKG/etc/lxc/lxc.conf.sample
# Move the other config files to .new:
mv $PKG/etc/lxc/default.conf $PKG/etc/lxc/default.conf.new
mv $PKG/etc/default/lxc $PKG/etc/default/lxc.new
# Install an init script (non executable by default):
install -D -m 0644 $CWD/rc.lxc $PKG/etc/rc.d/rc.lxc.new
# Put bash completion file in system directory:
mkdir -p $PKG/usr/share/bash-completion/completions/
mv $PKG/etc/bash_completion.d/lxc \
$PKG/usr/share/bash-completion/completions/lxc
rmdir --parents $PKG/etc/bash_completion.d 2>/dev/null
# Replace illegal characters in the bash completion file:
sed -i "s/lxc-generic-/lxc_generic_/g" $PKG/usr/share/bash-completion/completions/lxc
# Strip binaries:
( cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
# Add a documentation directory:
mkdir -p $PKG/usr/doc/${PKGNAM}-$VERSION
cp -a \
AUTHORS CONTRIBUTING COPYING* INSTALL MAINTAINERS NEWS README* TODO \
doc/FAQ.txt \
$PKG/usr/doc/${PKGNAM}-$VERSION
mkdir -p $PKG/usr/doc/${PKGNAM}-$VERSION/examples
cp -a doc/examples/*.conf $PKG/usr/doc/${PKGNAM}-$VERSION/examples
# Fix up man pages to stop 'man' from barfing a warning:
( cd $PKG/usr/man
fgrep -lr -- '-*- coding: us-ascii -*-' . | xargs sed -i '/-*- coding: us-ascii -*-/d' )
# Compress and if needed symlink the man pages:
if [ -d $PKG/usr/man ]; then
( cd $PKG/usr/man
for manpagedir in $(find . -type d -name "man*") ; do
( cd $manpagedir
for eachpage in $( find . -type l -maxdepth 1) ; do
ln -s $( readlink $eachpage ).gz $eachpage.gz
rm $eachpage
done
gzip -9 *.?
)
done
)
fi
# If there's a ChangeLog, installing at least part of the recent history
# is useful, but don't let it get totally out of control:
if [ -r ChangeLog ]; then
DOCSDIR=$(echo $PKG/usr/doc/${PKGNAM}-$VERSION)
cat ChangeLog | head -n 1000 > $DOCSDIR/ChangeLog
touch -r ChangeLog $DOCSDIR/ChangeLog
fi
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh
cd $PKG
/sbin/makepkg -l y -c n $TMP/$PKGNAM-$(echo $VERSION | tr - _)-$ARCH-$BUILD.txz

63
rc.lxc

@ -0,0 +1,63 @@
#!/bin/sh
# rc.lxc init script
# Written by Matteo Bernardini <ponce@slackbuilds.org>
#
# This script checks for the presence of the parameter lxc.start.auto
# in the available container configurations: if it's set to 1 the
# container is started (in an auto-detached screen session if
# screen is available) when rc.lxc is called with the "start" param.
#
# To stop the container it uses lxc-attach to execute /sbin/halt
# inside of it.
. /usr/share/lxc/lxc.functions
start_lxc() {
for CONTAIN in $(/usr/bin/lxc-ls); do
if [ "$(lxc-info -n $CONTAIN -c lxc.start.auto)" = "lxc.start.auto = 1" ]; then
if [ "$(/usr/bin/lxc-info -s -n $CONTAIN | grep STOPPED$)" ]; then
echo "Starting LXC container ${CONTAIN}."
if [ -x /usr/bin/screen ]; then
/usr/bin/screen -dmS init-${CONTAIN} /usr/bin/lxc-start -n $CONTAIN
else
/usr/bin/lxc-start -n $CONTAIN -d
fi
/usr/bin/lxc-wait -n $CONTAIN -s RUNNING
if [ $? -gt 0 ]; then
return 2
fi
fi
fi
done
}
stop_lxc() {
for CONTAIN in $(/usr/bin/lxc-ls --active); do
echo "Stopping LXC container ${CONTAIN}."
/usr/bin/lxc-stop -n $CONTAIN
/usr/bin/lxc-wait -n $CONTAIN -s STOPPED
if [ $? -gt 0 ]; then
return 2
fi
done
}
restart_lxc() {
stop_lxc
sleep 2
start_lxc
}
case "$1" in
'start')
start_lxc
;;
'stop')
stop_lxc
;;
restart)
restart_lxc
;;
*)
echo "usage $0 start|stop|restart"
esac

11
scripts/README

@ -0,0 +1,11 @@
These are modified versions of some sysvinit-scripts and network-scripts for
Slackware for use in a container (although they should also work for a regular
non-container system as well).
Versions ending in .lxc are the scripts to be used in a container.
Versions ending in .orig are the scripts from the sysvinit-scripts and
network-scripts packages that the .lxc scripts are based on.
Any changes made to the original scripts in sysvinit-scripts or network-scripts
*may* need to be ported to these versions.

316
scripts/rc.6.lxc

@ -0,0 +1,316 @@
#! /bin/sh
#
# rc.6 This file is executed by init when it goes into runlevel
# 0 (halt) or runlevel 6 (reboot). It kills all processes,
# unmounts file systems and then either halts or reboots.
#
# Version: @(#)/etc/rc.d/rc.6 2.47 Sat Jan 13 13:37:26 PST 2001
#
# Author: Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org>
# Modified by: Patrick J. Volkerding, <volkerdi@slackware.com>
#
# Set the path.
PATH=/sbin:/etc:/bin:/usr/bin
# Set $container variable since this is a modified version of rc.6 with
# changes for running in an lxc container. A check to see if this variable
# is set will be used to skip parts of the script that we don't want to run
# in a container. Thanks to Matteo Bernardini <ponce@slackbuilds.org> and
# Chris Willing for the initial work making this script lxc compatible.
container="lxc"
# If there are SystemV init scripts for this runlevel, run them.
if [ -x /etc/rc.d/rc.sysvinit ]; then
. /etc/rc.d/rc.sysvinit
fi
# Set linefeed mode to avoid staircase effect.
/bin/stty onlcr
echo "Running shutdown script $0:"
# Find out how we were called.
case "$0" in
*0)
shutdown_command="halt"
;;
*6)
shutdown_command=reboot
;;
*)
echo "$0: call me as \"rc.0\" or \"rc.6\" please!"
exit 1
;;
esac
# Save the system time to the hardware clock using hwclock --systohc.
# This will also create or update the timestamps in /etc/adjtime.
if [ -x /sbin/hwclock -a -z "$container" ]; then
# Check for a broken motherboard RTC clock (where ioports for rtc are
# unknown) to prevent hwclock causing a hang:
if ! grep -q " : rtc" /proc/ioports ; then
CLOCK_OPT="--directisa"
fi
if [ /etc/adjtime -nt /etc/hardwareclock ]; then
if grep -q "^LOCAL" /etc/adjtime ; then
echo "Saving system time to the hardware clock (localtime)."
else
echo "Saving system time to the hardware clock (UTC)."
fi
/sbin/hwclock $CLOCK_OPT --systohc
elif grep -q "^UTC" /etc/hardwareclock 2> /dev/null ; then
echo "Saving system time to the hardware clock (UTC)."
if [ ! -r /etc/adjtime ]; then
echo "Creating system time correction file /etc/adjtime."
fi
/sbin/hwclock $CLOCK_OPT --utc --systohc
else
echo "Saving system time to the hardware clock (localtime)."
if [ ! -r /etc/adjtime ]; then
echo "Creating system time correction file /etc/adjtime."
fi
/sbin/hwclock $CLOCK_OPT --localtime --systohc
fi
fi
# Run any local shutdown scripts:
if [ -x /etc/rc.d/rc.local_shutdown ]; then
/etc/rc.d/rc.local_shutdown stop
fi
# Stop the Apache web server:
if [ -x /etc/rc.d/rc.httpd ]; then
/etc/rc.d/rc.httpd stop
fi
# Stop the MySQL database:
if [ -r /var/run/mysql/mysql.pid ]; then
. /etc/rc.d/rc.mysqld stop
fi
# Stop the Samba server:
if [ -x /etc/rc.d/rc.samba ]; then
. /etc/rc.d/rc.samba stop
fi
# Shut down the NFS server:
if [ -x /etc/rc.d/rc.nfsd ]; then
/etc/rc.d/rc.nfsd stop
fi
# Shut down the SSH server:
if [ -x /etc/rc.d/rc.sshd ]; then
/etc/rc.d/rc.sshd stop
fi
# Shut down the SASL authentication daemon:
if [ -x /etc/rc.d/rc.saslauthd ]; then
/etc/rc.d/rc.saslauthd stop
fi
# Shut down OpenLDAP:
if [ -x /etc/rc.d/rc.openldap ]; then
/etc/rc.d/rc.openldap stop
fi
# Stop D-Bus:
if [ -x /etc/rc.d/rc.messagebus ]; then
sh /etc/rc.d/rc.messagebus stop
fi
# Kill any processes (typically gam) that would otherwise prevent
# unmounting NFS volumes:
unset FUSER_DELAY
for dir in $(/bin/mount | grep 'type nfs ' | cut -d ' ' -f 3 ) ; do
echo "Killing processes holding NFS mount $dir open..."
# Background this to prevent fuser from also blocking shutdown:
/usr/bin/fuser -k -m $dir &
FUSER_DELAY=5
done
# If fuser was run, let it have some delay:
if [ ! -z "$FUSER_DELAY" ]; then
sleep $FUSER_DELAY
fi
# Unmount any NFS, SMB, or CIFS filesystems:
echo "Unmounting remote filesystems:"
/bin/umount -v -a -l -f -r -t nfs,smbfs,cifs | tr -d ' ' | grep successfully | sed "s/:successfullyunmounted/ has been successfully unmounted./g"
# Try to shut down pppd:
PS="$(ps ax)"
if echo "$PS" | /bin/grep -q -w pppd ; then
if [ -x /usr/sbin/ppp-off ]; then
/usr/sbin/ppp-off
fi
fi
# Shut down YP services:
if [ -x /etc/rc.d/rc.yp ]; then
if grep -wq stop /etc/rc.d/rc.yp ; then
/etc/rc.d/rc.yp stop
fi
fi
# Bring down the networking system, but first make sure that this
# isn't a diskless client with the / partition mounted via NFS:
if ! /bin/mount | /bin/grep -q 'on / type nfs' ; then
if [ -x /etc/rc.d/rc.inet1 ]; then
. /etc/rc.d/rc.inet1 stop
fi
fi
# In case dhcpcd might have been manually started on the command line,
# look for the .pid file, and shut dhcpcd down if it's found:
if /bin/ls /etc/dhcpc/*.pid 1> /dev/null 2> /dev/null ; then
/sbin/dhcpcd -k 1> /dev/null 2> /dev/null
# A little time for /etc/resolv.conf and/or other files to
# restore themselves.
sleep 2
fi
# Shut down PCMCIA devices:
if [ -x /etc/rc.d/rc.pcmcia -a -z "$container" ]; then
. /etc/rc.d/rc.pcmcia stop
# The cards might need a little extra time here to deactivate:
/bin/sleep 5
fi
# Turn off process accounting:
if [ -x /sbin/accton -a -r /var/log/pacct ]; then
/sbin/accton off
fi
# Terminate acpid before syslog:
if [ -x /etc/rc.d/rc.acpid -a -r /var/run/acpid.pid -a -z "$container" ]; then # quit
. /etc/rc.d/rc.acpid stop
fi
# Stop udev:
if [ -x /etc/rc.d/rc.udev -a -z "$container" ]; then
sh /etc/rc.d/rc.udev force-stop
fi
# Kill all remaining processes.
OMITPIDS="$(for p in $(pgrep mdmon); do echo -o $p; done)" # Don't kill mdmon
if [ ! "$1" = "fast" ]; then
echo "Sending all processes the SIGTERM signal."
/sbin/killall5 -15 $OMITPIDS
/bin/sleep 5
echo "Sending all processes the SIGKILL signal."
/sbin/killall5 -9 $OMITPIDS
fi
# Try to turn off quota.
if /bin/grep -q quota /etc/fstab ; then
if [ -x /sbin/quotaoff -a -z "$container" ]; then
echo "Turning off filesystem quotas."
/sbin/quotaoff -a
fi
fi
# Carry a random seed between reboots.
echo "Saving random seed from /dev/urandom in /etc/random-seed."
# Use the pool size from /proc, or 4096 bits:
if [ -r /proc/sys/kernel/random/poolsize ]; then
/bin/dd if=/dev/urandom of=/etc/random-seed count=1 bs=$(expr $(cat /proc/sys/kernel/random/poolsize) / 8) 2> /dev/null
else
/bin/dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null
fi
/bin/chmod 600 /etc/random-seed
# Before unmounting file systems write a reboot or halt record to wtmp.
$shutdown_command -w
# Turn off swap:
if [ -z "$container" ]; then
echo "Turning off swap."
/sbin/swapoff -a
/bin/sync
fi
# Stop cgmanager and cgproxy:
if [ -x /etc/rc.d/rc.cgmanager -a -z "$container" ]; then
sh /etc/rc.d/rc.cgmanager stop
fi
if [ -z "$container" ]; then
echo "Unmounting local file systems:"
/bin/umount -v -a -t no,proc,sysfs | tr -d ' ' | grep successfully | sed "s/:successfullyunmounted/ has been successfully unmounted./g" 2> /dev/null
echo "Remounting root filesystem read-only:"
/bin/mount -v -n -o remount,ro /
fi
# This never hurts:
/bin/sync
# Close any volumes opened by cryptsetup:
if [ -f /etc/crypttab -a -x /sbin/cryptsetup ]; then
cat /etc/crypttab | grep -v "^#" | grep -v "^$" | while read line; do
# NOTE: we only support LUKS formatted volumes (except for swap)!
LUKS=$(echo $line | tr '\t' ' ' | tr -s ' ' | cut -f1 -d' ')
DEV=$(echo $line | tr '\t' ' ' | tr -s ' ' | cut -f2 -d' ')
OPTS=$(echo $line | tr '\t' ' ' | tr -s ' ' | cut -f4 -d' ')
if /sbin/cryptsetup isLuks $DEV 2>/dev/null ; then
echo "Locking LUKS crypt volume '${LUKS}':"
/sbin/cryptsetup luksClose ${LUKS}
elif echo $OPTS | grep -wq swap ; then
# If any of the volumes was used as encrypted swap,
# then run mkswap on the underlying device -
# in case other Linux installations on this computer should use it:
echo "Erasing encrypted swap '${LUKS}' and restoring normal swap on ${DEV}:"
/sbin/cryptsetup remove ${LUKS}
mkswap $DEV
fi
done
fi
# Deactivate LVM volume groups:
if [ -z "$container" ]; then
if [ -r /etc/lvmtab -o -d /etc/lvm/backup ]; then
echo "Deactivating LVM volume groups:"
/sbin/vgchange -an --ignorelockingfailure
fi
fi
# This never hurts again (especially since root-on-LVM always fails
# to deactivate the / logical volume... but at least it was
# remounted as read-only first)
/bin/sync
# sleep 3 fixes problems with some hard drives that don't
# otherwise finish syncing before reboot or poweroff
/bin/sleep 3
# This is to ensure all processes have completed on SMP machines:
wait
if [ -x /sbin/genpowerd -a -z "$container" ]; then
# See if this is a powerfail situation:
if /bin/egrep -q "FAIL|SCRAM" /etc/upsstatus 2> /dev/null ; then
# Signal UPS to shut off the inverter:
/sbin/genpowerd -k
if [ ! $? = 0 ]; then
echo
echo "There was an error signaling the UPS."
echo "Perhaps you need to edit /etc/genpowerd.conf to configure"
echo "the serial line and UPS type."
# Wasting 15 seconds of precious power:
/bin/sleep 15
fi
fi
fi
if [ "$container" = "lxc" ]; then
# confirm successful shutdown of the container
echo "LXC container stopped."
fi
# Now halt (poweroff with APM or ACPI enabled kernels) or reboot.
if [ "$shutdown_command" = "reboot" ]; then
echo "Rebooting."
/sbin/reboot
else
/sbin/poweroff
fi

299
scripts/rc.6.orig

@ -0,0 +1,299 @@
#! /bin/sh
#
# rc.6 This file is executed by init when it goes into runlevel
# 0 (halt) or runlevel 6 (reboot). It kills all processes,
# unmounts file systems and then either halts or reboots.
#
# Version: @(#)/etc/rc.d/rc.6 2.47 Sat Jan 13 13:37:26 PST 2001
#
# Author: Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org>
# Modified by: Patrick J. Volkerding, <volkerdi@slackware.com>
#
# Set the path.
PATH=/sbin:/etc:/bin:/usr/bin
# If there are SystemV init scripts for this runlevel, run them.
if [ -x /etc/rc.d/rc.sysvinit ]; then
. /etc/rc.d/rc.sysvinit
fi
# Set linefeed mode to avoid staircase effect.
/bin/stty onlcr
echo "Running shutdown script $0:"
# Find out how we were called.
case "$0" in
*0)
shutdown_command="halt"
;;
*6)
shutdown_command=reboot
;;
*)
echo "$0: call me as \"rc.0\" or \"rc.6\" please!"
exit 1
;;
esac
# Save the system time to the hardware clock using hwclock --systohc.
# This will also create or update the timestamps in /etc/adjtime.
if [ -x /sbin/hwclock ]; then
# Check for a broken motherboard RTC clock (where ioports for rtc are
# unknown) to prevent hwclock causing a hang:
if ! grep -q " : rtc" /proc/ioports ; then
CLOCK_OPT="--directisa"
fi
if [ /etc/adjtime -nt /etc/hardwareclock ]; then
if grep -q "^LOCAL" /etc/adjtime ; then
echo "Saving system time to the hardware clock (localtime)."
else
echo "Saving system time to the hardware clock (UTC)."
fi
/sbin/hwclock $CLOCK_OPT --systohc
elif grep -q "^UTC" /etc/hardwareclock 2> /dev/null ; then
echo "Saving system time to the hardware clock (UTC)."
if [ ! -r /etc/adjtime ]; then
echo "Creating system time correction file /etc/adjtime."
fi
/sbin/hwclock $CLOCK_OPT --utc --systohc
else
echo "Saving system time to the hardware clock (localtime)."
if [ ! -r /etc/adjtime ]; then
echo "Creating system time correction file /etc/adjtime."
fi
/sbin/hwclock $CLOCK_OPT --localtime --systohc
fi
fi
# Run any local shutdown scripts:
if [ -x /etc/rc.d/rc.local_shutdown ]; then
/etc/rc.d/rc.local_shutdown stop
fi
# Stop the Apache web server:
if [ -x /etc/rc.d/rc.httpd ]; then
/etc/rc.d/rc.httpd stop
fi
# Stop the MySQL database:
if [ -r /var/run/mysql/mysql.pid ]; then
. /etc/rc.d/rc.mysqld stop
fi
# Stop the Samba server:
if [ -x /etc/rc.d/rc.samba ]; then
. /etc/rc.d/rc.samba stop
fi
# Shut down the NFS server:
if [ -x /etc/rc.d/rc.nfsd ]; then
/etc/rc.d/rc.nfsd stop
fi
# Shut down the SSH server:
if [ -x /etc/rc.d/rc.sshd ]; then
/etc/rc.d/rc.sshd stop
fi
# Shut down the SASL authentication daemon:
if [ -x /etc/rc.d/rc.saslauthd ]; then
/etc/rc.d/rc.saslauthd stop
fi
# Shut down OpenLDAP:
if [ -x /etc/rc.d/rc.openldap ]; then
/etc/rc.d/rc.openldap stop
fi
# Stop D-Bus:
if [ -x /etc/rc.d/rc.messagebus ]; then
sh /etc/rc.d/rc.messagebus stop
fi
# Kill any processes (typically gam) that would otherwise prevent
# unmounting NFS volumes:
unset FUSER_DELAY
for dir in $(/bin/mount | grep 'type nfs ' | cut -d ' ' -f 3 ) ; do
echo "Killing processes holding NFS mount $dir open..."
# Background this to prevent fuser from also blocking shutdown:
/usr/bin/fuser -k -m $dir &
FUSER_DELAY=5
done
# If fuser was run, let it have some delay:
if [ ! -z "$FUSER_DELAY" ]; then
sleep $FUSER_DELAY
fi
# Unmount any NFS, SMB, or CIFS filesystems:
echo "Unmounting remote filesystems:"
/bin/umount -v -a -l -f -r -t nfs,smbfs,cifs | tr -d ' ' | grep successfully | sed "s/:successfullyunmounted/ has been successfully unmounted./g"
# Try to shut down pppd:
PS="$(ps ax)"
if echo "$PS" | /bin/grep -q -w pppd ; then
if [ -x /usr/sbin/ppp-off ]; then
/usr/sbin/ppp-off
fi
fi
# Shut down YP services:
if [ -x /etc/rc.d/rc.yp ]; then
if grep -wq stop /etc/rc.d/rc.yp ; then
/etc/rc.d/rc.yp stop
fi
fi
# Bring down the networking system, but first make sure that this
# isn't a diskless client with the / partition mounted via NFS:
if ! /bin/mount | /bin/grep -q 'on / type nfs' ; then
if [ -x /etc/rc.d/rc.inet1 ]; then
. /etc/rc.d/rc.inet1 stop
fi
fi
# In case dhcpcd might have been manually started on the command line,
# look for the .pid file, and shut dhcpcd down if it's found:
if /bin/ls /etc/dhcpc/*.pid 1> /dev/null 2> /dev/null ; then
/sbin/dhcpcd -k 1> /dev/null 2> /dev/null
# A little time for /etc/resolv.conf and/or other files to
# restore themselves.
sleep 2
fi
# Shut down PCMCIA devices:
if [ -x /etc/rc.d/rc.pcmcia ]; then
. /etc/rc.d/rc.pcmcia stop
# The cards might need a little extra time here to deactivate:
/bin/sleep 5
fi
# Turn off process accounting:
if [ -x /sbin/accton -a -r /var/log/pacct ]; then
/sbin/accton off
fi
# Terminate acpid before syslog:
if [ -x /etc/rc.d/rc.acpid -a -r /var/run/acpid.pid ]; then # quit
. /etc/rc.d/rc.acpid stop
fi
# Stop udev:
if [ -x /etc/rc.d/rc.udev ]; then
sh /etc/rc.d/rc.udev force-stop
fi
# Kill all remaining processes.
OMITPIDS="$(for p in $(pgrep mdmon); do echo -o $p; done)" # Don't kill mdmon
if [ ! "$1" = "fast" ]; then
echo "Sending all processes the SIGTERM signal."
/sbin/killall5 -15 $OMITPIDS
/bin/sleep 5
echo "Sending all processes the SIGKILL signal."
/sbin/killall5 -9 $OMITPIDS
fi
# Try to turn off quota.
if /bin/grep -q quota /etc/fstab ; then
if [ -x /sbin/quotaoff ]; then
echo "Turning off filesystem quotas."
/sbin/quotaoff -a
fi
fi
# Carry a random seed between reboots.
echo "Saving random seed from /dev/urandom in /etc/random-seed."
# Use the pool size from /proc, or 4096 bits:
if [ -r /proc/sys/kernel/random/poolsize ]; then
/bin/dd if=/dev/urandom of=/etc/random-seed count=1 bs=$(expr $(cat /proc/sys/kernel/random/poolsize) / 8) 2> /dev/null
else
/bin/dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null
fi
/bin/chmod 600 /etc/random-seed
# Before unmounting file systems write a reboot or halt record to wtmp.
$shutdown_command -w
# Turn off swap:
echo "Turning off swap."
/sbin/swapoff -a
/bin/sync
# Stop cgmanager and cgproxy:
if [ -x /etc/rc.d/rc.cgmanager ]; then
sh /etc/rc.d/rc.cgmanager stop
fi
echo "Unmounting local file systems:"
/bin/umount -v -a -t no,proc,sysfs | tr -d ' ' | grep successfully | sed "s/:successfullyunmounted/ has been successfully unmounted./g" 2> /dev/null
echo "Remounting root filesystem read-only:"
/bin/mount -v -n -o remount,ro /
# This never hurts:
/bin/sync
# Close any volumes opened by cryptsetup:
if [ -f /etc/crypttab -a -x /sbin/cryptsetup ]; then
cat /etc/crypttab | grep -v "^#" | grep -v "^$" | while read line; do
# NOTE: we only support LUKS formatted volumes (except for swap)!
LUKS=$(echo $line | tr '\t' ' ' | tr -s ' ' | cut -f1 -d' ')
DEV=$(echo $line | tr '\t' ' ' | tr -s ' ' | cut -f2 -d' ')
OPTS=$(echo $line | tr '\t' ' ' | tr -s ' ' | cut -f4 -d' ')
if /sbin/cryptsetup isLuks $DEV 2>/dev/null ; then
echo "Locking LUKS crypt volume '${LUKS}':"
/sbin/cryptsetup luksClose ${LUKS}
elif echo $OPTS | grep -wq swap ; then
# If any of the volumes was used as encrypted swap,
# then run mkswap on the underlying device -
# in case other Linux installations on this computer should use it:
echo "Erasing encrypted swap '${LUKS}' and restoring normal swap on ${DEV}:"
/sbin/cryptsetup remove ${LUKS}
mkswap $DEV
fi
done
fi
# Deactivate LVM volume groups:
if [ -r /etc/lvmtab -o -d /etc/lvm/backup ]; then
echo "Deactivating LVM volume groups:"
/sbin/vgchange -an --ignorelockingfailure
fi
# This never hurts again (especially since root-on-LVM always fails
# to deactivate the / logical volume... but at least it was
# remounted as read-only first)
/bin/sync
# sleep 3 fixes problems with some hard drives that don't
# otherwise finish syncing before reboot or poweroff
/bin/sleep 3
# This is to ensure all processes have completed on SMP machines:
wait
if [ -x /sbin/genpowerd ]; then
# See if this is a powerfail situation:
if /bin/egrep -q "FAIL|SCRAM" /etc/upsstatus 2> /dev/null ; then
# Signal UPS to shut off the inverter:
/sbin/genpowerd -k
if [ ! $? = 0 ]; then
echo
echo "There was an error signaling the UPS."
echo "Perhaps you need to edit /etc/genpowerd.conf to configure"
echo "the serial line and UPS type."
# Wasting 15 seconds of precious power:
/bin/sleep 15
fi
fi
fi
# Now halt (poweroff with APM or ACPI enabled kernels) or reboot.
if [ "$shutdown_command" = "reboot" ]; then
echo "Rebooting."
/sbin/reboot
else
/sbin/poweroff
fi

397
scripts/rc.M.lxc

@ -0,0 +1,397 @@
#!/bin/sh
#
# rc.M This file is executed by init(8) when the system is being
# initialized for one of the "multi user" run levels (i.e.
# levels 1 through 6). It usually does mounting of file
# systems et al.
#
# Version: @(#)/etc/rc.d/rc.M 2.23 Wed Feb 26 19:20:58 PST 2003
#
# Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
# Heavily modified by Patrick Volkerding <volkerdi@slackware.com>
#
# Tell the viewers what's going to happen.
echo "Going multiuser..."
# Set $container variable since this is a modified version of rc.M with
# changes for running in an lxc container. A check to see if this variable
# is set will be used to skip parts of the script that we don't want to run
# in a container. Thanks to Matteo Bernardini <ponce@slackbuilds.org> and
# Chris Willing for the initial work making this script lxc compatible.
container="lxc"
# Update all the shared library links:
if [ -x /sbin/ldconfig ]; then
echo "Updating shared library links: /sbin/ldconfig &"
/sbin/ldconfig &
fi
# Screen blanks after 15 minutes idle time, and powers down in one hour
# if the kernel supports APM or ACPI power management:
if [ -z "$container" ]; then
/bin/setterm -blank 15 -powersave powerdown -powerdown 60
fi
# Set the hostname.
if [ -z "$container" ]; then
if [ -r /etc/HOSTNAME ]; then
/bin/hostname $(cat /etc/HOSTNAME | cut -f1 -d .)
else
# fall back on this old default:
echo "darkstar.example.net" > /etc/HOSTNAME
/bin/hostname darkstar
fi
fi
# Set the permissions on /var/log/dmesg according to whether the kernel
# permits non-root users to access kernel dmesg information:
if [ -r /proc/sys/kernel/dmesg_restrict ]; then
if [ $(cat /proc/sys/kernel/dmesg_restrict) = 1 ]; then
touch /var/log/dmesg
chmod 640 /var/log/dmesg
fi
else
touch /var/log/dmesg
chmod 644 /var/log/dmesg
fi
# Save the contents of 'dmesg':
/bin/dmesg -s 65536 > /var/log/dmesg
# Initialize PCMCIA devices:
#
# NOTE: This used to be started near the top of rc.S so that PCMCIA devices
# could be fsck'ed along with the other drives. This had some unfortunate
# side effects, however, since root isn't yet read-write, and /var might not
# even be mounted the .pid files can't be correctly written in /var/run and
# the pcmcia system can't be correctly shut down. If you want some PCMCIA
# partition to be mounted at boot (or when the card is inserted) then add
# the appropriate lines to /etc/pcmcia/scsi.opts.
#
# Note that the stuff in /etc/pcmcia/ is only for 2.4.x kernels using
# 16-bit PCMCIA cards (not 32-bit Cardbus cards!). For example, with a
# wireless card you might need to set options in /etc/pcmcia OR in
# /etc/rc.d/rc.wireless.conf, or even in /etc/rc.d/rc.inet1.conf (with
# extra options if needed for the encryption key, ESSID, etc.)
#
# Hopefully this situation will be unified in the future, but for now
# that's how it is...
#
if [ -x /etc/rc.d/rc.pcmcia -a -z "$container" ]; then
. /etc/rc.d/rc.pcmcia start
# The cards might need a little extra time here to initialize.
sleep 5
fi
# Start the system logger.
if [ -x /etc/rc.d/rc.syslog -a -x /usr/sbin/syslogd -a -d /var/log ]; then
. /etc/rc.d/rc.syslog start
fi
# Update the X font indexes:
if [ -x /usr/bin/fc-cache ]; then
echo "Updating X font indexes: /usr/bin/fc-cache -f &"
/usr/bin/fc-cache -f &
fi
# Run rc.udev again. This will start udev if it is not already running
# (for example, upon return from runlevel 1), otherwise it will trigger it
# to look for device changes and to generate persistent rules if needed.
if grep -wq sysfs /proc/mounts && grep -q devtmpfs /proc/filesystems ; then
if ! grep -wq nohotplug /proc/cmdline ; then
if [ -x /etc/rc.d/rc.udev -a -z "$container" ]; then
/bin/sh /etc/rc.d/rc.udev start
fi
fi
fi
# Initialize the networking hardware.
if [ -x /etc/rc.d/rc.inet1 ]; then
. /etc/rc.d/rc.inet1
fi
# Start D-Bus:
if [ -x /etc/rc.d/rc.messagebus ]; then
sh /etc/rc.d/rc.messagebus start
fi
# Start Bluetooth:
if [ -x /etc/rc.d/rc.bluetooth ]; then
sh /etc/rc.d/rc.bluetooth start
fi
# Start wicd or networkmanager:
if [ -x /etc/rc.d/rc.wicd -a -x /usr/sbin/wicd ]; then
sh /etc/rc.d/rc.wicd start
elif [ -x /etc/rc.d/rc.networkmanager ]; then
sh /etc/rc.d/rc.networkmanager start
fi
# Start networking daemons:
if [ -x /etc/rc.d/rc.inet2 ]; then
. /etc/rc.d/rc.inet2
fi
# Look for additional USB/SCSI/IEEE1394/etc devices on multiple LUNs:
if [ -x /etc/rc.d/rc.scanluns ]; then
. /etc/rc.d/rc.scanluns
fi
# Mount any additional filesystem types that haven't already been mounted:
mount -a -v 2> /dev/null | grep -v -e "already mounted" -e "ignored" | cut -f 1 -d : | tr -d ' ' | while read dev ; do mount | grep "${dev} " ; done
# Start the Control Script for automounter:
if [ -x /etc/rc.d/rc.autofs ]; then
sh /etc/rc.d/rc.autofs start
fi
# Start the Network Time Protocol daemon:
if [ -x /etc/rc.d/rc.ntpd ]; then
sh /etc/rc.d/rc.ntpd start
fi
# Remove stale locks and junk files (must be done after mount -a!)
/bin/rm -f /var/lock/* /var/spool/uucp/LCK..* /tmp/.X*lock /tmp/core /core 2> /dev/null
/bin/rm -rf /var/spool/cron/cron.?????? 2> /dev/null
# Remove stale hunt sockets so the game can start.
if [ -r /tmp/hunt -o -r /tmp/hunt.stats ]; then
echo "Removing your stale hunt sockets from /tmp."
/bin/rm -f /tmp/hunt*
fi
# Ensure basic filesystem permissions sanity.
chmod 755 / 2> /dev/null
chmod 1777 /tmp /var/tmp
# Start ACPI daemon.
if [ -x /etc/rc.d/rc.acpid -a -z "$container" ]; then
. /etc/rc.d/rc.acpid start
fi
# Enable CPU frequency scaling:
if [ -x /etc/rc.d/rc.cpufreq -a -z "$container" ]; then
. /etc/rc.d/rc.cpufreq start
fi
# Update any existing icon cache files:
if find /usr/share/icons -maxdepth 2 2> /dev/null | grep -q icon-theme.cache ; then
for theme_dir in /usr/share/icons/* ; do
if [ -r ${theme_dir}/icon-theme.cache ]; then
echo "Updating icon-theme.cache in ${theme_dir}..."
/usr/bin/gtk-update-icon-cache -t -f ${theme_dir} 1> /dev/null 2> /dev/null &
fi
done
# This would be a large file and probably shouldn't be there.
if [ -r /usr/share/icons/icon-theme.cache ]; then
echo "Deleting icon-theme.cache in /usr/share/icons..."
#/usr/bin/gtk-update-icon-cache -t -f /usr/share/icons 1> /dev/null 2> /dev/null &
rm -f /usr/share/icons/icon-theme.cache
fi
fi
# Update mime database:
if [ -x /usr/bin/update-mime-database -a -d /usr/share/mime ]; then
echo "Updating MIME database: /usr/bin/update-mime-database /usr/share/mime &"
/usr/bin/update-mime-database /usr/share/mime 1> /dev/null 2> /dev/null &
fi
# Start console-kit-daemon:
if [ -x /etc/rc.d/rc.consolekit ]; then
sh /etc/rc.d/rc.consolekit start
fi
# Start HAL:
if [ -x /etc/rc.d/rc.hald ]; then
sh /etc/rc.d/rc.hald start
fi
# Start system-wide PulseAudio daemon (not recommended, nor required in
# order to use PulseAudio -- see the script for details):
if [ -x /etc/rc.d/rc.pulseaudio ]; then
. /etc/rc.d/rc.pulseaudio start
fi
# These GTK+/pango files need to be kept up to date for
# proper input method, pixbuf loaders, and font support.
if [ -x /usr/bin/update-gtk-immodules ]; then
echo "Updating gtk.immodules:"
echo " /usr/bin/update-gtk-immodules &"
/usr/bin/update-gtk-immodules > /dev/null 2>&1 &
fi
if [ -x /usr/bin/update-gdk-pixbuf-loaders ]; then
echo "Updating gdk-pixbuf.loaders:"
echo " /usr/bin/update-gdk-pixbuf-loaders &"
/usr/bin/update-gdk-pixbuf-loaders > /dev/null 2>&1 &
fi
if [ -x /usr/bin/update-pango-querymodules ]; then
echo "Updating pango.modules:"
echo " /usr/bin/update-pango-querymodules &"
/usr/bin/update-pango-querymodules > /dev/null 2>&1 &
fi
if [ -x /usr/bin/glib-compile-schemas ]; then
echo "Compiling GSettings XML schema files:"
echo " /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &"
/usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas >/dev/null 2>&1 &
fi
# Start dnsmasq, a simple DHCP/DNS server:
if [ -x /etc/rc.d/rc.dnsmasq ]; then
/etc/rc.d/rc.dnsmasq start
fi
# Start snmpd:
if [ -x /etc/rc.d/rc.snmpd ]; then
/etc/rc.d/rc.snmpd start
fi
# Start the print spooling system. This will usually be LPRng (lpd) or CUPS.
if [ -x /etc/rc.d/rc.cups ]; then
# Start CUPS:
/etc/rc.d/rc.cups start
elif [ -x /etc/rc.d/rc.lprng ]; then
# Start LPRng (lpd):
. /etc/rc.d/rc.lprng start
fi
# Start netatalk. (a file/print server for Macs using Appletalk)
if [ -x /etc/rc.d/rc.atalk ]; then
/etc/rc.d/rc.atalk start
fi
# Start smartd, which monitors the status of S.M.A.R.T. compatible
# hard drives and reports any problems. Note some devices (which aren't
# smart, I guess ;) will hang if probed by smartd, so it's commented out
# by default.
#if [ -x /usr/sbin/smartd ]; then
# /usr/sbin/smartd
#fi
# Monitor the UPS with genpowerd.
# To use this, uncomment this section and edit your settings in
# /etc/genpowerd.conf (serial device, UPS type, etc). For more information,
# see "man genpowerd" or the extensive documentation in the
# /usr/doc/genpower-*/ directory.
# You'll also need to configure a similar block in /etc/rc.d/rc.6 if you want
# support for stopping the UPS's inverter after the machine halts.
#if [ -x /sbin/genpowerd ]; then
# echo "Starting genpowerd daemon..."
# /sbin/genpowerd
#fi
# Turn on process accounting. To enable process accounting, make sure the
# option for BSD process accounting is enabled in your kernel, and then
# create the file /var/log/pacct (touch /var/log/pacct). By default, process
# accounting is not enabled (since /var/log/pacct does not exist). This is
# because the log file can get VERY large.
if [ -x /sbin/accton -a -r /var/log/pacct ]; then
chmod 640 /var/log/pacct
/sbin/accton /var/log/pacct
fi
# Start crond (Dillon's crond):
# If you want cron to actually log activity to /var/log/cron, then change
# -l notice to -l info to increase the logging level.
if [ -x /usr/sbin/crond ]; then
/usr/sbin/crond -l notice
fi
# Start atd (manages jobs scheduled with 'at'):
if [ -x /usr/sbin/atd ]; then
/usr/sbin/atd -b 15 -l 1
fi
# Slackware-Mini-Quota-HOWTO:
# To really activate quotas, you'll need to add 'usrquota' and/or 'grpquota' to
# the appropriate partitions as listed in /etc/fstab. Here's an example:
#
# /dev/hda2 /home ext3 defaults,usrquota 1 1
#
# You'll then need to setup initial quota files at the top of the partitions
# to support quota, like this:
# touch /home/aquota.user /home/aquota.group
# chmod 600 /home/aquota.user /home/aquota.group
#
# Then, reboot to activate the system.
# To edit user quotas, use 'edquota'. See 'man edquota'. Also, the
# official Quota Mini-HOWTO has lots of useful information. That can be found
# here: /usr/doc/Linux-HOWTOs/Quota
# Check quotas and then turn quota system on:
if grep -q quota /etc/fstab ; then
for quotafs in $(awk '/quota/ {print $2}' /etc/fstab) ; do
/bin/rm -f $quotafs/{a,}quota.{group,user}.new
done
if [ -x /sbin/quotacheck ]; then
echo "Checking filesystem quotas: /sbin/quotacheck -avugm"
/sbin/quotacheck -avugm
fi
if [ -x /sbin/quotaon ]; then
echo "Activating filesystem quotas: /sbin/quotaon -avug"
/sbin/quotaon -avug
fi
fi
# Start the SASL authentication server. This provides SASL
# authentication services for sendmail:
if [ -x /etc/rc.d/rc.saslauthd ]; then
. /etc/rc.d/rc.saslauthd start
fi
# Start the sendmail daemon:
if [ -x /etc/rc.d/rc.sendmail ]; then
. /etc/rc.d/rc.sendmail start
fi
# Load ALSA (sound) defaults:
if [ -x /etc/rc.d/rc.alsa -a -z "$container" ]; then
. /etc/rc.d/rc.alsa
fi
# Load a custom screen font if the user has an rc.font script.
if [ -x /etc/rc.d/rc.font ]; then
. /etc/rc.d/rc.font
fi
# Load a custom keymap if the user has an rc.keymap script.
if [ -x /etc/rc.d/rc.keymap ]; then
. /etc/rc.d/rc.keymap
fi
# Start the MySQL database:
if [ -x /etc/rc.d/rc.mysqld ]; then
. /etc/rc.d/rc.mysqld start
fi
# Start Apache web server:
if [ -x /etc/rc.d/rc.httpd ]; then
. /etc/rc.d/rc.httpd start
fi
# Start OpenLDAP:
if [ -x /etc/rc.d/rc.openldap ]; then
. /etc/rc.d/rc.openldap start
fi
# Start Samba (a file/print server for Win95/NT machines).
# Samba can be started in /etc/inetd.conf instead.
if [ -x /etc/rc.d/rc.samba ]; then
. /etc/rc.d/rc.samba start
fi
# Start the GPM mouse server:
if [ -x /etc/rc.d/rc.gpm ]; then
. /etc/rc.d/rc.gpm start
fi
# If there are SystemV init scripts for this runlevel, run them.
if [ -x /etc/rc.d/rc.sysvinit ]; then
. /etc/rc.d/rc.sysvinit
fi
# Start the local setup procedure.
if [ -x /etc/rc.d/rc.local ]; then
. /etc/rc.d/rc.local
fi
# All done.

386
scripts/rc.M.orig

@ -0,0 +1,386 @@
#!/bin/sh
#
# rc.M This file is executed by init(8) when the system is being
# initialized for one of the "multi user" run levels (i.e.
# levels 1 through 6). It usually does mounting of file
# systems et al.
#
# Version: @(#)/etc/rc.d/rc.M 2.23 Wed Feb 26 19:20:58 PST 2003
#
# Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
# Heavily modified by Patrick Volkerding <volkerdi@slackware.com>
#
# Tell the viewers what's going to happen.
echo "Going multiuser..."
# Update all the shared library links:
if [ -x /sbin/ldconfig ]; then
echo "Updating shared library links: /sbin/ldconfig &"
/sbin/ldconfig &
fi
# Screen blanks after 15 minutes idle time, and powers down in one hour
# if the kernel supports APM or ACPI power management:
/bin/setterm -blank 15 -powersave powerdown -powerdown 60
# Set the hostname.
if [ -r /etc/HOSTNAME ]; then
/bin/hostname $(cat /etc/HOSTNAME | cut -f1 -d .)
else
# fall back on this old default:
echo "darkstar.example.net" > /etc/HOSTNAME
/bin/hostname darkstar
fi
# Set the permissions on /var/log/dmesg according to whether the kernel
# permits non-root users to access kernel dmesg information:
if [ -r /proc/sys/kernel/dmesg_restrict ]; then
if [ $(cat /proc/sys/kernel/dmesg_restrict) = 1 ]; then
touch /var/log/dmesg
chmod 640 /var/log/dmesg
fi
else
touch /var/log/dmesg
chmod 644 /var/log/dmesg
fi
# Save the contents of 'dmesg':
/bin/dmesg -s 65536 > /var/log/dmesg
# Initialize PCMCIA devices:
#
# NOTE: This used to be started near the top of rc.S so that PCMCIA devices
# could be fsck'ed along with the other drives. This had some unfortunate
# side effects, however, since root isn't yet read-write, and /var might not
# even be mounted the .pid files can't be correctly written in /var/run and
# the pcmcia system can't be correctly shut down. If you want some PCMCIA
# partition to be mounted at boot (or when the card is inserted) then add
# the appropriate lines to /etc/pcmcia/scsi.opts.
#
# Note that the stuff in /etc/pcmcia/ is only for 2.4.x kernels using
# 16-bit PCMCIA cards (not 32-bit Cardbus cards!). For example, with a
# wireless card you might need to set options in /etc/pcmcia OR in
# /etc/rc.d/rc.wireless.conf, or even in /etc/rc.d/rc.inet1.conf (with
# extra options if needed for the encryption key, ESSID, etc.)
#
# Hopefully this situation will be unified in the future, but for now
# that's how it is...
#
if [ -x /etc/rc.d/rc.pcmcia ]; then
. /etc/rc.d/rc.pcmcia start
# The cards might need a little extra time here to initialize.
sleep 5
fi
# Start the system logger.
if [ -x /etc/rc.d/rc.syslog -a -x /usr/sbin/syslogd -a -d /var/log ]; then
. /etc/rc.d/rc.syslog start
fi
# Update the X font indexes:
if [ -x /usr/bin/fc-cache ]; then
echo "Updating X font indexes: /usr/bin/fc-cache -f &"
/usr/bin/fc-cache -f &
fi
# Run rc.udev again. This will start udev if it is not already running
# (for example, upon return from runlevel 1), otherwise it will trigger it
# to look for device changes and to generate persistent rules if needed.
if grep -wq sysfs /proc/mounts && grep -q devtmpfs /proc/filesystems ; then
if ! grep -wq nohotplug /proc/cmdline ; then
if [ -x /etc/rc.d/rc.udev ]; then
/bin/sh /etc/rc.d/rc.udev start
fi
fi
fi
# Initialize the networking hardware.
if [ -x /etc/rc.d/rc.inet1 ]; then
. /etc/rc.d/rc.inet1
fi
# Start D-Bus:
if [ -x /etc/rc.d/rc.messagebus ]; then
sh /etc/rc.d/rc.messagebus start
fi
# Start Bluetooth:
if [ -x /etc/rc.d/rc.bluetooth ]; then
sh /etc/rc.d/rc.bluetooth start
fi
# Start wicd or networkmanager:
if [ -x /etc/rc.d/rc.wicd -a -x /usr/sbin/wicd ]; then
sh /etc/rc.d/rc.wicd start
elif [ -x /etc/rc.d/rc.networkmanager ]; then
sh /etc/rc.d/rc.networkmanager start
fi
# Start networking daemons:
if [ -x /etc/rc.d/rc.inet2 ]; then
. /etc/rc.d/rc.inet2
fi
# Look for additional USB/SCSI/IEEE1394/etc devices on multiple LUNs:
if [ -x /etc/rc.d/rc.scanluns ]; then
. /etc/rc.d/rc.scanluns
fi
# Mount any additional filesystem types that haven't already been mounted:
mount -a -v 2> /dev/null | grep -v -e "already mounted" -e "ignored" | cut -f 1 -d : | tr -d ' ' | while read dev ; do mount | grep "${dev} " ; done
# Start the Control Script for automounter:
if [ -x /etc/rc.d/rc.autofs ]; then
sh /etc/rc.d/rc.autofs start
fi
# Start the Network Time Protocol daemon:
if [ -x /etc/rc.d/rc.ntpd ]; then
sh /etc/rc.d/rc.ntpd start
fi
# Remove stale locks and junk files (must be done after mount -a!)
/bin/rm -f /var/lock/* /var/spool/uucp/LCK..* /tmp/.X*lock /tmp/core /core 2> /dev/null
/bin/rm -rf /var/spool/cron/cron.?????? 2> /dev/null
# Remove stale hunt sockets so the game can start.
if [ -r /tmp/hunt -o -r /tmp/hunt.stats ]; then
echo "Removing your stale hunt sockets from /tmp."
/bin/rm -f /tmp/hunt*
fi
# Ensure basic filesystem permissions sanity.
chmod 755 / 2> /dev/null
chmod 1777 /tmp /var/tmp
# Start ACPI daemon.
if [ -x /etc/rc.d/rc.acpid ]; then
. /etc/rc.d/rc.acpid start
fi
# Enable CPU frequency scaling:
if [ -x /etc/rc.d/rc.cpufreq ]; then
. /etc/rc.d/rc.cpufreq start
fi
# Update any existing icon cache files:
if find /usr/share/icons -maxdepth 2 2> /dev/null | grep -q icon-theme.cache ; then
for theme_dir in /usr/share/icons/* ; do
if [ -r ${theme_dir}/icon-theme.cache ]; then
echo "Updating icon-theme.cache in ${theme_dir}..."
/usr/bin/gtk-update-icon-cache -t -f ${theme_dir} 1> /dev/null 2> /dev/null &
fi
done
# This would be a large file and probably shouldn't be there.
if [ -r /usr/share/icons/icon-theme.cache ]; then
echo "Deleting icon-theme.cache in /usr/share/icons..."
#/usr/bin/gtk-update-icon-cache -t -f /usr/share/icons 1> /dev/null 2> /dev/null &
rm -f /usr/share/icons/icon-theme.cache
fi
fi
# Update mime database:
if [ -x /usr/bin/update-mime-database -a -d /usr/share/mime ]; then
echo "Updating MIME database: /usr/bin/update-mime-database /usr/share/mime &"
/usr/bin/update-mime-database /usr/share/mime 1> /dev/null 2> /dev/null &
fi
# Start console-kit-daemon:
if [ -x /etc/rc.d/rc.consolekit ]; then
sh /etc/rc.d/rc.consolekit start
fi
# Start HAL:
if [ -x /etc/rc.d/rc.hald ]; then
sh /etc/rc.d/rc.hald start
fi
# Start system-wide PulseAudio daemon (not recommended, nor required in
# order to use PulseAudio -- see the script for details):
if [ -x /etc/rc.d/rc.pulseaudio ]; then
. /etc/rc.d/rc.pulseaudio start
fi
# These GTK+/pango files need to be kept up to date for
# proper input method, pixbuf loaders, and font support.
if [ -x /usr/bin/update-gtk-immodules ]; then
echo "Updating gtk.immodules:"
echo " /usr/bin/update-gtk-immodules &"
/usr/bin/update-gtk-immodules > /dev/null 2>&1 &
fi
if [ -x /usr/bin/update-gdk-pixbuf-loaders ]; then
echo "Updating gdk-pixbuf.loaders:"
echo " /usr/bin/update-gdk-pixbuf-loaders &"
/usr/bin/update-gdk-pixbuf-loaders > /dev/null 2>&1 &
fi
if [ -x /usr/bin/update-pango-querymodules ]; then
echo "Updating pango.modules:"
echo " /usr/bin/update-pango-querymodules &"
/usr/bin/update-pango-querymodules > /dev/null 2>&1 &
fi
if [ -x /usr/bin/glib-compile-schemas ]; then
echo "Compiling GSettings XML schema files:"
echo " /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas &"
/usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas >/dev/null 2>&1 &
fi
# Start dnsmasq, a simple DHCP/DNS server:
if [ -x /etc/rc.d/rc.dnsmasq ]; then
/etc/rc.d/rc.dnsmasq start
fi
# Start snmpd:
if [ -x /etc/rc.d/rc.snmpd ]; then
/etc/rc.d/rc.snmpd start
fi
# Start the print spooling system. This will usually be LPRng (lpd) or CUPS.
if [ -x /etc/rc.d/rc.cups ]; then
# Start CUPS:
/etc/rc.d/rc.cups start
elif [ -x /etc/rc.d/rc.lprng ]; then
# Start LPRng (lpd):
. /etc/rc.d/rc.lprng start
fi
# Start netatalk. (a file/print server for Macs using Appletalk)
if [ -x /etc/rc.d/rc.atalk ]; then
/etc/rc.d/rc.atalk start
fi
# Start smartd, which monitors the status of S.M.A.R.T. compatible
# hard drives and reports any problems. Note some devices (which aren't
# smart, I guess ;) will hang if probed by smartd, so it's commented out
# by default.
#if [ -x /usr/sbin/smartd ]; then
# /usr/sbin/smartd
#fi
# Monitor the UPS with genpowerd.
# To use this, uncomment this section and edit your settings in
# /etc/genpowerd.conf (serial device, UPS type, etc). For more information,
# see "man genpowerd" or the extensive documentation in the
# /usr/doc/genpower-*/ directory.
# You'll also need to configure a similar block in /etc/rc.d/rc.6 if you want
# support for stopping the UPS's inverter after the machine halts.
#if [ -x /sbin/genpowerd ]; then
# echo "Starting genpowerd daemon..."
# /sbin/genpowerd
#fi
# Turn on process accounting. To enable process accounting, make sure the
# option for BSD process accounting is enabled in your kernel, and then
# create the file /var/log/pacct (touch /var/log/pacct). By default, process
# accounting is not enabled (since /var/log/pacct does not exist). This is
# because the log file can get VERY large.
if [ -x /sbin/accton -a -r /var/log/pacct ]; then
chmod 640 /var/log/pacct
/sbin/accton /var/log/pacct
fi
# Start crond (Dillon's crond):
# If you want cron to actually log activity to /var/log/cron, then change
# -l notice to -l info to increase the logging level.
if [ -x /usr/sbin/crond ]; then
/usr/sbin/crond -l notice
fi
# Start atd (manages jobs scheduled with 'at'):
if [ -x /usr/sbin/atd ]; then
/usr/sbin/atd -b 15 -l 1
fi
# Slackware-Mini-Quota-HOWTO:
# To really activate quotas, you'll need to add 'usrquota' and/or 'grpquota' to
# the appropriate partitions as listed in /etc/fstab. Here's an example:
#
# /dev/hda2 /home ext3 defaults,usrquota 1 1
#
# You'll then need to setup initial quota files at the top of the partitions
# to support quota, like this:
# touch /home/aquota.user /home/aquota.group
# chmod 600 /home/aquota.user /home/aquota.group
#
# Then, reboot to activate the system.
# To edit user quotas, use 'edquota'. See 'man edquota'. Also, the
# official Quota Mini-HOWTO has lots of useful information. That can be found
# here: /usr/doc/Linux-HOWTOs/Quota
# Check quotas and then turn quota system on:
if grep -q quota /etc/fstab ; then
for quotafs in $(awk '/quota/ {print $2}' /etc/fstab) ; do
/bin/rm -f $quotafs/{a,}quota.{group,user}.new
done
if [ -x /sbin/quotacheck ]; then
echo "Checking filesystem quotas: /sbin/quotacheck -avugm"
/sbin/quotacheck -avugm
fi
if [ -x /sbin/quotaon ]; then
echo "Activating filesystem quotas: /sbin/quotaon -avug"
/sbin/quotaon -avug
fi
fi
# Start the SASL authentication server. This provides SASL
# authentication services for sendmail:
if [ -x /etc/rc.d/rc.saslauthd ]; then
. /etc/rc.d/rc.saslauthd start
fi
# Start the sendmail daemon:
if [ -x /etc/rc.d/rc.sendmail ]; then
. /etc/rc.d/rc.sendmail start
fi
# Load ALSA (sound) defaults:
if [ -x /etc/rc.d/rc.alsa ]; then
. /etc/rc.d/rc.alsa
fi
# Load a custom screen font if the user has an rc.font script.
if [ -x /etc/rc.d/rc.font ]; then
. /etc/rc.d/rc.font
fi
# Load a custom keymap if the user has an rc.keymap script.
if [ -x /etc/rc.d/rc.keymap ]; then
. /etc/rc.d/rc.keymap
fi
# Start the MySQL database:
if [ -x /etc/rc.d/rc.mysqld ]; then
. /etc/rc.d/rc.mysqld start
fi
# Start Apache web server:
if [ -x /etc/rc.d/rc.httpd ]; then
. /etc/rc.d/rc.httpd start
fi
# Start OpenLDAP:
if [ -x /etc/rc.d/rc.openldap ]; then
. /etc/rc.d/rc.openldap start
fi
# Start Samba (a file/print server for Win95/NT machines).
# Samba can be started in /etc/inetd.conf instead.
if [ -x /etc/rc.d/rc.samba ]; then
. /etc/rc.d/rc.samba start
fi
# Start the GPM mouse server:
if [ -x /etc/rc.d/rc.gpm ]; then
. /etc/rc.d/rc.gpm start
fi
# If there are SystemV init scripts for this runlevel, run them.
if [ -x /etc/rc.d/rc.sysvinit ]; then
. /etc/rc.d/rc.sysvinit
fi
# Start the local setup procedure.
if [ -x /etc/rc.d/rc.local ]; then
. /etc/rc.d/rc.local
fi
# All done.

474
scripts/rc.S.lxc

@ -0,0 +1,474 @@
#!/bin/sh
#
# /etc/rc.d/rc.S: System initialization script.
#
# Mostly written by: Patrick J. Volkerding, <volkerdi@slackware.com>
#
# Set $container variable since this is a modified version of rc.S with
# changes for running in an lxc container. A check to see if this variable
# is set will be used to skip parts of the script that we don't want to run
# in a container. Thanks to Matteo Bernardini <ponce@slackbuilds.org> and
# Chris Willing for the initial work making this script lxc compatible.
container="lxc"
PATH=/sbin:/usr/sbin:/bin:/usr/bin
# Try to mount /proc:
if [ -z "$container" ]; then
/sbin/mount -v proc /proc -n -t proc 2> /dev/null
fi
# Mount sysfs next, if the kernel supports it:
if [ -d /sys -a -z "$container" ]; then
if grep -wq sysfs /proc/filesystems ; then
if ! grep -wq sysfs /proc/mounts ; then
/sbin/mount -v sysfs /sys -n -t sysfs
fi
fi
fi
# If /run exists, mount a tmpfs on it (unless the
# initrd has already done so):
if [ -d /run -a -z "$container" ]; then
if ! grep -wq "tmpfs /run tmpfs" /proc/mounts ; then
/sbin/mount -v -n -t tmpfs tmpfs /run -o mode=0755
fi
fi
# Load the loop device kernel module:
if [ -x /etc/rc.d/rc.loop -a -z "$container" ]; then
. /etc/rc.d/rc.loop start
fi
# Initialize udev to manage /dev entries and hotplugging.
# You may turn off udev by making the /etc/rc.d/rc.udev file non-executable
# or giving the "nohotplug" option at boot, but realize that if you turn off
# udev that you will have to load all the kernel modules that you need
# yourself (possibly in /etc/rc.d/rc.modules.local), and make any additional
# device nodes that you need in the /dev directory. Even USB and IEEE1394
# devices will need to have the modules loaded by hand if udev is not used.
# So use it. :-)
if grep -wq sysfs /proc/mounts && grep -q devtmpfs /proc/filesystems ; then
if ! grep -wq nohotplug /proc/cmdline ; then
if [ -x /etc/rc.d/rc.udev -a -z "$container" ]; then
/bin/sh /etc/rc.d/rc.udev start
fi
fi
fi
# Mount Control Groups filesystem interface:
if [ -z "$container" ]; then
if grep -wq cgroup /proc/filesystems ; then
if [ -d /sys/fs/cgroup ]; then
# See linux-*/Documentation/cgroups/cgroups.txt (section 1.6)
# Check if we have some tools to autodetect the available cgroup controllers
if [ -x /bin/cut -a -x /bin/tail ]; then
# Mount a tmpfs as the cgroup filesystem root
mount -t tmpfs -o mode=0755 cgroup_root /sys/fs/cgroup
# Autodetect available controllers and mount them in subfolders
controllers="$(/bin/cut -f 1 /proc/cgroups | /bin/tail -n +2)"
for i in $controllers; do
mkdir /sys/fs/cgroup/$i
mount -t cgroup -o $i $i /sys/fs/cgroup/$i
done
unset i controllers
else
# We can't use autodetection so fall back mounting them all together
mount -t cgroup cgroup /sys/fs/cgroup
fi
else
mkdir -p /dev/cgroup
mount -t cgroup cgroup /dev/cgroup
fi
fi
fi
# Initialize the Logical Volume Manager.
# This won't start unless we find /etc/lvmtab (LVM1) or
# /etc/lvm/backup/ (LVM2). This is created by /sbin/vgscan, so to
# use LVM you must run /sbin/vgscan yourself the first time (and
# create some VGs and LVs).
if [ -z "$container" ]; then
# Create LVM lock/run directories:
mkdir -p -m 0700 /run/lvm /run/lock /run/lock/lvm
if [ -r /etc/lvmtab -o -d /etc/lvm/backup ]; then
echo "Initializing LVM (Logical Volume Manager):"
# Check for device-mapper support.
if ! grep -wq device-mapper /proc/devices ; then
# Try to load a device-mapper kernel module:
/sbin/modprobe -q dm-mod
fi
# Scan for new volume groups:
/sbin/vgscan --mknodes --ignorelockingfailure 2> /dev/null
if [ $? = 0 ]; then
# Make volume groups available to the kernel.
# This should also make logical volumes available.
/sbin/vgchange -ay --ignorelockingfailure
fi
fi
fi
# Open any volumes created by cryptsetup.
#
# Some notes on /etc/crypttab in Slackware:
# Only LUKS formatted volumes are supported (except for swap)
# crypttab follows the following format:
# <luks_name> <device> <password> <options>
#
# <luks_name>: This is the name of your LUKS volume.
# For example: crypt-home
#
# <device>: This is the device containing your LUKS volume.
# For example: /dev/sda2
#
# <password>: This is either the volume password in plain text, or the name of
# a key file. Use 'none' to interactively enter password on boot.
#
# <options>: Comma-separated list of options. Note that there must be a
# password field for any options to be picked up (use a password of 'none' to
# get a password prompt at boot). The following options are supported:
#
# discard -- this will cause --allow-discards to be passed to the cryptsetup
# program while opening the LUKS volume.
#
# ro -- this will cause --readonly to be passed to the cryptsetup program while
# opening the LUKS volume.
#
# swap -- this option cannot be used with other options. The device given will
# be formatted as a new encrypted volume with a random key on boot, and used as
# swap.
#
if [ -f /etc/crypttab -a -x /sbin/cryptsetup -a -z "$container" ]; then
# First, check for device-mapper support.
if ! grep -wq device-mapper /proc/devices ; then
# If device-mapper exists as a module, try to load it.
# Try to load a device-mapper kernel module:
/sbin/modprobe -q dm-mod
fi
# NOTE: we only support LUKS formatted volumes (except for swap)!
cat /etc/crypttab | grep -v "^#" | grep -v "^$" | while read line; do
eval LUKSARRAY=( $line )
LUKS="${LUKSARRAY[0]}"
DEV="${LUKSARRAY[1]}"
PASS="${LUKSARRAY[2]}"
OPTS="${LUKSARRAY[3]}"
LUKSOPTS=""
if echo $OPTS | grep -wq ro ; then LUKSOPTS="${LUKSOPTS} --readonly" ; fi
if echo $OPTS | grep -wq discard ; then LUKSOPTS="${LUKSOPTS} --allow-discards" ; fi
# Skip LUKS volumes that were already unlocked (in the initrd):
/sbin/cryptsetup status $LUKS 2>/dev/null | head -n 1 | grep -q "is active" && continue
if /sbin/cryptsetup isLuks $DEV 2>/dev/null ; then
if [ -z "${LUKSOPTS}" ]; then
echo "Unlocking LUKS encrypted volume '${LUKS}' on device '$DEV':"
else
echo "Unlocking LUKS encrypted volume '${LUKS}' on device '$DEV' with options '${LUKSOPTS}':"
fi
if [ -n "${PASS}" -a "${PASS}" != "none" ]; then
if [ -f "${PASS}" ]; then
# A password was given a key-file filename
/sbin/cryptsetup ${LUKSOPTS} --key-file=${PASS} luksOpen $DEV $LUKS
else
# A password was provided in plain text
echo "${PASS}" | /sbin/cryptsetup ${LUKSOPTS} luksOpen $DEV $LUKS
fi
else
# No password was given, or a password of 'none' was given
/sbin/cryptsetup ${LUKSOPTS} luksOpen $DEV $LUKS </dev/tty0 >/dev/tty0 2>&1
fi
elif echo $OPTS | grep -wq swap ; then
# If any of the volumes is to be used as encrypted swap,
# then encrypt it using a random key and run mkswap:
echo "Creating encrypted swap volume '${LUKS}' on device '$DEV':"
/sbin/cryptsetup --cipher=aes --key-file=/dev/urandom --key-size=256 create $LUKS $DEV
mkswap /dev/mapper/$LUKS
fi
done
fi
# Enable swapping:
if [ -z "$container" ]; then
/sbin/swapon -a 2> /dev/null
fi
# Start FUSE, if requested:
if [ -x /etc/rc.d/rc.fuse -a -z "$container" ]; then
sh /etc/rc.d/rc.fuse start
fi
# Set the tick and frequency for the system clock.
# Default values are: TICK=10000 and FREQ=0
if [ -z "$container" ]; then
TICK=10000
FREQ=0
# If there's a /etc/default/adjtimex config file, source it to override
# the default TICK and FREQ:
if [ -r /etc/default/adjtimex ]; then
. /etc/default/adjtimex
fi
if /sbin/adjtimex --tick $TICK --frequency $FREQ; then
echo "Setting the system clock rate: /sbin/adjtimex --tick $TICK --frequency $FREQ"
else
echo "Failed to set system clock with adjtimex, possibly invalid parameters? (TICK=$TICK FREQ=$FREQ)"
fi
fi
# Set the system time from the hardware clock using hwclock --hctosys.
if [ -x /sbin/hwclock -a -z "$container" ]; then
# Check for a broken motherboard RTC clock (where ioports for rtc are
# unknown) to prevent hwclock causing a hang:
if ! grep -q " : rtc" /proc/ioports ; then
CLOCK_OPT="--directisa"
fi
if [ /etc/adjtime -nt /etc/hardwareclock ]; then
if grep -q "^LOCAL" /etc/adjtime ; then
echo -n "Setting system time from the hardware clock (localtime): "
else
echo -n "Setting system time from the hardware clock (UTC): "
fi
/sbin/hwclock $CLOCK_OPT --hctosys
elif grep -wq "^localtime" /etc/hardwareclock 2> /dev/null ; then
echo -n "Setting system time from the hardware clock (localtime): "
/sbin/hwclock $CLOCK_OPT --localtime --hctosys
else
echo -n "Setting system time from the hardware clock (UTC): "
/sbin/hwclock $CLOCK_OPT --utc --hctosys
fi
date
fi
# Test to see if the root partition is read-only, like it ought to be.
if [ -z "$container" ]; then
READWRITE=no
if touch /fsrwtestfile 2>/dev/null; then
rm -f /fsrwtestfile
READWRITE=yes
else
echo "Testing root filesystem status: read-only filesystem"
fi
fi
# See if a forced filesystem check was requested at shutdown:
if [ -r /etc/forcefsck -a -z "$container" ]; then
FORCEFSCK="-f"
fi
# Check the root filesystem:
if [ -z "$container" ]; then
if [ ! $READWRITE = yes ]; then
RETVAL=0
if [ ! -r /etc/fastboot ]; then
echo "Checking root filesystem:"
/sbin/fsck $FORCEFSCK -C -a /
RETVAL=$?
fi
# An error code of 2 or higher will require a reboot.
if [ $RETVAL -ge 2 ]; then
# An error code equal to or greater than 4 means that some errors
# could not be corrected. This requires manual attention, so we
# offer a chance to try to fix the problem in single-user mode:
if [ $RETVAL -ge 4 ]; then
echo
echo "***********************************************************"
echo "*** An error occurred during the root filesystem check. ***"
echo "*** You will now be given a chance to log into the ***"
echo "*** system in single-user mode to fix the problem. ***"
echo "*** ***"
echo "*** If you are using the ext2 filesystem, running ***"
echo "*** 'e2fsck -v -y <partition>' might help. ***"
echo "***********************************************************"
echo
echo "Once you exit the single-user shell, the system will reboot."
echo
PS1="(Repair filesystem) \#"; export PS1
sulogin
else # With an error code of 2 or 3, reboot the machine automatically:
echo
echo "***********************************"
echo "*** The filesystem was changed. ***"
echo "*** The system will now reboot. ***"
echo "***********************************"
echo
fi
echo "Unmounting file systems."
/sbin/umount -a -r
/sbin/mount -n -o remount,ro /
echo "Rebooting system."
sleep 2
reboot -f
fi
# Remount the root filesystem in read-write mode
echo "Remounting root device with read-write enabled."
/sbin/mount -w -v -n -o remount /
if [ $? -gt 0 ] ; then
echo "FATAL: Attempt to remount root device as read-write failed! This is going to"
echo "cause serious problems."
fi
else
echo "Testing root filesystem status: read-write filesystem"
echo
echo "ERROR: Root partition has already been mounted read-write. Cannot check!"
echo
echo "For filesystem checking to work properly, your system must initially mount"
echo "the root partition as read only. If you're booting with LILO, add a line:"
echo
echo " read-only"
echo
echo "to the Linux section in your /etc/lilo.conf and type 'lilo' to reinstall it."
fi
fi # Done checking root filesystem
# Any /etc/mtab that exists here is old, so we start with a new one:
/bin/rm -f /etc/mtab{,~,.tmp} && /bin/touch /etc/mtab
# Add entry for / to /etc/mtab:
if [ -z "$container" ]; then
/sbin/mount -f -w /
fi
# Add /proc, /sys, and /dev/shm mounts to /etc/mtab:
if [ -z "$container" ]; then
if [ -d /proc/sys ]; then
/sbin/mount -f -t proc proc /proc
fi
if [ -d /sys/bus ]; then
/sbin/mount -f -t sysfs sysfs /sys
fi
if grep -q '^[^ ]\+ /dev/shm ' /proc/mounts 2> /dev/null ; then
/sbin/mount -f -t tmpfs tmpfs /dev/shm
fi
fi
# Configure ISA Plug-and-Play devices:
if [ -r /etc/isapnp.conf -a -z "$container" ]; then
if [ -x /sbin/isapnp ]; then
/sbin/isapnp /etc/isapnp.conf
fi
fi
# Run the kernel module script. This updates the module dependencies and
# also supports manually loading kernel modules through rc.modules.local.
if [ -x /etc/rc.d/rc.modules -a -z "$container" ]; then
. /etc/rc.d/rc.modules
fi
# Configure kernel parameters:
if [ -x /sbin/sysctl -a -r /etc/sysctl.conf -a -z "$container" ]; then
echo "Configuring kernel parameters: /sbin/sysctl -e --system"
/sbin/sysctl -e --system
elif [ -x /sbin/sysctl -a -z "$container" ]; then
echo "Configuring kernel parameters: /sbin/sysctl -e --system"
# Don't say "Applying /etc/sysctl.conf" or complain if the file doesn't exist
/sbin/sysctl -e --system 2> /dev/null | grep -v "Applying /etc/sysctl.conf"
fi
# Check all the non-root filesystems:
if [ ! -r /etc/fastboot -a -z "$container" ]; then
echo "Checking non-root filesystems:"
/sbin/fsck $FORCEFSCK -C -R -A -a
fi
# Mount usbfs only if it is found in /etc/fstab:
if [ -z "$container" ]; then
if grep -wq usbfs /proc/filesystems; then
if ! grep -wq usbfs /proc/mounts ; then
if grep -wq usbfs /etc/fstab; then
/sbin/mount -v /proc/bus/usb
fi
fi
fi
fi
# Mount non-root file systems in fstab, but not NFS or SMB
# because TCP/IP is not yet configured, and not proc or sysfs
# because those have already been mounted. Also check that
# devpts is not already mounted before attempting to mount
# it. With a 2.6.x or newer kernel udev mounts devpts.
# We also need to wait a little bit to let USB and other
# hotplugged devices settle (sorry to slow down the boot):
if [ -z "$container" ]; then
echo "Mounting non-root local filesystems:"
sleep 3
if /bin/grep -wq devpts /proc/mounts ; then
# This pipe after the mount command is just to convert the new
# mount verbose output back to the old format that contained
# more useful information:
/sbin/mount -a -v -t nonfs,nosmbfs,nocifs,noproc,nosysfs,nodevpts | grep successfully | cut -f 1 -d : | tr -d ' ' | while read dev ; do mount | grep "${dev} " ; done
else
/sbin/mount -a -v -t nonfs,nosmbfs,nocifs,noproc,nosysfs | grep successfully | cut -f 1 -d : | tr -d ' ' | while read dev ; do mount | grep "${dev} " ; done
fi
fi
# Enable swapping again. This is needed in case a swapfile is used,
# as it can't be enabled until the filesystem it resides on has been
# mounted read-write.
if [ -z "$container" ]; then
/sbin/swapon -a 2> /dev/null
fi
# Start cgmanager (or cgproxy in a container):
if [ -x /etc/rc.d/rc.cgmanager -a -d /sys/fs/cgroup ]; then
sh /etc/rc.d/rc.cgmanager start
fi
# Clean up some temporary files:
rm -f /var/run/* /var/run/*/* /var/run/*/*/* /etc/nologin \
/etc/dhcpc/*.pid /etc/forcefsck /etc/fastboot \
/var/state/saslauthd/saslauthd.pid \
/tmp/.Xauth* 1> /dev/null 2> /dev/null
( cd /var/log/setup/tmp && rm -rf * )
( cd /tmp && rm -rf kde-[a-zA-Z]* ksocket-[a-zA-Z]* hsperfdata_[a-zA-Z]* plugtmp* )
# Clear /var/lock/subsys:
if [ -d /var/lock/subsys ]; then
rm -f /var/lock/subsys/*
fi
# Create /tmp/{.ICE-unix,.X11-unix} if they are not present:
if [ ! -e /tmp/.ICE-unix ]; then
mkdir -p /tmp/.ICE-unix
chmod 1777 /tmp/.ICE-unix
fi
if [ ! -e /tmp/.X11-unix ]; then
mkdir -p /tmp/.X11-unix
chmod 1777 /tmp/.X11-unix
fi
# Create a fresh utmp file:
touch /var/run/utmp
chown root:utmp /var/run/utmp
chmod 664 /var/run/utmp
# Update the current kernel level in the /etc/motd (Message Of The Day) file,
# if the first line of that file begins with the word 'Linux'.
# You are free to modify the rest of the file as you see fit.
if [ -x /bin/sed ]; then
/bin/sed -i "{1s/^Linux.*/$(/bin/uname -sr)\./}" /etc/motd
fi
# If there are SystemV init scripts for this runlevel, run them.
if [ -x /etc/rc.d/rc.sysvinit ]; then
. /etc/rc.d/rc.sysvinit
fi
# Run serial port setup script:
# CAREFUL! This can make some systems hang if the rc.serial script isn't
# set up correctly. If this happens, you may have to edit the file from a
# boot disk, and/or set it as non-executable:
if [ -x /etc/rc.d/rc.serial -a -z "$container" ]; then
sh /etc/rc.d/rc.serial start
fi
# Carry an entropy pool between reboots to improve randomness.
if [ -f /etc/random-seed ]; then
echo "Using /etc/random-seed to initialize /dev/urandom."
cat /etc/random-seed > /dev/urandom
fi
# Use the pool size from /proc, or 4096 bits:
if [ -r /proc/sys/kernel/random/poolsize ]; then
dd if=/dev/urandom of=/etc/random-seed count=1 bs=$(expr $(cat /proc/sys/kernel/random/poolsize) / 8) 2> /dev/null
else
dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null
fi
chmod 600 /etc/random-seed

445
scripts/rc.S.orig

@ -0,0 +1,445 @@
#!/bin/sh
#
# /etc/rc.d/rc.S: System initialization script.
#
# Mostly written by: Patrick J. Volkerding, <volkerdi@slackware.com>
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin
# Try to mount /proc:
/sbin/mount -v proc /proc -n -t proc 2> /dev/null
# Mount sysfs next, if the kernel supports it:
if [ -d /sys ]; then
if grep -wq sysfs /proc/filesystems ; then
if ! grep -wq sysfs /proc/mounts ; then
/sbin/mount -v sysfs /sys -n -t sysfs
fi
fi
fi
# If /run exists, mount a tmpfs on it (unless the
# initrd has already done so):
if [ -d /run ]; then
if ! grep -wq "tmpfs /run tmpfs" /proc/mounts ; then
/sbin/mount -v -n -t tmpfs tmpfs /run -o mode=0755
fi
fi
# Load the loop device kernel module:
if [ -x /etc/rc.d/rc.loop ]; then
. /etc/rc.d/rc.loop start
fi
# Initialize udev to manage /dev entries and hotplugging.
# You may turn off udev by making the /etc/rc.d/rc.udev file non-executable
# or giving the "nohotplug" option at boot, but realize that if you turn off
# udev that you will have to load all the kernel modules that you need
# yourself (possibly in /etc/rc.d/rc.modules.local), and make any additional
# device nodes that you need in the /dev directory. Even USB and IEEE1394
# devices will need to have the modules loaded by hand if udev is not used.
# So use it. :-)
if grep -wq sysfs /proc/mounts && grep -q devtmpfs /proc/filesystems ; then
if ! grep -wq nohotplug /proc/cmdline ; then
if [ -x /etc/rc.d/rc.udev ]; then
/bin/sh /etc/rc.d/rc.udev start
fi
fi
fi
# Mount Control Groups filesystem interface:
if grep -wq cgroup /proc/filesystems ; then
if [ -d /sys/fs/cgroup ]; then
# See linux-*/Documentation/cgroups/cgroups.txt (section 1.6)
# Check if we have some tools to autodetect the available cgroup controllers
if [ -x /bin/cut -a -x /bin/tail ]; then
# Mount a tmpfs as the cgroup filesystem root
mount -t tmpfs -o mode=0755 cgroup_root /sys/fs/cgroup
# Autodetect available controllers and mount them in subfolders
controllers="$(/bin/cut -f 1 /proc/cgroups | /bin/tail -n +2)"
for i in $controllers; do
mkdir /sys/fs/cgroup/$i
mount -t cgroup -o $i $i /sys/fs/cgroup/$i
done
unset i controllers
else
# We can't use autodetection so fall back mounting them all together
mount -t cgroup cgroup /sys/fs/cgroup
fi
else
mkdir -p /dev/cgroup
mount -t cgroup cgroup /dev/cgroup
fi
fi
# Initialize the Logical Volume Manager.
# This won't start unless we find /etc/lvmtab (LVM1) or
# /etc/lvm/backup/ (LVM2). This is created by /sbin/vgscan, so to
# use LVM you must run /sbin/vgscan yourself the first time (and
# create some VGs and LVs).
# Create LVM lock/run directories:
mkdir -p -m 0700 /run/lvm /run/lock /run/lock/lvm
if [ -r /etc/lvmtab -o -d /etc/lvm/backup ]; then
echo "Initializing LVM (Logical Volume Manager):"
# Check for device-mapper support.
if ! grep -wq device-mapper /proc/devices ; then
# Try to load a device-mapper kernel module:
/sbin/modprobe -q dm-mod
fi
# Scan for new volume groups:
/sbin/vgscan --mknodes --ignorelockingfailure 2> /dev/null
if [ $? = 0 ]; then
# Make volume groups available to the kernel.
# This should also make logical volumes available.
/sbin/vgchange -ay --ignorelockingfailure
fi
fi
# Open any volumes created by cryptsetup.
#
# Some notes on /etc/crypttab in Slackware:
# Only LUKS formatted volumes are supported (except for swap)
# crypttab follows the following format:
# <luks_name> <device> <password> <options>
#
# <luks_name>: This is the name of your LUKS volume.
# For example: crypt-home
#
# <device>: This is the device containing your LUKS volume.
# For example: /dev/sda2
#
# <password>: This is either the volume password in plain text, or the name of
# a key file. Use 'none' to interactively enter password on boot.
#
# <options>: Comma-separated list of options. Note that there must be a
# password field for any options to be picked up (use a password of 'none' to
# get a password prompt at boot). The following options are supported:
#
# discard -- this will cause --allow-discards to be passed to the cryptsetup
# program while opening the LUKS volume.
#
# ro -- this will cause --readonly to be passed to the cryptsetup program while
# opening the LUKS volume.
#
# swap -- this option cannot be used with other options. The device given will
# be formatted as a new encrypted volume with a random key on boot, and used as
# swap.
#
if [ -f /etc/crypttab -a -x /sbin/cryptsetup ]; then
# First, check for device-mapper support.
if ! grep -wq device-mapper /proc/devices ; then
# If device-mapper exists as a module, try to load it.
# Try to load a device-mapper kernel module:
/sbin/modprobe -q dm-mod
fi
# NOTE: we only support LUKS formatted volumes (except for swap)!
cat /etc/crypttab | grep -v "^#" | grep -v "^$" | while read line; do
eval LUKSARRAY=( $line )
LUKS="${LUKSARRAY[0]}"
DEV="${LUKSARRAY[1]}"
PASS="${LUKSARRAY[2]}"
OPTS="${LUKSARRAY[3]}"
LUKSOPTS=""
if echo $OPTS | grep -wq ro ; then LUKSOPTS="${LUKSOPTS} --readonly" ; fi
if echo $OPTS | grep -wq discard ; then LUKSOPTS="${LUKSOPTS} --allow-discards" ; fi
# Skip LUKS volumes that were already unlocked (in the initrd):
/sbin/cryptsetup status $LUKS 2>/dev/null | head -n 1 | grep -q "is active" && continue
if /sbin/cryptsetup isLuks $DEV 2>/dev/null ; then
if [ -z "${LUKSOPTS}" ]; then
echo "Unlocking LUKS encrypted volume '${LUKS}' on device '$DEV':"
else
echo "Unlocking LUKS encrypted volume '${LUKS}' on device '$DEV' with options '${LUKSOPTS}':"
fi
if [ -n "${PASS}" -a "${PASS}" != "none" ]; then
if [ -f "${PASS}" ]; then
# A password was given a key-file filename
/sbin/cryptsetup ${LUKSOPTS} --key-file=${PASS} luksOpen $DEV $LUKS
else
# A password was provided in plain text
echo "${PASS}" | /sbin/cryptsetup ${LUKSOPTS} luksOpen $DEV $LUKS
fi
else
# No password was given, or a password of 'none' was given
/sbin/cryptsetup ${LUKSOPTS} luksOpen $DEV $LUKS </dev/tty0 >/dev/tty0 2>&1
fi
elif echo $OPTS | grep -wq swap ; then
# If any of the volumes is to be used as encrypted swap,
# then encrypt it using a random key and run mkswap:
echo "Creating encrypted swap volume '${LUKS}' on device '$DEV':"
/sbin/cryptsetup --cipher=aes --key-file=/dev/urandom --key-size=256 create $LUKS $DEV
mkswap /dev/mapper/$LUKS
fi
done
fi
# Enable swapping:
/sbin/swapon -a 2> /dev/null
# Start FUSE, if requested:
if [ -x /etc/rc.d/rc.fuse ]; then
sh /etc/rc.d/rc.fuse start
fi
# Set the tick and frequency for the system clock.
# Default values are: TICK=10000 and FREQ=0
TICK=10000
FREQ=0
# If there's a /etc/default/adjtimex config file, source it to override
# the default TICK and FREQ:
if [ -r /etc/default/adjtimex ]; then
. /etc/default/adjtimex
fi
if /sbin/adjtimex --tick $TICK --frequency $FREQ; then
echo "Setting the system clock rate: /sbin/adjtimex --tick $TICK --frequency $FREQ"
else
echo "Failed to set system clock with adjtimex, possibly invalid parameters? (TICK=$TICK FREQ=$FREQ)"
fi
# Set the system time from the hardware clock using hwclock --hctosys.
if [ -x /sbin/hwclock ]; then
# Check for a broken motherboard RTC clock (where ioports for rtc are
# unknown) to prevent hwclock causing a hang:
if ! grep -q " : rtc" /proc/ioports ; then
CLOCK_OPT="--directisa"
fi
if [ /etc/adjtime -nt /etc/hardwareclock ]; then
if grep -q "^LOCAL" /etc/adjtime ; then
echo -n "Setting system time from the hardware clock (localtime): "
else
echo -n "Setting system time from the hardware clock (UTC): "
fi
/sbin/hwclock $CLOCK_OPT --hctosys
elif grep -wq "^localtime" /etc/hardwareclock 2> /dev/null ; then
echo -n "Setting system time from the hardware clock (localtime): "
/sbin/hwclock $CLOCK_OPT --localtime --hctosys
else
echo -n "Setting system time from the hardware clock (UTC): "
/sbin/hwclock $CLOCK_OPT --utc --hctosys
fi
date
fi
# Test to see if the root partition is read-only, like it ought to be.
READWRITE=no
if touch /fsrwtestfile 2>/dev/null; then
rm -f /fsrwtestfile
READWRITE=yes
else
echo "Testing root filesystem status: read-only filesystem"
fi
# See if a forced filesystem check was requested at shutdown:
if [ -r /etc/forcefsck ]; then
FORCEFSCK="-f"
fi
# Check the root filesystem:
if [ ! $READWRITE = yes ]; then
RETVAL=0
if [ ! -r /etc/fastboot ]; then
echo "Checking root filesystem:"
/sbin/fsck $FORCEFSCK -C -a /
RETVAL=$?
fi
# An error code of 2 or higher will require a reboot.
if [ $RETVAL -ge 2 ]; then
# An error code equal to or greater than 4 means that some errors
# could not be corrected. This requires manual attention, so we
# offer a chance to try to fix the problem in single-user mode:
if [ $RETVAL -ge 4 ]; then
echo
echo "***********************************************************"
echo "*** An error occurred during the root filesystem check. ***"
echo "*** You will now be given a chance to log into the ***"
echo "*** system in single-user mode to fix the problem. ***"
echo "*** ***"
echo "*** If you are using the ext2 filesystem, running ***"
echo "*** 'e2fsck -v -y <partition>' might help. ***"
echo "***********************************************************"
echo
echo "Once you exit the single-user shell, the system will reboot."
echo
PS1="(Repair filesystem) \#"; export PS1
sulogin
else # With an error code of 2 or 3, reboot the machine automatically:
echo
echo "***********************************"
echo "*** The filesystem was changed. ***"
echo "*** The system will now reboot. ***"
echo "***********************************"
echo
fi
echo "Unmounting file systems."
/sbin/umount -a -r
/sbin/mount -n -o remount,ro /
echo "Rebooting system."
sleep 2
reboot -f
fi
# Remount the root filesystem in read-write mode
echo "Remounting root device with read-write enabled."
/sbin/mount -w -v -n -o remount /
if [ $? -gt 0 ] ; then
echo "FATAL: Attempt to remount root device as read-write failed! This is going to"
echo "cause serious problems."
fi
else
echo "Testing root filesystem status: read-write filesystem"
echo
echo "ERROR: Root partition has already been mounted read-write. Cannot check!"
echo
echo "For filesystem checking to work properly, your system must initially mount"
echo "the root partition as read only. If you're booting with LILO, add a line:"
echo
echo " read-only"
echo
echo "to the Linux section in your /etc/lilo.conf and type 'lilo' to reinstall it."
fi # Done checking root filesystem
# Any /etc/mtab that exists here is old, so we start with a new one:
/bin/rm -f /etc/mtab{,~,.tmp} && /bin/touch /etc/mtab
# Add entry for / to /etc/mtab:
/sbin/mount -f -w /
# Add /proc, /sys, and /dev/shm mounts to /etc/mtab:
if [ -d /proc/sys ]; then
/sbin/mount -f -t proc proc /proc
fi
if [ -d /sys/bus ]; then
/sbin/mount -f -t sysfs sysfs /sys
fi
if grep -q '^[^ ]\+ /dev/shm ' /proc/mounts 2> /dev/null ; then
/sbin/mount -f -t tmpfs tmpfs /dev/shm
fi
# Configure ISA Plug-and-Play devices:
if [ -r /etc/isapnp.conf ]; then
if [ -x /sbin/isapnp ]; then
/sbin/isapnp /etc/isapnp.conf
fi
fi
# Run the kernel module script. This updates the module dependencies and
# also supports manually loading kernel modules through rc.modules.local.
if [ -x /etc/rc.d/rc.modules ]; then
. /etc/rc.d/rc.modules
fi
# Configure kernel parameters:
if [ -x /sbin/sysctl -a -r /etc/sysctl.conf ]; then
echo "Configuring kernel parameters: /sbin/sysctl -e --system"
/sbin/sysctl -e --system
elif [ -x /sbin/sysctl ]; then
echo "Configuring kernel parameters: /sbin/sysctl -e --system"
# Don't say "Applying /etc/sysctl.conf" or complain if the file doesn't exist
/sbin/sysctl -e --system 2> /dev/null | grep -v "Applying /etc/sysctl.conf"
fi
# Check all the non-root filesystems:
if [ ! -r /etc/fastboot ]; then
echo "Checking non-root filesystems:"
/sbin/fsck $FORCEFSCK -C -R -A -a
fi
# Mount usbfs only if it is found in /etc/fstab:
if grep -wq usbfs /proc/filesystems; then
if ! grep -wq usbfs /proc/mounts ; then
if grep -wq usbfs /etc/fstab; then
/sbin/mount -v /proc/bus/usb
fi
fi
fi
# Mount non-root file systems in fstab, but not NFS or SMB
# because TCP/IP is not yet configured, and not proc or sysfs
# because those have already been mounted. Also check that
# devpts is not already mounted before attempting to mount
# it. With a 2.6.x or newer kernel udev mounts devpts.
# We also need to wait a little bit to let USB and other
# hotplugged devices settle (sorry to slow down the boot):
echo "Mounting non-root local filesystems:"
sleep 3
if /bin/grep -wq devpts /proc/mounts ; then
# This pipe after the mount command is just to convert the new
# mount verbose output back to the old format that contained
# more useful information:
/sbin/mount -a -v -t nonfs,nosmbfs,nocifs,noproc,nosysfs,nodevpts | grep successfully | cut -f 1 -d : | tr -d ' ' | while read dev ; do mount | grep "${dev} " ; done
else
/sbin/mount -a -v -t nonfs,nosmbfs,nocifs,noproc,nosysfs | grep successfully | cut -f 1 -d : | tr -d ' ' | while read dev ; do mount | grep "${dev} " ; done
fi
# Enable swapping again. This is needed in case a swapfile is used,
# as it can't be enabled until the filesystem it resides on has been
# mounted read-write.
/sbin/swapon -a 2> /dev/null
# Start cgmanager (or cgproxy in a container):
if [ -x /etc/rc.d/rc.cgmanager -a -d /sys/fs/cgroup ]; then
sh /etc/rc.d/rc.cgmanager start
fi
# Clean up some temporary files:
rm -f /var/run/* /var/run/*/* /var/run/*/*/* /etc/nologin \
/etc/dhcpc/*.pid /etc/forcefsck /etc/fastboot \
/var/state/saslauthd/saslauthd.pid \
/tmp/.Xauth* 1> /dev/null 2> /dev/null
( cd /var/log/setup/tmp && rm -rf * )
( cd /tmp && rm -rf kde-[a-zA-Z]* ksocket-[a-zA-Z]* hsperfdata_[a-zA-Z]* plugtmp* )
# Clear /var/lock/subsys:
if [ -d /var/lock/subsys ]; then
rm -f /var/lock/subsys/*
fi
# Create /tmp/{.ICE-unix,.X11-unix} if they are not present:
if [ ! -e /tmp/.ICE-unix ]; then
mkdir -p /tmp/.ICE-unix
chmod 1777 /tmp/.ICE-unix
fi
if [ ! -e /tmp/.X11-unix ]; then
mkdir -p /tmp/.X11-unix
chmod 1777 /tmp/.X11-unix
fi
# Create a fresh utmp file:
touch /var/run/utmp
chown root:utmp /var/run/utmp
chmod 664 /var/run/utmp
# Update the current kernel level in the /etc/motd (Message Of The Day) file,
# if the first line of that file begins with the word 'Linux'.
# You are free to modify the rest of the file as you see fit.
if [ -x /bin/sed ]; then
/bin/sed -i "{1s/^Linux.*/$(/bin/uname -sr)\./}" /etc/motd
fi
# If there are SystemV init scripts for this runlevel, run them.
if [ -x /etc/rc.d/rc.sysvinit ]; then
. /etc/rc.d/rc.sysvinit
fi
# Run serial port setup script:
# CAREFUL! This can make some systems hang if the rc.serial script isn't
# set up correctly. If this happens, you may have to edit the file from a
# boot disk, and/or set it as non-executable:
if [ -x /etc/rc.d/rc.serial ]; then
sh /etc/rc.d/rc.serial start
fi
# Carry an entropy pool between reboots to improve randomness.
if [ -f /etc/random-seed ]; then
echo "Using /etc/random-seed to initialize /dev/urandom."
cat /etc/random-seed > /dev/urandom
fi
# Use the pool size from /proc, or 4096 bits:
if [ -r /proc/sys/kernel/random/poolsize ]; then
dd if=/dev/urandom of=/etc/random-seed count=1 bs=$(expr $(cat /proc/sys/kernel/random/poolsize) / 8) 2> /dev/null
else
dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null
fi
chmod 600 /etc/random-seed

331
scripts/rc.inet1.lxc

@ -0,0 +1,331 @@
#! /bin/sh
# /etc/rc.d/rc.inet1
# This script is used to bring up the various network interfaces.
#
# @(#)/etc/rc.d/rc.inet1 10.2 Sun Jul 24 12:45:56 PDT 2005 (pjv)
# Set $container variable since this is a modified version of rc.inet1 with
# changes for running in an lxc container. A check to see if this variable
# is set will be used to skip parts of the script that we don't want to run
# in a container. Thanks to Matteo Bernardini <ponce@slackbuilds.org> and
# Chris Willing for the initial work making this script lxc compatible.
container="lxc"
############################
# READ NETWORK CONFIG FILE #
############################
# Get the configuration information from /etc/rc.d/rc.inet1.conf:
. /etc/rc.d/rc.inet1.conf
###########
# LOGGING #
###########
# If possible, log events in /var/log/messages:
if [ -f /var/run/syslogd.pid -a -x /usr/bin/logger ]; then
LOGGER=/usr/bin/logger
else # output to stdout/stderr:
LOGGER=/bin/cat
fi
############################
# DETERMINE INTERFACE LIST #
############################
# Compose a list of interfaces from /etc/rc.d/rc.inet1.conf (with a maximum
# of 6 interfaces, but you can easily enlarge the interface limit
# - send me a picture of such a box :-).
# If a value for IFNAME[n] is not set, we assume it is an eth'n' interface.
# This way, the new script is compatible with older rc.inet1.conf files.
# The IFNAME array will be used to determine which interfaces to bring up/down.
MAXNICS=${MAXNICS:-6}
i=0
while [ $i -lt $MAXNICS ];
do
IFNAME[$i]=${IFNAME[$i]:=eth${i}}
i=$(($i+1))
done
if [ "$DEBUG_ETH_UP" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: List of interfaces: '${IFNAME[@]}'" | $LOGGER
fi
######################
# LOOPBACK FUNCTIONS #
######################
# Function to bring up the loopback interface. If loopback is
# already up, do nothing.
lo_up() {
if grep lo: /proc/net/dev 1> /dev/null ; then
if ! /sbin/ifconfig | grep "^lo" 1> /dev/null ; then
echo "/etc/rc.d/rc.inet1: /sbin/ifconfig lo 127.0.0.1" | $LOGGER
/sbin/ifconfig lo 127.0.0.1
echo "/etc/rc.d/rc.inet1: /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo" | $LOGGER
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo
fi
fi
}
# Function to take down the loopback interface:
lo_down() {
if grep lo: /proc/net/dev 1> /dev/null ; then
echo "/etc/rc.d/rc.inet1: /sbin/ifconfig lo down" | $LOGGER
/sbin/ifconfig lo down
fi
}
#######################
# INTERFACE FUNCTIONS #
#######################
# Function to assemble a bridge interface.
br_open() {
# argument is 'i' - the position of this interface in the IFNAME array.
/sbin/brctl addbr ${IFNAME[$1]}
for BRIF in $(echo ${BRNICS[$1]}); do
/sbin/ifconfig $BRIF down
/sbin/ifconfig $BRIF 0.0.0.0 promisc up
/sbin/brctl addif ${IFNAME[$1]} $BRIF
done
}
# Function to disassemble a bridge interface.
br_close() {
# argument is 'i' - the position of this interface in the IFNAME array.
#for BRIF in $(echo ${BRNICS[$1]}); do
for BRIF in $(ls --indicator-style=none /sys/class/net/${IFNAME[$1]}/brif/)
do
/sbin/brctl delif ${IFNAME[$1]} $BRIF
done
/sbin/ifconfig ${IFNAME[$1]} down
/sbin/brctl delbr ${IFNAME[$1]}
}
# Function to bring up a network interface. If the interface is
# already up or does not yet exist (perhaps because the kernel driver
# is not loaded yet), do nothing.
if_up() {
# Determine position 'i' of this interface in the IFNAME array:
i=0
while [ $i -lt $MAXNICS ]; do
[ "${IFNAME[$i]}" = "${1}" ] && break
i=$(($i+1))
done
if [ -z "$container" ]; then
# If the interface is a bridge, then create it first:
[ -n "${BRNICS[$i]}" ] && br_open $i
# If the interface isn't in the kernel yet (but there's an alias for it in
# modules.conf), then it should be loaded first:
if ! grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then # no interface yet
if /sbin/modprobe -c | grep -v "^#" | grep -w "alias ${1}" | grep -vw "alias ${1} off" > /dev/null ; then
echo "/etc/rc.d/rc.inet1: /sbin/modprobe ${1}" | $LOGGER
/sbin/modprobe ${1}
fi
fi
fi # end check container
if grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then # interface exists
if ! /sbin/ifconfig | grep -w "${1}" 1>/dev/null || \
! /sbin/ifconfig ${1} | grep -w inet 1> /dev/null ; then # interface not up or not configured
if [ ! "${HWADDR[$i]}" = "" ]; then # Set hardware address _before_ the interface goes up:
echo "/etc/rc.d/rc.inet1: /sbin/ifconfig ${1} hw ether ${HWADDR[$i]}" | $LOGGER
/sbin/ifconfig ${1} hw ether ${HWADDR[$i]}
fi
if [ ! "${MTU[$i]}" = "" ]; then # Set MTU to something else than 1500
echo "/etc/rc.d/rc.inet1: /sbin/ifconfig ${1} mtu ${MTU[$i]}" | $LOGGER
/sbin/ifconfig ${1} mtu ${MTU[$i]}
fi
if [ -x /etc/rc.d/rc.wireless ]; then
. /etc/rc.d/rc.wireless ${1} start # Initialize any wireless parameters
fi
if [ "${USE_DHCP[$i]}" = "yes" ]; then # use DHCP to bring interface up
# Clear DHCP_OPTIONS before adding new options to it:
unset DHCP_OPTIONS
# Set DHCP_OPTIONS for this interface:
[ ${DHCP_HOSTNAME[$i]} ] && DHCP_OPTIONS="-h ${DHCP_HOSTNAME[$i]}"
[ "${DHCP_KEEPRESOLV[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -C resolv.conf"
[ "${DHCP_KEEPNTP[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -C ntp.conf"
[ "${DHCP_KEEPGW[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -G"
[ "${DHCP_DEBUG[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -d"
[ "${DHCP_NOIPV4LL[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -L"
[ ${DHCP_IPADDR[$i]} ] && DHCP_OPTIONS="$DHCP_OPTIONS -r ${DHCP_IPADDR[$i]}"
echo "Polling for DHCP server on interface ${1}:"
# If you set a timeout, you get one, even if the kernel doesn't think that
# your device is connected, in case /sys isn't right (which it usually isn't
# except right after the device is loaded, when it usually is):
#### (start commented out)
# This is deactivated for now since the kernel has been returning incorrect
# results concerning whether the interface carrier is detected.
#if [ "${DHCP_TIMEOUT[$i]}" = "" ]; then
# ifconfig ${1} up && sleep 1
# CONNSTATUS="$(cat /sys/class/net/${1}/carrier 2> /dev/null)"
# ifconfig ${1} down
# if [ "$CONNSTATUS" = "0" ]; then
# # The kernel has just told us the cable isn't even plugged in, but we will
# # give any DHCP server a short chance to reply anyway:
# echo "No carrier detected on ${1}. Reducing DHCP timeout to 10 seconds."
# DHCP_TIMEOUT[$i]=10
# fi
#fi
#### (end commented out)
# 10 seconds should be a reasonable default DHCP timeout. 30 was too much.
echo "/etc/rc.d/rc.inet1: /sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS} ${1}" | $LOGGER
/sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS} ${1}
else # bring up interface using a static IP address
if [ ! "${IPADDR[$i]}" = "" ]; then # skip unconfigured interfaces
# Determine broadcast address from the IP address and netmask:
BROADCAST[$i]=`/bin/ipmask ${NETMASK[$i]} ${IPADDR[$i]}|cut -f1 -d' '`
# Set up the network card:
echo "/etc/rc.d/rc.inet1: /sbin/ifconfig ${1} ${IPADDR[$i]} broadcast ${BROADCAST[$i]} netmask ${NETMASK[$i]}" | $LOGGER
/sbin/ifconfig ${1} ${IPADDR[$i]} broadcast ${BROADCAST[$i]} netmask ${NETMASK[$i]}
else
if [ "$DEBUG_ETH_UP" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: ${1} interface is not configured in /etc/rc.d/rc.inet1.conf" | $LOGGER
fi
fi
fi
else
if [ "$DEBUG_ETH_UP" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: ${1} is already up, skipping" | $LOGGER
fi
fi
else
if [ "$DEBUG_ETH_UP" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: ${1} interface does not exist (yet)" | $LOGGER
fi
fi
}
# Function to take down a network interface:
if_down() {
# Determine position 'i' of this interface in the IFNAME array:
i=0
while [ $i -lt $MAXNICS ]; do
[ "${IFNAME[$i]}" = "${1}" ] && break
i=$(($i+1))
done
if grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then
if [ "${USE_DHCP[$i]}" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: /sbin/dhcpcd -k -d ${1}" | $LOGGER
/sbin/dhcpcd -k -d ${1} 2> /dev/null || /sbin/ifconfig ${1} down
sleep 1
else
echo "/etc/rc.d/rc.inet1: /sbin/ifconfig ${1} down" | $LOGGER
/sbin/ifconfig ${1} down
fi
if [ -x /etc/rc.d/rc.wireless ]; then
. /etc/rc.d/rc.wireless ${1} stop # Kill wireless daemons if any.
fi
# If the interface is a bridge, then destroy it now:
if [ -n "${BRNICS[$i]}" ]; then
br_close $i
fi
fi
}
#####################
# GATEWAY FUNCTIONS #
#####################
# Function to bring up the gateway if there is not yet a default route:
gateway_up() {
if ! /sbin/route -n | grep "^0.0.0.0" 1> /dev/null ; then
if [ ! "$GATEWAY" = "" ]; then
echo "/etc/rc.d/rc.inet1: /sbin/route add default gw ${GATEWAY} metric 1" | $LOGGER
/sbin/route add default gw ${GATEWAY} metric 1 2>&1 | $LOGGER
fi
fi
}
# Function to take down an existing default gateway:
gateway_down() {
if /sbin/route -n | grep "^0.0.0.0" 1> /dev/null ; then
echo "/etc/rc.d/rc.inet1: /sbin/route del default" | $LOGGER
/sbin/route del default
fi
}
# Function to start the network:
start() {
lo_up
for i in ${IFNAME[@]} ; do
if_up $i
done
gateway_up
}
# Function to stop the network:
stop() {
gateway_down
for i in ${IFNAME[@]} ; do
if_down $i
done
lo_down
}
############
### MAIN ###
############
case "$1" in
'start') # "start" brings up all configured interfaces:
start
;;
'stop') # "stop" takes down all configured interfaces:
stop
;;
'restart') # "restart" restarts the network:
stop
start
;;
'lo_start') # Start the loopback interface:
lo_up
;;
*_start) # Example: "eth1_start" will start the specified interface 'eth1'
INTERFACE=`echo $1 | /bin/cut -d '_' -f 1`
if_up $INTERFACE
gateway_up
;;
'lo_stop') # Stop the loopback interface:
lo_down
;;
*_stop) # Example: "eth0_stop" will stop the specified interface 'eth0'
INTERFACE=`echo $1 | /bin/cut -d '_' -f 1`
if_down $INTERFACE
;;
*_restart) # Example: "wlan0_restart" will take 'wlan0' down and up again
INTERFACE=`echo $1 | /bin/cut -d '_' -f 1`
if_down $INTERFACE
sleep 1
if_up $INTERFACE
gateway_up
;;
'up') # "up" does the same thing as "start"
start
;;
'down') # "down" does the same thing as "stop"
stop
;;
'lo_up') # Start the loopback interface:
lo_up
;;
*_up) # "*_up" does the same thing as "*_start"
INTERFACE=`echo $1 | /bin/cut -d '_' -f 1`
if_up $INTERFACE
gateway_up
;;
'lo_down') # Stop the loopback interface:
lo_down
;;
*_down) # "*_down" does the same thing as "*_stop"
INTERFACE=`echo $1 | /bin/cut -d '_' -f 1`
if_down $INTERFACE
;;
*) # The default is to bring up all configured interfaces:
start
esac
# End of /etc/rc.d/rc.inet1

320
scripts/rc.inet1.orig

@ -0,0 +1,320 @@
#! /bin/sh
# /etc/rc.d/rc.inet1
# This script is used to bring up the various network interfaces.
#
# @(#)/etc/rc.d/rc.inet1 10.2 Sun Jul 24 12:45:56 PDT 2005 (pjv)
############################
# READ NETWORK CONFIG FILE #
############################
# Get the configuration information from /etc/rc.d/rc.inet1.conf:
. /etc/rc.d/rc.inet1.conf
###########
# LOGGING #
###########
# If possible, log events in /var/log/messages:
if [ -f /var/run/syslogd.pid -a -x /usr/bin/logger ]; then
LOGGER=/usr/bin/logger
else # output to stdout/stderr:
LOGGER=/bin/cat
fi
############################
# DETERMINE INTERFACE LIST #
############################
# Compose a list of interfaces from /etc/rc.d/rc.inet1.conf (with a maximum
# of 6 interfaces, but you can easily enlarge the interface limit
# - send me a picture of such a box :-).
# If a value for IFNAME[n] is not set, we assume it is an eth'n' interface.
# This way, the new script is compatible with older rc.inet1.conf files.
# The IFNAME array will be used to determine which interfaces to bring up/down.
MAXNICS=${MAXNICS:-6}
i=0
while [ $i -lt $MAXNICS ];
do
IFNAME[$i]=${IFNAME[$i]:=eth${i}}
i=$(($i+1))
done
if [ "$DEBUG_ETH_UP" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: List of interfaces: '${IFNAME[@]}'" | $LOGGER
fi
######################
# LOOPBACK FUNCTIONS #
######################
# Function to bring up the loopback interface. If loopback is
# already up, do nothing.
lo_up() {
if grep lo: /proc/net/dev 1> /dev/null ; then
if ! /sbin/ifconfig | grep "^lo" 1> /dev/null ; then
echo "/etc/rc.d/rc.inet1: /sbin/ifconfig lo 127.0.0.1" | $LOGGER
/sbin/ifconfig lo 127.0.0.1
echo "/etc/rc.d/rc.inet1: /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo" | $LOGGER
/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 lo
fi
fi
}
# Function to take down the loopback interface:
lo_down() {
if grep lo: /proc/net/dev 1> /dev/null ; then
echo "/etc/rc.d/rc.inet1: /sbin/ifconfig lo down" | $LOGGER
/sbin/ifconfig lo down
fi
}
#######################
# INTERFACE FUNCTIONS #
#######################
# Function to assemble a bridge interface.
br_open() {
# argument is 'i' - the position of this interface in the IFNAME array.
/sbin/brctl addbr ${IFNAME[$1]}
for BRIF in $(echo ${BRNICS[$1]}); do
/sbin/ifconfig $BRIF down
/sbin/ifconfig $BRIF 0.0.0.0 promisc up
/sbin/brctl addif ${IFNAME[$1]} $BRIF
done
}
# Function to disassemble a bridge interface.
br_close() {
# argument is 'i' - the position of this interface in the IFNAME array.
#for BRIF in $(echo ${BRNICS[$1]}); do
for BRIF in $(ls --indicator-style=none /sys/class/net/${IFNAME[$1]}/brif/)
do
/sbin/brctl delif ${IFNAME[$1]} $BRIF
done
/sbin/ifconfig ${IFNAME[$1]} down
/sbin/brctl delbr ${IFNAME[$1]}
}
# Function to bring up a network interface. If the interface is
# already up or does not yet exist (perhaps because the kernel driver
# is not loaded yet), do nothing.
if_up() {
# Determine position 'i' of this interface in the IFNAME array:
i=0
while [ $i -lt $MAXNICS ]; do
[ "${IFNAME[$i]}" = "${1}" ] && break
i=$(($i+1))
done
# If the interface is a bridge, then create it first:
[ -n "${BRNICS[$i]}" ] && br_open $i
# If the interface isn't in the kernel yet (but there's an alias for it in
# modules.conf), then it should be loaded first:
if ! grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then # no interface yet
if /sbin/modprobe -c | grep -v "^#" | grep -w "alias ${1}" | grep -vw "alias ${1} off" > /dev/null ; then
echo "/etc/rc.d/rc.inet1: /sbin/modprobe ${1}" | $LOGGER
/sbin/modprobe ${1}
fi
fi
if grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then # interface exists
if ! /sbin/ifconfig | grep -w "${1}" 1>/dev/null || \
! /sbin/ifconfig ${1} | grep -w inet 1> /dev/null ; then # interface not up or not configured
if [ ! "${HWADDR[$i]}" = "" ]; then # Set hardware address _before_ the interface goes up:
echo "/etc/rc.d/rc.inet1: /sbin/ifconfig ${1} hw ether ${HWADDR[$i]}" | $LOGGER
/sbin/ifconfig ${1} hw ether ${HWADDR[$i]}
fi
if [ ! "${MTU[$i]}" = "" ]; then # Set MTU to something else than 1500
echo "/etc/rc.d/rc.inet1: /sbin/ifconfig ${1} mtu ${MTU[$i]}" | $LOGGER
/sbin/ifconfig ${1} mtu ${MTU[$i]}
fi
if [ -x /etc/rc.d/rc.wireless ]; then
. /etc/rc.d/rc.wireless ${1} start # Initialize any wireless parameters
fi
if [ "${USE_DHCP[$i]}" = "yes" ]; then # use DHCP to bring interface up
# Clear DHCP_OPTIONS before adding new options to it:
unset DHCP_OPTIONS
# Set DHCP_OPTIONS for this interface:
[ ${DHCP_HOSTNAME[$i]} ] && DHCP_OPTIONS="-h ${DHCP_HOSTNAME[$i]}"
[ "${DHCP_KEEPRESOLV[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -C resolv.conf"
[ "${DHCP_KEEPNTP[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -C ntp.conf"
[ "${DHCP_KEEPGW[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -G"
[ "${DHCP_DEBUG[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -d"
[ "${DHCP_NOIPV4LL[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -L"
[ ${DHCP_IPADDR[$i]} ] && DHCP_OPTIONS="$DHCP_OPTIONS -r ${DHCP_IPADDR[$i]}"
echo "Polling for DHCP server on interface ${1}:"
# If you set a timeout, you get one, even if the kernel doesn't think that
# your device is connected, in case /sys isn't right (which it usually isn't
# except right after the device is loaded, when it usually is):
#### (start commented out)
# This is deactivated for now since the kernel has been returning incorrect
# results concerning whether the interface carrier is detected.
#if [ "${DHCP_TIMEOUT[$i]}" = "" ]; then
# ifconfig ${1} up && sleep 1
# CONNSTATUS="$(cat /sys/class/net/${1}/carrier 2> /dev/null)"
# ifconfig ${1} down
# if [ "$CONNSTATUS" = "0" ]; then
# # The kernel has just told us the cable isn't even plugged in, but we will
# # give any DHCP server a short chance to reply anyway:
# echo "No carrier detected on ${1}. Reducing DHCP timeout to 10 seconds."
# DHCP_TIMEOUT[$i]=10
# fi
#fi
#### (end commented out)
# 10 seconds should be a reasonable default DHCP timeout. 30 was too much.
echo "/etc/rc.d/rc.inet1: /sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS} ${1}" | $LOGGER
/sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS} ${1}
else # bring up interface using a static IP address
if [ ! "${IPADDR[$i]}" = "" ]; then # skip unconfigured interfaces
# Determine broadcast address from the IP address and netmask:
BROADCAST[$i]=`/bin/ipmask ${NETMASK[$i]} ${IPADDR[$i]}|cut -f1 -d' '`
# Set up the network card:
echo "/etc/rc.d/rc.inet1: /sbin/ifconfig ${1} ${IPADDR[$i]} broadcast ${BROADCAST[$i]} netmask ${NETMASK[$i]}" | $LOGGER
/sbin/ifconfig ${1} ${IPADDR[$i]} broadcast ${BROADCAST[$i]} netmask ${NETMASK[$i]}
else
if [ "$DEBUG_ETH_UP" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: ${1} interface is not configured in /etc/rc.d/rc.inet1.conf" | $LOGGER
fi
fi
fi
else
if [ "$DEBUG_ETH_UP" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: ${1} is already up, skipping" | $LOGGER
fi
fi
else
if [ "$DEBUG_ETH_UP" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: ${1} interface does not exist (yet)" | $LOGGER
fi
fi
}
# Function to take down a network interface:
if_down() {
# Determine position 'i' of this interface in the IFNAME array:
i=0
while [ $i -lt $MAXNICS ]; do
[ "${IFNAME[$i]}" = "${1}" ] && break
i=$(($i+1))
done
if grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then
if [ "${USE_DHCP[$i]}" = "yes" ]; then
echo "/etc/rc.d/rc.inet1: /sbin/dhcpcd -k -d ${1}" | $LOGGER
/sbin/dhcpcd -k -d ${1} 2> /dev/null || /sbin/ifconfig ${1} down
sleep 1
else
echo "/etc/rc.d/rc.inet1: /sbin/ifconfig ${1} down" | $LOGGER
/sbin/ifconfig ${1} down
fi
if [ -x /etc/rc.d/rc.wireless ]; then
. /etc/rc.d/rc.wireless ${1} stop # Kill wireless daemons if any.
fi
# If the interface is a bridge, then destroy it now:
if [ -n "${BRNICS[$i]}" ]; then
br_close $i
fi
fi
}
#####################
# GATEWAY FUNCTIONS #
#####################
# Function to bring up the gateway if there is not yet a default route:
gateway_up() {
if ! /sbin/route -n | grep "^0.0.0.0" 1> /dev/null ; then
if [ ! "$GATEWAY" = "" ]; then
echo "/etc/rc.d/rc.inet1: /sbin/route add default gw ${GATEWAY} metric 1" | $LOGGER
/sbin/route add default gw ${GATEWAY} metric 1 2>&1 | $LOGGER
fi
fi
}
# Function to take down an existing default gateway:
gateway_down() {
if /sbin/route -n | grep "^0.0.0.0" 1> /dev/null ; then
echo "/etc/rc.d/rc.inet1: /sbin/route del default" | $LOGGER
/sbin/route del default
fi
}
# Function to start the network:
start() {
lo_up
for i in ${IFNAME[@]} ; do
if_up $i
done
gateway_up
}
# Function to stop the network:
stop() {
gateway_down
for i in ${IFNAME[@]} ; do
if_down $i
done
lo_down
}
############
### MAIN ###
############
case "$1" in
'start') # "start" brings up all configured interfaces:
start
;;
'stop') # "stop" takes down all configured interfaces:
stop
;;
'restart') # "restart" restarts the network:
stop
start
;;
'lo_start') # Start the loopback interface:
lo_up
;;
*_start) # Example: "eth1_start" will start the specified interface 'eth1'
INTERFACE=`echo $1 | /bin/cut -d '_' -f 1`
if_up $INTERFACE
gateway_up
;;
'lo_stop') # Stop the loopback interface:
lo_down
;;
*_stop) # Example: "eth0_stop" will stop the specified interface 'eth0'
INTERFACE=`echo $1 | /bin/cut -d '_' -f 1`
if_down $INTERFACE
;;
*_restart) # Example: "wlan0_restart" will take 'wlan0' down and up again
INTERFACE=`echo $1 | /bin/cut -d '_' -f 1`
if_down $INTERFACE
sleep 1
if_up $INTERFACE
gateway_up
;;
'up') # "up" does the same thing as "start"
start
;;
'down') # "down" does the same thing as "stop"
stop
;;
'lo_up') # Start the loopback interface:
lo_up
;;
*_up) # "*_up" does the same thing as "*_start"
INTERFACE=`echo $1 | /bin/cut -d '_' -f 1`
if_up $INTERFACE
gateway_up
;;
'lo_down') # Stop the loopback interface:
lo_down
;;
*_down) # "*_down" does the same thing as "*_stop"
INTERFACE=`echo $1 | /bin/cut -d '_' -f 1`
if_down $INTERFACE
;;
*) # The default is to bring up all configured interfaces:
start
esac
# End of /etc/rc.d/rc.inet1

19
slack-desc

@ -0,0 +1,19 @@
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':'.
|-----handy-ruler------------------------------------------------------|
lxc: lxc (Linux Containers)
lxc:
lxc: Linux Containers (LXC) are an operating system-level virtualization
lxc: method for running multiple isolated server installs (containers) on
lxc: a single control host. LXC does not provide a virtual machine, but
lxc: rather provides a virtual environment that has its own process and
lxc: network space. It is similar to a chroot, but offers more isolation.
lxc:
lxc: Daniel Lezcano is the primary developer of lxc.
lxc: Homepage: https://linuxcontainers.org
lxc:
Loading…
Cancel
Save