Revision 151

Date:
2009/10/21 12:06:10
Author:
dpavlin
Revision Log:
configurable hostname as optional third param
Files:

Legend:

 
Added
 
Removed
 
Modified
  • recepies/lxc/ve2lxc.sh

     
    1 1 #!/bin/sh -x
    2 2
    3 test -z "$1" && echo "usage: $0 /path/to/ve/private [10.60.0.253]" && exit
    3 test -z "$1" && echo "usage: $0 /path/to/ve/private [10.60.0.253 [hostname]]" && exit
    4 4
    5 5 dir=$1
    6 hostname=ve2lxc
    7 6 ip=$2
    7 hostname=$3
    8 8 netmask=`grep netmask /etc/network/interfaces | head -1 | sed 's/^.*netmask *//'`
    9 9 gateway=`grep gateway /etc/network/interfaces | head -1 | sed 's/^.*gateway *//'`
    10 10
    11 test -z "$ip" && ip=10.60.0.253
    11 test -z "$ip" && ip=10.60.0.252
    12 test -z "$hostname" && hostname=ve2lxc
    12 13
    13 14 path=/$dir/etc/inittab
    14 15 tmp=/tmp/inittab
     
    32 33 cp $path $path.old && mv $tmp $path
    33 34 fi
    34 35
    35 lxc-stop -n ve2lxc
    36 lxc-destroy -n ve2lxc
    36 lxc-stop -n $hostname
    37 lxc-destroy -n $hostname
    37 38
    38 39 test -d /cgroup || mkdir /cgroup
    39 40 grep /cgroup /etc/fstab || echo "cgroup /cgroup cgroup rw 0 0" >> /etc/fstab
     
    54 55
    55 56 echo "$ip $hostname" >> $dir/etc/hosts
    56 57
    57 conf=/tmp/ve2lxc.conf
    58 conf=/tmp/$hostname.conf
    58 59
    59 60 cat << __lxc__ > $conf
    60 61 lxc.utsname = $hostname
     
    89 90
    90 91 mount | grep /cgroup || mount /cgroup || exit
    91 92
    92 lxc-create -n ve2lxc -f $conf && lxc-start -n ve2lxc
    93 lxc-create -n $hostname -f $conf && lxc-start -n $hostname