vshost-util-vserver

Build script and sources for util-vserver.
git clone https://ccx.te2000.cz/git/vshost-util-vserver
Log | Files | Refs

initpost (2255B)


      1 #!/bin/bash
      2 
      3 # Copyright (C) 2007, 2009 Natanael Copa <ncopa@alpinelinux.org>
      4 #  
      5 # This program is free software; you can redistribute it and/or modify
      6 # it under the terms of the GNU General Public License as published by
      7 # the Free Software Foundation; version 2 of the License.
      8 #  
      9 # This program is distributed in the hope that it will be useful,
     10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 # GNU General Public License for more details.
     13 #  
     14 # You should have received a copy of the GNU General Public License
     15 # along with this program; if not, write to the Free Software
     16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     17 
     18 ## Called as: initpost <cfgdir> <path of util-vserver-vars>
     19 
     20 cfgdir="$1"
     21 vdir="$cfgdir"/vdir
     22 . "$2"
     23 
     24 cd "$vdir"
     25 
     26 echo ">>> Creating missing dirs..."
     27 $_CHROOT_SH mkdir proc sys dev home etc etc/rcL.d etc/rcK.d 2>/dev/null
     28 
     29 # remove mtab which is a link
     30 if test -e "$vdir/etc/mtab"; then
     31 	$_CHROOT_SH rm /etc/mtab 2>/dev/null
     32 fi
     33 
     34 # trick to install busybox links and boot services
     35 echo ">>> Installing boot services..."
     36 vserver="$1"
     37 $_VSERVER "$vserver" stop  &>/dev/null || true
     38 $_VSERVER "$vserver" start --rescue --rescue-init /bin/busybox sh -c '
     39 	/bin/busybox --install -s
     40 	if [ -x /sbin/rc-update ]; then
     41 	    /sbin/rc-update add syslog boot
     42 	    /bin/rmdir /etc/rcL.d /etc/rcK.d
     43 	else
     44 	    /sbin/rc_add -s 20 -k syslog
     45 	fi
     46 '
     47 
     48 # set up hostname
     49 if test -r "$cfgdir"/uts/nodename; then
     50 	echo ">>> Setting hostname..."
     51 	$_CHROOT_SH truncate /etc/hostname < "$cfgdir/uts/nodename"
     52 fi
     53 
     54 # create fstab
     55 echo -e "none\t/\tnone\tdefaults" | $_CHROOT_SH truncate /etc/fstab
     56 
     57 # create busybox style inittab
     58 cat <<EOF | $_CHROOT_SH truncate /etc/inittab
     59 ::wait:/etc/init.d/rcL
     60 ::ctrlaltdel:/etc/init.d/rcK
     61 ::ctrlaltdel:/usr/bin/killall5 -15
     62 EOF
     63 
     64 # set up cmd.start and cmd stop if needed
     65 test -e "$1"/apps/init/style && initstlye=$(cat "$1"/apps/init/style)
     66 if test "$initstlye" != "plain"; then
     67 	echo "/etc/init.d/rcL" > "$cfgdir/apps/init/cmd.start"
     68 	echo "/etc/init.d/rcK" > "$cfgdir/apps/init/cmd.stop"
     69 fi
     70 
     71 # vserver should not be running at this point but lets be sure
     72 $_VSERVER "$vserver" stop  &>/dev/null || true
     73