Skip to content

Instantly share code, notes, and snippets.

@codedot
Forked from anonymous/add
Created December 23, 2012 18:03
Show Gist options
  • Save codedot/4364901 to your computer and use it in GitHub Desktop.
Save codedot/4364901 to your computer and use it in GitHub Desktop.
Scripts for cloning fair-scheduled zones in Solaris 11. To be installed under /opt/custom. Assume `chmod +x /opt/custom/{add,reset}; zonecfg -z origin "create; set zonepath=/zones/origin"; zoneadm -z origin install; zonecfg -z global set cpu-shares=1; dispadm -d FSS; reboot` done before using. Run /opt/custom/reset once, then /opt/custom/add for…
#!/usr/xpg4/bin/sh
set -Cex
export PATH=/usr/xpg6/bin:/usr/xpg4/bin:/usr/bin:/usr/sbin
MIN=10
MAX=99
POOL=busy
ROOT=/opt/custom
. $ROOT/config
cd $ROOT
mkdir -p vacant
for p in $(ls vacant); do
test -d vacant/$p
if echo $$ >vacant/$p/lock; then
POOL=$p
trap 'rm -f vacant/$POOL/lock' INT TERM EXIT
break
fi
done
test "$POOL" != busy
test "$POOL" -ge "$MIN"
test "$POOL" -le "$MAX"
read ZONE <vacant/$POOL/next
test "$ZONE" -ge "$MIN"
test "$ZONE" -le "$MAX"
ZONENAME=$NETWORK.$POOL.$ZONE
ZONEPATH=/zones/clones/$NETWORK/$POOL/$ZONE
zoneadm list -ip | grep -F :origin:installed:/zones/origin:
! zoneadm list -cp | grep -F :$ZONENAME:
zonecfg -z $ZONENAME <<-COMMIT
create
set zonepath=$ZONEPATH
select anet linkname=net0
set defrouter=$DEFROUTER
set allowed-address=10.$ZONENAME
end
set cpu-shares=1
COMMIT
zoneadm list -cp | grep -F :$ZONENAME:configured:$ZONEPATH:
zoneadm -z $ZONENAME clone origin
zoneadm list -ip | grep -F :$ZONENAME:installed:$ZONEPATH:
NEXT=$(($ZONE + 1))
if [ "$NEXT" -le "$MAX" ]; then
echo $NEXT >|vacant/$POOL/next
rm -f vacant/$POOL/lock
else
mkdir -p full
test ! -e full/$POOL
mv vacant/$POOL full
fi
trap - INT TERM EXIT
DEFROUTER=10.0.2.2
NETWORK=17
#!/usr/xpg4/bin/sh
set -Cex
export PATH=/usr/xpg6/bin:/usr/xpg4/bin:/usr/bin:/usr/sbin
FORMAT='^[1-9][0-9]\.[1-9][0-9]\.[1-9][0-9]$'
MIN=10
MAX=99
ROOT=/opt/custom
. $ROOT/config
cd $ROOT
for z in $(zoneadm list -c | grep $FORMAT); do
if zoneadm list -p | grep -F :$z:running:; then
zoneadm -z $z halt
fi
zoneadm list -ip | grep -F :$z:installed:
zoneadm -z $z uninstall -F
zoneadm list -cp | grep -F :$z:configured:
zonecfg -z $z delete -F
! zoneadm list -cp | grep -F :$z:
done
rm -fr vacant full
p=$MIN
while [ "$p" -le "$MAX" ]; do
mkdir -p full/$p
echo $MIN >full/$p/next
p=$(($p + 1))
done
mv full vacant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment