~smoser/+junk/jstack

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# btrfs for lxc-clone
sudo apt-get update 
sudo apt-get install lxc libvirt-bin -y </dev/null

sudo apt-get dist-upgrade -y </dev/null

## only necessary if you want btrfs (for faster clone)
sudo apt-get install btrfs-tools  -y </dev/null
sudo umount /mnt
dev=$(awk '$2 == "/mnt" { print $1; }' /etc/fstab)
sudo mkfs -t btrfs $dev -L ephemeral0 $dev
sudo mount /mnt

sudo rsync -a /var/lib/lxc/ /mnt/var-lib-lxc
sudo rm -Rf /var/lib/lxc
sudo ln -sf /mnt/var-lib-lxc /var/lib/lxc

sudo mkdir -p /var/cache/lxc
sudo rsync -a /var/cache/lxc/ /mnt/var-cache-lxc
sudo rm -Rf /var/cache/lxc
sudo ln -sf /mnt/var-cache-lxc /var/cache/lxc

## sudo lxc-create -B btrfs -t ubuntu -n ubuntu-source

##
## add host for archive.ubuntu.com to a local mirror into /etc/hosts
##
my_mirror="us-east-1.ec2.archive.ubuntu.com.s3.amazonaws.com"
my_mirror=""
[ -n "$my_mirror" ] &&
  ip=$(host "$my_mirror" | awk '$0 ~ /has address/ { print $4 }') &&
  echo "$ip archive.ubuntu.com us.archive.ubuntu.com" | sudo tee -a /etc/hosts

## LP: #925110
## fix lxc-ls as non-root
[ -f /usr/bin/lxc-ls.real ] ||
   sudo sh -c 'f=/usr/bin/lxc-ls && mv $f $f.real && cat >$f && chmod 755 $f' <<"EOF"
#!/bin/sh
exec sudo /usr/bin/lxc-ls.real "$@"
EOF

##
# get juju from ppa
sudo add-apt-repository -y ppa:juju/pkgs
sudo apt-get update

pkgs="libvirt-bin lxc apt-cacher-ng libzookeeper-java zookeeper juju bzr"
sudo apt-get install --assume-yes $pkgs </dev/null

## allow /dev/loop access to containers
lxc_conf="/usr/share/pyshared/juju/lib/lxc/data/lxc.conf"
if [ ! -f "${lxc_conf}.dist" ]; then
   sudo cp -a "${lxc_conf}" "${lxc_conf}.dist"
   sudo tee -a "$lxc_conf" <<"EOF"
# /dev/loop-control, /dev/loop[0-9]*
lxc.cgroup.devices.allow = b 10:237 rwm
lxc.cgroup.devices.allow = b 7:* rwm
EOF
fi

## improve speed of dpkg installs in juju guests
juju_create="/usr/share/pyshared/juju/lib/lxc/data/juju-create"
sudo sed -i.dist 's,^setup_apt_cache$,echo force-unsafe-io > /etc/dpkg/dpkg.cfg.d/force-unsafe-io; setup_apt_cache,' $juju_create

# make sure you're in the libvirtd group
groups $USER | grep libvirtd || sudo adduser $USER libvirtd

## set up juju for this user
JJ_ENAME="jstack"
JJ_SECRET="SEEKRET"
JJ_CTRL_BKT="juju-${JJ_ENAME}-bucket"
JJ_DATA_D="$HOME/juju-data"
JJ_SERIES="precise"
JJ_ORIGIN="ppa"

mkdir -p ~/.juju
cat > ~/.juju/environments.yaml <<EOF
environments:
  $JJ_ENAME:
    type: local
    data-dir: $JJ_DATA_D
    admin-secret: $JJ_SECRET
    default-series: $JJ_SERIES
    juju-origin: $JJ_ORIGIN
EOF

idrsa=$HOME/.ssh/id_rsa
[ -f "$idrsa" ] || ssh-keygen -t rsa -f $idrsa -N ''

# LP: 914932, fix hard coded release for lxc containers
sudo sed -i.lp914932.dist 's,release="oneiric",release="precise",' \
  /usr/share/pyshared/juju/lib/lxc/__init__.py

# load modules we know are needed by guests openstack
modules=""
modules="$modules scsi_transport_iscsi" # open-iscsi needs this
for mod in $modules; do sudo modprobe $mod; done

# bootstrap juju
juju bootstrap

# get deployer

bzr branch lp:~smoser/+junk/juju-deployer-concurrent deployer
cd deployer

#
./deployer.py --config deployments.cfg.jstack jstack-precise-ec2 --concurrent-deploy=4