3 # Copyright (C) 2003,2004,2005,2006 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
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.
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.
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.
32 declare -a SETUP_INTERFACES=()
33 declare -a SETUP_FLAGS=()
35 declare -r SETUP_OPTIONS="confdir:,lockfile:,hostname:,netdev:,netmask:,netprefix:,netbcast:,interface:,flags:,context:,initstyle:,cpuset:,cpusetcpus:,cpusetmems:,cpusetvirt"
36 declare -r SETUP_HELPMSG=$"
37 --context ... the static context of the vserver [default: none; one will
39 --confdir ... [default: $__CONFDIR/<name>]
41 ... [default: $__RUNDIR/<name>]
44 --netbcast <broadcast>
45 --netmask <netmask>|--netprefix <prefixlen>
46 ... sets the default netmask (a.b.c.d quadruple) or prefixlen
47 (length of the interface)
48 --interface [<name-suffix>=][<device>:]<ip>[/<mask|prefixlen>]
49 ... declares an network-interface; this option can be specified
52 ... sets comma-separated list of flags; possible flags are
53 lock: Prevent the vserver from setting new security context
54 sched: Merge scheduler priority of all processes in the
55 vserver so that it acts a like a single
56 one (kernel 2.4 only).
57 nproc: Limit the number of processes in the vserver
58 according to ulimit (instead of a per user limit,
59 this becomes a per vserver limit)
60 private: No other process can join this security context.
63 ... declares the CPUSET this vserver will run in [default: none]
64 --cpusetcpus <number[-number][:<exclusive>]>
65 ... sets which cpus belong to the CPUSET,
66 exclusive is a flag (0|1) prohibiting any other cpuset from
68 --cpusetmems <number[-number][:<exclusive>]>
69 ... sets which memory pools belong to the CPUSET,
70 exclusive is a flag (0|1) prohibiting any other cpuset from
71 using those memory pools
73 ... virtualize cpuset (guest will see only CPUs defined in cpuset)
74 Requires kernel patch from http://www.bullopensource.org/cpuset/
76 ... configures the initstyle (e.g. minit,sysv,plain)
79 function setup_setOption2
82 (--context) SETUP_CONTEXT=$2;;
83 (--confdir) SETUP_CONFDIR=$2;;
84 (--lockfile) SETUP_LOCKFILE=$2;;
85 (--hostname) SETUP_HOSTNAME=$2;;
86 (--netdev) SETUP_NETDEV=$2;;
87 (--netmask) SETUP_NETMASK=$2;;
88 (--netprefix) SETUP_NETPREFIX=$2;;
89 (--netbcast) SETUP_NETBCAST=$2;;
90 (--interface) SETUP_INTERFACES=( "${SETUP_INTERFACES[@]}" "$2" );;
91 (--initstyle) SETUP_INITSTYLE=$2;;
92 (--cpuset) SETUP_CPUSET=$2;;
93 (--cpusetcpus) old_IFS=$IFS
97 SETUP_CPUSETCPUSEXCL=$2
100 (--cpusetmems) old_IFS=$IFS
104 SETUP_CPUSETMEMSEXCL=$2
107 (--cpusetvirt) SETUP_CPUSETVIRT=1;;
108 (--flags) old_IFS=$IFS
111 SETUP_FLAGS=( "${SETUP_FLAGS[@]}" "$@" )
120 function _setup_writeSingleOption
122 test -z "$1" || echo "$1" >"$2"
125 function _setup_writeInterface
131 local name=${tmp%%=*}
132 test "$name" != "$tmp" || name=
137 test "$dev" != "$tmp" || dev=
140 test "$dev" != "nodev" || {
144 local mask=${tmp##*/}
145 test "$mask" != "$tmp" || mask=
147 local ip=${tmp%%/${mask}}
150 test "${mask%%.*}" != "$mask" || {
155 d=$vdir/interfaces/$idx
158 _setup_writeSingleOption "$name" $d/name
159 _setup_writeSingleOption "$dev" $d/dev
160 _setup_writeSingleOption "$ip" $d/ip
161 _setup_writeSingleOption "$mask" $d/mask
162 _setup_writeSingleOption "$prefix" $d/prefix
164 test -n "$dev" -o -n "$SETUP_NETDEV" || {
165 test -n "$nodev" || \
166 echo $"No device specified for interface '$idx'; setting 'nodev'" >&2
171 function setup_setDefaults
173 : ${SETUP_CONFDIR:=$__CONFDIR/$1}
174 : ${SETUP_LOCKFILE:=$__RUNDIR/$1}
175 findFile SETUP_FSTAB "$__CONFDIR"/.defaults/fstab "$__PKGLIBDEFAULTDIR"/fstab
178 function _setup_generateContext
180 if test -z "$SETUP_CONTEXT" && test ! -e "$__CONFDIR/.defaults/context.dynamic"; then
181 if test -e "$__CONFDIR/.defaults/context.next"; then
182 SETUP_CONTEXT=`$_CAT "$__CONFDIR/.defaults/context.next"`
184 SETUP_CONTEXT=`$_CAT "$__PKGLIBDEFAULTDIR/context.start"`
186 expr "$SETUP_CONTEXT" + 1 > "$__CONFDIR/.defaults/context.next"
190 function setup_writeOption
193 local cfgdir=${SETUP_CONFDIR:?}
196 mkdir -p "$cfgdir"/interfaces "$cfgdir"/apps/init "$cfgdir"/uts "$cfgdir"/cpuset
198 _setup_generateContext
200 _setup_writeSingleOption "$name" "$cfgdir"/name
201 _setup_writeSingleOption "$SETUP_CONTEXT" "$cfgdir"/context
202 _setup_writeSingleOption "$SETUP_HOSTNAME" "$cfgdir"/uts/nodename
203 _setup_writeSingleOption "$SETUP_NETDEV" "$cfgdir"/interfaces/dev
204 _setup_writeSingleOption "$SETUP_NETMASK" "$cfgdir"/interfaces/mask
205 _setup_writeSingleOption "$SETUP_NETPREFIX" "$cfgdir"/interfaces/prefix
206 _setup_writeSingleOption "$SETUP_NETBCAST" "$cfgdir"/interfaces/bcast
207 _setup_writeSingleOption "$SETUP_INITSTYLE" "$cfgdir"/apps/init/style
208 _setup_writeSingleOption "$SETUP_CPUSET" "$cfgdir"/cpuset/name
209 _setup_writeSingleOption "$SETUP_CPUSETCPUS" "$cfgdir"/cpuset/cpus
210 _setup_writeSingleOption "$SETUP_CPUSETCPUSEXCL" "$cfgdir"/cpuset/cpus_exclusive
211 _setup_writeSingleOption "$SETUP_CPUSETMEMS" "$cfgdir"/cpuset/mems
212 _setup_writeSingleOption "$SETUP_CPUSETMEMSEXCL" "$cfgdir"/cpuset/mem_exclusive
213 _setup_writeSingleOption "$SETUP_CPUSETVIRT" "$cfgdir"/cpuset/virtualized
216 for i in "${SETUP_INTERFACES[@]}"; do
217 _setup_writeInterface "$cfgdir" $idx "$i"
221 test -z "$SETUP_FLAGS" || for i in "${SETUP_FLAGS[@]}"; do
223 done >"$cfgdir"/flags
225 ln -s "$SETUP_LOCKFILE" "$cfgdir"/run
228 function setup_writeInitialFstab
230 cat "${SETUP_FSTAB:?}" >"${SETUP_CONFDIR:?}"/fstab
237 setup_setOption2 --interface foo0=eth0:1.2.3.4/1
238 setup_setOption2 --interface foo1=eth0:1.2.3.4/255.255.248.0
239 setup_setOption2 --interface foo2=eth0:1.2.3.4
240 setup_setOption2 --interface foo3=1.2.3.4
241 setup_setOption2 --interface foo4=1.2.3.4/1
242 setup_setOption2 --interface eth0:1.2.3.4
243 setup_setOption2 --interface eth0:1.2.3.4/1
244 setup_setOption2 --interface 1.2.3.4
245 setup_setOption2 --interface 1.2.3.4/1