X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=cirros-testvm%2Fsrc-cirros%2Fsrc%2Fetc%2Finit.d%2Frc.sysinit;fp=cirros-testvm%2Fsrc-cirros%2Fsrc%2Fetc%2Finit.d%2Frc.sysinit;h=0953c4c06e2667a135e75f000f747820948028fa;hb=b0a0f15dfaa205161a7fcb20cf1b8cd4948c2ef3;hp=0000000000000000000000000000000000000000;hpb=c6ac3cd55ee2da956195eee393b0882105dfad4e;p=packages%2Ftrusty%2Fcirros-testvm.git diff --git a/cirros-testvm/src-cirros/src/etc/init.d/rc.sysinit b/cirros-testvm/src-cirros/src/etc/init.d/rc.sysinit new file mode 100755 index 0000000..0953c4c --- /dev/null +++ b/cirros-testvm/src-cirros/src/etc/init.d/rc.sysinit @@ -0,0 +1,100 @@ +#!/bin/sh +# vi: ts=4 noexpandtab + +. /lib/cirros/shlib + +write_lxc_is_container() { + cat <<"EOF" +#!/bin/sh +# This program is written by /etc/rc.d/rc.sysinit. +# It simply reports whether or not this system is in an lxc container + +EOF + if is_lxc; then + echo "# This is an LXC container" + echo '[ "$1" = "-v" ] && echo '"$_LXC_CONTAINER" + echo "exit 0" + else + echo "# This is NOT an LXC container" + echo '[ "$1" = "-v" ] && echo none' + echo "exit 1" + fi +} + +fail() { echo "FAIL:" "$@"; } +warn() { echo "WARN:" "$@"; } + +### begin init ### + +if [ ! -d /proc/1 ]; then + mount -n -t proc /proc /proc || fail "failed mount /proc" +fi + +read uptime cputime < /proc/uptime +iinfo "$0: up at $uptime" + +if (: >/.testrw; ) >/dev/null 2>&1; then + rm -f /.testrw +else + mount -o remount,rw / || fail "failed mount / rw" +fi + +is_mounted sysfs "" /sys || + mount -t sysfs sysfs /sys || fail "failed mount /sys!" + +if ! is_lxc; then + mount_once devtmpfs /dev /dev || fail "failed mount /dev" +fi +iinfo "container: $_LXC_CONTAINER" + +mkdir -p /dev/pts /dev/shm /run + +mount -a + +mkdir /run/var.tmp + +hostname -F /etc/hostname + +f="/bin/lxc-is-container" && write_lxc_is_container > "$f" && chmod 755 "$f" + +if ! is_lxc; then + for d in $(awk '$2 == "/" { print $1 }' /proc/mounts); do + [ -e "/dev/${d#/dev}" ] && ln -sf "${d#/dev/}" /dev/root && break + done +fi + +## pretend you're runlevel 3 +set +f +for s in /etc/rc3.d/S*; do + [ -x "$s" ] || continue + "$s" "start" > /etc/securetty + if ! [ /dev/tty1 -ef /dev/console ]; then + # on libvirt lxc, /dev/console is a symlink to /dev/pts0 + # and /dev/tty1 is also a symlink to /dev/pts/0. So using + # the tty1 gets us a getty on "console" + # + # on upstream lxc, /dev/console is a character device + # so we run a getty there if so. + lxc_console="console" + fi +fi + +s_args="" +for tty in $lxc_console tty1 ttyS0 hvc0; do + if [ -e /dev/$tty ] && { echo "" >> "/dev/$tty" ; } 2>/dev/null ; then + s_args="${s_args:+${s_args} }s/^#$tty:\(.*\)/$tty:\1/;" + else + s_args="${s_args:+${s_args} }s/^$tty:\(.*\)/#$tty:\1/;" + fi +done +[ -z "$s_args" ] || + { sed -i "$s_args" /etc/inittab && kill -HUP 1; } + +if [ -f /etc/rc.local -a -x /etc/rc.local ]; then + /etc/rc.local +fi